@berlysia/vertical-writing-slide-system 0.1.1 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@berlysia/vertical-writing-slide-system",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "vertical-slides": "./cli.js"
@@ -4,12 +4,30 @@ import type { Root, Image } from "mdast";
4
4
 
5
5
  interface RemarkSlideImagesOptions {
6
6
  base: string;
7
+ collection?: string; // フルURL時のみ使用(複数スライドホスティング対応)
8
+ }
9
+
10
+ /**
11
+ * baseとcollectionから画像パスのプレフィックスを生成
12
+ * - フルURL(http/https)の場合: collection名を含める
13
+ * - 相対パスの場合: collection名なし(ローカル開発用)
14
+ */
15
+ function buildImagePathPrefix(base: string, collection?: string): string {
16
+ if (
17
+ collection &&
18
+ (base.startsWith("http://") || base.startsWith("https://"))
19
+ ) {
20
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
21
+ return `${normalizedBase}${collection}/slide-assets/images/`;
22
+ }
23
+ return `${base}slide-assets/images/`;
7
24
  }
8
25
 
9
26
  const remarkSlideImages: Plugin<[RemarkSlideImagesOptions], Root> = (
10
27
  options,
11
28
  ) => {
12
- const { base } = options;
29
+ const { base, collection } = options;
30
+ const imagePathPrefix = buildImagePathPrefix(base, collection);
13
31
 
14
32
  return (tree) => {
15
33
  visit(tree, (node) => {
@@ -17,7 +35,7 @@ const remarkSlideImages: Plugin<[RemarkSlideImagesOptions], Root> = (
17
35
  if (node.type === "image") {
18
36
  const imageNode = node as Image;
19
37
  if (imageNode.url.startsWith("@slide/")) {
20
- imageNode.url = `${base}slide-assets/images/${imageNode.url.slice(7)}`;
38
+ imageNode.url = `${imagePathPrefix}${imageNode.url.slice(7)}`;
21
39
  }
22
40
  }
23
41
 
@@ -35,7 +53,7 @@ const remarkSlideImages: Plugin<[RemarkSlideImagesOptions], Root> = (
35
53
  typeof src.value === "string" &&
36
54
  src.value.startsWith("@slide/")
37
55
  ) {
38
- src.value = `${base}slide-assets/images/${src.value.slice(7)}`;
56
+ src.value = `${imagePathPrefix}${src.value.slice(7)}`;
39
57
  }
40
58
  }
41
59
 
@@ -50,7 +68,7 @@ const remarkSlideImages: Plugin<[RemarkSlideImagesOptions], Root> = (
50
68
  (_, attributes, src) => {
51
69
  return `<img ${attributes.replace(
52
70
  src,
53
- `${base}slide-assets/images/${src.slice(7)}`,
71
+ `${imagePathPrefix}${src.slice(7)}`,
54
72
  )}>`;
55
73
  },
56
74
  );
@@ -54,6 +54,7 @@ function rehypeExtractStyles(extractedStyles: string[]) {
54
54
  async function processMarkdown(
55
55
  markdown: string,
56
56
  base: string,
57
+ collection: string,
57
58
  extractedStyles: string[],
58
59
  extractedScripts: ParsedScript,
59
60
  ) {
@@ -65,7 +66,7 @@ async function processMarkdown(
65
66
 
66
67
  return await unified()
67
68
  .use(remarkParse)
68
- .use(remarkSlideImages, { base })
69
+ .use(remarkSlideImages, { base, collection })
69
70
  .use(remarkRehype, { allowDangerousHtml: true })
70
71
  .use(rehypeExtractStyles(extractedStyles))
71
72
  .use(rehypeStringify, { allowDangerousHtml: true })
@@ -354,9 +355,9 @@ export default async function slidesPlugin(
354
355
  if (ogpImageFile) {
355
356
  const ogpPath = `slide-assets/${ogpImageFile}`;
356
357
  if (base.startsWith("http://") || base.startsWith("https://")) {
357
- // フルURLの場合: baseの末尾スラッシュを正規化して結合
358
+ // フルURLの場合: baseの末尾スラッシュを正規化し、collection名を含めて結合
358
359
  const normalizedBase = base.endsWith("/") ? base : `${base}/`;
359
- slideMetadata.ogImage = `${normalizedBase}${ogpPath}`;
360
+ slideMetadata.ogImage = `${normalizedBase}${config.collection}/${ogpPath}`;
360
361
  } else {
361
362
  // 相対パスの場合: そのまま相対パスを設定
362
363
  slideMetadata.ogImage = `${base}${ogpPath}`;
@@ -388,7 +389,13 @@ export default async function slidesPlugin(
388
389
  const extractedScripts: ParsedScript = { external: [], inline: [] };
389
390
  const processedSlides = await Promise.all(
390
391
  slides.map((slide) =>
391
- processMarkdown(slide, base, extractedStyles, extractedScripts),
392
+ processMarkdown(
393
+ slide,
394
+ base,
395
+ config.collection,
396
+ extractedStyles,
397
+ extractedScripts,
398
+ ),
392
399
  ),
393
400
  );
394
401
 
@@ -457,7 +464,9 @@ export default async function slidesPlugin(
457
464
  development: false,
458
465
  jsxImportSource: "react",
459
466
  jsxRuntime: "automatic",
460
- remarkPlugins: [[remarkSlideImages, { base }]],
467
+ remarkPlugins: [
468
+ [remarkSlideImages, { base, collection: config.collection }],
469
+ ],
461
470
  });
462
471
  return result.value as string;
463
472
  }),