@berlysia/vertical-writing-slide-system 0.0.24 → 0.0.26
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/index.css +15 -0
- package/src/vite-plugin-slides.ts +53 -12
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
package/src/index.css
CHANGED
|
@@ -65,6 +65,21 @@ code {
|
|
|
65
65
|
margin: 0;
|
|
66
66
|
margin-block-end: 0.2em;
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
h2 {
|
|
70
|
+
font-size: 1.2em;
|
|
71
|
+
font-weight: bold;
|
|
72
|
+
margin: 0;
|
|
73
|
+
margin-block-end: 0.2em;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
h3 {
|
|
77
|
+
font-size: 1em;
|
|
78
|
+
font-weight: bold;
|
|
79
|
+
margin: 0;
|
|
80
|
+
margin-block-end: 0.2em;
|
|
81
|
+
}
|
|
82
|
+
|
|
68
83
|
ul,
|
|
69
84
|
ol {
|
|
70
85
|
list-style-position: outside;
|
|
@@ -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
|
|
|
@@ -322,7 +323,27 @@ export default async function slidesPlugin(
|
|
|
322
323
|
// スライド固有のスクリプトを文字列として生成
|
|
323
324
|
const slideScriptsString = JSON.stringify(slideScripts);
|
|
324
325
|
|
|
326
|
+
// スライド固有のCSSを文字列として生成
|
|
327
|
+
const slideStylesString =
|
|
328
|
+
slideStyles.length > 0
|
|
329
|
+
? JSON.stringify(slideStyles.join("\n\n"))
|
|
330
|
+
: "null";
|
|
331
|
+
|
|
325
332
|
return `
|
|
333
|
+
// スライド固有のCSSを注入
|
|
334
|
+
const slideStyles = ${slideStylesString};
|
|
335
|
+
if (slideStyles && typeof document !== 'undefined') {
|
|
336
|
+
const existingStyleElement = document.getElementById('slide-custom-styles');
|
|
337
|
+
if (existingStyleElement) {
|
|
338
|
+
existingStyleElement.textContent = slideStyles;
|
|
339
|
+
} else {
|
|
340
|
+
const styleElement = document.createElement('style');
|
|
341
|
+
styleElement.id = 'slide-custom-styles';
|
|
342
|
+
styleElement.textContent = slideStyles;
|
|
343
|
+
document.head.appendChild(styleElement);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
326
347
|
export default ${JSON.stringify(processedSlides.map((p) => p.value))};
|
|
327
348
|
export const slideScripts = ${slideScriptsString};
|
|
328
349
|
`;
|
|
@@ -454,36 +475,56 @@ export default async function slidesPlugin(
|
|
|
454
475
|
async buildStart() {
|
|
455
476
|
// Handle images during dev mode
|
|
456
477
|
if (resolvedConfig.command === "serve") {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
+
|
|
461
484
|
const sourceImagesDir = path.resolve(
|
|
462
485
|
config.slidesDir,
|
|
463
486
|
config.collection,
|
|
464
487
|
"images",
|
|
465
488
|
);
|
|
466
489
|
|
|
490
|
+
logger.info(`Checking for images in: ${sourceImagesDir}`);
|
|
491
|
+
logger.info(`Target images directory: ${targetImagesDir}`);
|
|
492
|
+
|
|
467
493
|
// Copy images from slides directory
|
|
468
494
|
if (fs.existsSync(sourceImagesDir)) {
|
|
469
495
|
try {
|
|
470
496
|
// Create target directory if it doesn't exist
|
|
471
497
|
mkdirSync(targetImagesDir, { recursive: true });
|
|
472
498
|
|
|
473
|
-
// Copy all files from source to target
|
|
499
|
+
// Copy all files from source to target using async operations
|
|
474
500
|
const imageFiles = readdirSync(sourceImagesDir);
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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");
|
|
479
519
|
}
|
|
480
|
-
logger.info("Copied slide images successfully");
|
|
481
520
|
} catch (error) {
|
|
482
521
|
if (error instanceof Error) {
|
|
483
522
|
logger.error("Failed to copy slide images", error);
|
|
484
523
|
}
|
|
485
524
|
throw error;
|
|
486
525
|
}
|
|
526
|
+
} else {
|
|
527
|
+
logger.info(`No images directory found at: ${sourceImagesDir}`);
|
|
487
528
|
}
|
|
488
529
|
}
|
|
489
530
|
},
|