@berlysia/vertical-writing-slide-system 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +3 -0
- package/package.json +1 -1
- package/src/remark-slide-images.ts +1 -1
- package/src/vite-plugin-slides.ts +34 -13
package/cli.js
CHANGED
|
@@ -25,9 +25,12 @@ async function runDev() {
|
|
|
25
25
|
libPath,
|
|
26
26
|
// Allow serving files from the current working directory
|
|
27
27
|
projectPath,
|
|
28
|
+
// Allow serving public assets from project directory
|
|
29
|
+
resolve(projectPath, "public"),
|
|
28
30
|
],
|
|
29
31
|
},
|
|
30
32
|
},
|
|
33
|
+
publicDir: resolve(projectPath, "public"), // Set public directory to project path
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
await server.listen();
|
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ const remarkSlideImages: Plugin<[RemarkSlideImagesOptions], Root> = (
|
|
|
44
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
45
|
const htmlNode = node as any;
|
|
46
46
|
const value = htmlNode.value as string;
|
|
47
|
-
if (value.
|
|
47
|
+
if (value.includes("<img")) {
|
|
48
48
|
htmlNode.value = value.replace(
|
|
49
49
|
/<img\s+([^>]*src="(@slide\/[^"]+)"[^>]*)>/g,
|
|
50
50
|
(_, attributes, src) => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Plugin, ViteDevServer, ResolvedConfig } from "vite";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import { mkdirSync,
|
|
4
|
+
import { mkdirSync, readdirSync } from "node:fs";
|
|
5
|
+
import { copyFile } from "node:fs/promises";
|
|
5
6
|
import prompts from "prompts";
|
|
6
7
|
import { compile } from "@mdx-js/mdx";
|
|
7
8
|
import { unified } from "unified";
|
|
@@ -116,7 +117,7 @@ function loadAdjacentScripts(
|
|
|
116
117
|
);
|
|
117
118
|
}
|
|
118
119
|
} catch (error) {
|
|
119
|
-
logger.warn(
|
|
120
|
+
logger.warn(`Failed to parse scripts.json: ${error}`);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
@@ -422,7 +423,7 @@ export default async function slidesPlugin(
|
|
|
422
423
|
|
|
423
424
|
// Return as a module with CSS injection
|
|
424
425
|
return `
|
|
425
|
-
${slideComponentsFilenames.map((filename) => `import * as ${filenameToComponentName(filename)} from '
|
|
426
|
+
${slideComponentsFilenames.map((filename) => `import * as ${filenameToComponentName(filename)} from '${slideComponentsDir}/${filename}';`).join("\n")}
|
|
426
427
|
|
|
427
428
|
const SlideComponents = {${slideComponentsFilenames.map((filename) => `...${filenameToComponentName(filename)}`).join(", ")}};
|
|
428
429
|
|
|
@@ -474,36 +475,56 @@ export default async function slidesPlugin(
|
|
|
474
475
|
async buildStart() {
|
|
475
476
|
// Handle images during dev mode
|
|
476
477
|
if (resolvedConfig.command === "serve") {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
478
|
+
// CLIモードでは適切なパスを使用
|
|
479
|
+
const isExternalCLI = process.cwd() !== resolvedConfig.root;
|
|
480
|
+
const targetImagesDir = isExternalCLI
|
|
481
|
+
? path.resolve(process.cwd(), "public/slide-assets/images")
|
|
482
|
+
: path.resolve(resolvedConfig.root, "public/slide-assets/images");
|
|
483
|
+
|
|
481
484
|
const sourceImagesDir = path.resolve(
|
|
482
485
|
config.slidesDir,
|
|
483
486
|
config.collection,
|
|
484
487
|
"images",
|
|
485
488
|
);
|
|
486
489
|
|
|
490
|
+
logger.info(`Checking for images in: ${sourceImagesDir}`);
|
|
491
|
+
logger.info(`Target images directory: ${targetImagesDir}`);
|
|
492
|
+
|
|
487
493
|
// Copy images from slides directory
|
|
488
494
|
if (fs.existsSync(sourceImagesDir)) {
|
|
489
495
|
try {
|
|
490
496
|
// Create target directory if it doesn't exist
|
|
491
497
|
mkdirSync(targetImagesDir, { recursive: true });
|
|
492
498
|
|
|
493
|
-
// Copy all files from source to target
|
|
499
|
+
// Copy all files from source to target using async operations
|
|
494
500
|
const imageFiles = readdirSync(sourceImagesDir);
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
501
|
+
logger.info(`Found ${imageFiles.length} image files to copy`);
|
|
502
|
+
|
|
503
|
+
if (imageFiles.length > 0) {
|
|
504
|
+
const copyPromises = imageFiles.map(async (file) => {
|
|
505
|
+
const sourcePath = path.join(sourceImagesDir, file);
|
|
506
|
+
const targetPath = path.join(targetImagesDir, file);
|
|
507
|
+
await copyFile(sourcePath, targetPath);
|
|
508
|
+
logger.info(`Copied image: ${file}`);
|
|
509
|
+
return file;
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// すべての画像コピーが完了するまで待機
|
|
513
|
+
const copiedFiles = await Promise.all(copyPromises);
|
|
514
|
+
logger.info(
|
|
515
|
+
`Successfully copied ${copiedFiles.length} slide images`,
|
|
516
|
+
);
|
|
517
|
+
} else {
|
|
518
|
+
logger.info("No image files found to copy");
|
|
499
519
|
}
|
|
500
|
-
logger.info("Copied slide images successfully");
|
|
501
520
|
} catch (error) {
|
|
502
521
|
if (error instanceof Error) {
|
|
503
522
|
logger.error("Failed to copy slide images", error);
|
|
504
523
|
}
|
|
505
524
|
throw error;
|
|
506
525
|
}
|
|
526
|
+
} else {
|
|
527
|
+
logger.info(`No images directory found at: ${sourceImagesDir}`);
|
|
507
528
|
}
|
|
508
529
|
}
|
|
509
530
|
},
|