grimoire3d 0.1.0 → 0.2.0-dev.785bb23

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.
Files changed (108) hide show
  1. package/README.md +15 -1
  2. package/cli/book-cover.d.ts +10 -0
  3. package/cli/book-cover.js +56 -0
  4. package/cli/cli.js +5 -3
  5. package/cli/content.js +128 -15
  6. package/cli/head-file.js +133 -0
  7. package/cli/library-footer.d.ts +10 -0
  8. package/cli/library-footer.js +21 -0
  9. package/cli/markdown.js +11 -0
  10. package/cli/static-pages.js +51 -12
  11. package/dist/site/assets/BookReader-5pM5wP2A.js +2 -0
  12. package/dist/site/assets/{BookScene-ClDai0Ew.js → BookScene-RrBaUUYB.js} +1 -1
  13. package/dist/site/assets/MermaidDiagram-D_0Lzujl.js +44 -0
  14. package/dist/site/assets/{PageMarkdown-8bd0sLEr.js → PageMarkdown-DQOlzkxh.js} +3 -3
  15. package/dist/site/assets/{abnfDiagram-S7VZAUFO-BLtDZQsQ.js → abnfDiagram-S7VZAUFO-CnBoibVK.js} +1 -1
  16. package/dist/site/assets/{architecture-WOLXFQ4H-Br-SxDK7.js → architecture-WOLXFQ4H-BUW5XoSg.js} +1 -1
  17. package/dist/site/assets/{architectureDiagram-YGSQEFNW-BMjvBU3D.js → architectureDiagram-YGSQEFNW-B6gpKPRf.js} +1 -1
  18. package/dist/site/assets/{blockDiagram-APKKGZFW-CJrjfQP8.js → blockDiagram-APKKGZFW-DzujHYb6.js} +1 -1
  19. package/dist/site/assets/{c4Diagram-KJ2TOQU5-C_L7eR0-.js → c4Diagram-KJ2TOQU5-CAApT3wg.js} +1 -1
  20. package/dist/site/assets/{chunk-6MUBBAK2-DLDw-vT7.js → chunk-6MUBBAK2-CBL8kJBQ.js} +1 -1
  21. package/dist/site/assets/{chunk-AXFCVDMN-0o4q-lH2.js → chunk-AXFCVDMN-CECdpNlC.js} +1 -1
  22. package/dist/site/assets/{chunk-BG4553SI-CGVj-yfp.js → chunk-BG4553SI-Bit8fGUK.js} +1 -1
  23. package/dist/site/assets/{chunk-DQASFODM-BKuFhVEZ.js → chunk-DQASFODM-DCXRnXLz.js} +1 -1
  24. package/dist/site/assets/{chunk-HFQBQIA3-98-S4lXj.js → chunk-HFQBQIA3-BBPlNXRe.js} +1 -1
  25. package/dist/site/assets/{chunk-KQLB2F66-Cwy4jCX-.js → chunk-KQLB2F66-B72nJl7f.js} +1 -1
  26. package/dist/site/assets/{chunk-KS47KZWR-DyN2V_V_.js → chunk-KS47KZWR-BmW9AsrF.js} +1 -1
  27. package/dist/site/assets/{chunk-LEVMRMFU-D998hT2l.js → chunk-LEVMRMFU-P01Wm6c9.js} +1 -1
  28. package/dist/site/assets/{chunk-M57EVK23-DVNKK3KL.js → chunk-M57EVK23-Dt9NSVMZ.js} +1 -1
  29. package/dist/site/assets/{chunk-OY52VR5R-Do_eRCOT.js → chunk-OY52VR5R-55zxU9gN.js} +1 -1
  30. package/dist/site/assets/{chunk-QB3YPZ4I-CUKYR7fo.js → chunk-QB3YPZ4I-Ba8Om-jB.js} +1 -1
  31. package/dist/site/assets/{chunk-R3KSYZAL-BINu_oUt.js → chunk-R3KSYZAL-Bhkxj8pV.js} +1 -1
  32. package/dist/site/assets/{chunk-STOXU5M4-DSOkDZ95.js → chunk-STOXU5M4-ZPfBWNfR.js} +1 -1
  33. package/dist/site/assets/{chunk-TU62E6Q5-CKPbcGB7.js → chunk-TU62E6Q5-DN_BJJox.js} +1 -1
  34. package/dist/site/assets/{chunk-X4PVCEUW-x_8xZedM.js → chunk-X4PVCEUW-wh_-rkJf.js} +1 -1
  35. package/dist/site/assets/{chunk-XXDRQBXY-Ls7gbN4B.js → chunk-XXDRQBXY-CNQnC--q.js} +1 -1
  36. package/dist/site/assets/{classDiagram-v2-L25IHNXF-BLswbJCW.js → classDiagram-v2-L25IHNXF-DJk0rUaa.js} +1 -1
  37. package/dist/site/assets/{cose-bilkent-JH36ORCC-jgZzNA8p.js → cose-bilkent-JH36ORCC-COco7PRi.js} +1 -1
  38. package/dist/site/assets/cynefin-EF2NZ3EQ-WZObn4oK.js +1 -0
  39. package/dist/site/assets/{cynefinDiagram-L36ESFBY-hsyd6FZA.js → cynefinDiagram-L36ESFBY-Bb2CAvFF.js} +1 -1
  40. package/dist/site/assets/{d3-selection-BgLPRw73.js → d3-selection-DHygnWoA.js} +1 -1
  41. package/dist/site/assets/{dagre-SPEB5RXH-CCtbYR55.js → dagre-SPEB5RXH-Bj5fBBSz.js} +1 -1
  42. package/dist/site/assets/{diagram-3B7GL73J-DdBQoKkR.js → diagram-3B7GL73J-C2wQG_ff.js} +1 -1
  43. package/dist/site/assets/{diagram-DNEMPZML-Df4RnpW9.js → diagram-DNEMPZML-BkCumRTy.js} +1 -1
  44. package/dist/site/assets/{diagram-L3MUGCDN-4lpf2zFh.js → diagram-L3MUGCDN-ueCGwS0n.js} +1 -1
  45. package/dist/site/assets/{diagram-LA4NIPWU-DTl6abGv.js → diagram-LA4NIPWU-CWXyhkCR.js} +1 -1
  46. package/dist/site/assets/{diagram-MHCOC4E2-TChI4LJC.js → diagram-MHCOC4E2-CjtgYuJD.js} +1 -1
  47. package/dist/site/assets/{diagram-XPFHEONP-BN2i8pem.js → diagram-XPFHEONP-DMJK3uYo.js} +1 -1
  48. package/dist/site/assets/{dist-BkyV6i4k.js → dist-D_7AE7hR.js} +1 -1
  49. package/dist/site/assets/{ebnfDiagram-UZSYDL2S-CTBs0OrB.js → ebnfDiagram-UZSYDL2S-BOYcicjK.js} +1 -1
  50. package/dist/site/assets/{elk-XV6XMXQE-BPXZDIn6.js → elk-XV6XMXQE-B5L8Iw7x.js} +1 -1
  51. package/dist/site/assets/{erDiagram-EYBAPDEH-69s09FNs.js → erDiagram-EYBAPDEH-CUUbHYkT.js} +1 -1
  52. package/dist/site/assets/{eventmodeling-K75KTNOO-Cv6nmcPj.js → eventmodeling-K75KTNOO-B7uQyKPK.js} +1 -1
  53. package/dist/site/assets/flowDiagram-MALGAFMO-DepLaS9B.js +1 -0
  54. package/dist/site/assets/{ganttDiagram-23REXITY-DuPK4jhs.js → ganttDiagram-23REXITY-D5HywVHP.js} +1 -1
  55. package/dist/site/assets/gitGraph-VSP46ZUC-DGApQopU.js +1 -0
  56. package/dist/site/assets/{gitGraphDiagram-STJD7YCW-CFFq3ISs.js → gitGraphDiagram-STJD7YCW-Ct1E3koZ.js} +1 -1
  57. package/dist/site/assets/index-BTjyXmrh.css +1 -0
  58. package/dist/site/assets/index-CiI39UEW.js +2 -0
  59. package/dist/site/assets/info-OHQRW6UA-Nb4bAH3m.js +1 -0
  60. package/dist/site/assets/{infoDiagram-KBXO4MBG-Dhu_km6o.js → infoDiagram-KBXO4MBG-DnU24S0B.js} +1 -1
  61. package/dist/site/assets/{ishikawaDiagram-M35NCXHK-DaADHVsr.js → ishikawaDiagram-M35NCXHK-BcQghjKX.js} +1 -1
  62. package/dist/site/assets/{journeyDiagram-OPLOXDXO-CH4pGZdE.js → journeyDiagram-OPLOXDXO-stnSaHRX.js} +1 -1
  63. package/dist/site/assets/{kanban-definition-BZKZHSQY-CwG8xTtA.js → kanban-definition-BZKZHSQY-DEHcPEwn.js} +1 -1
  64. package/dist/site/assets/{mermaid-parser.core-Bffyim8R.js → mermaid-parser.core-DeCnM7F6.js} +3 -3
  65. package/dist/site/assets/{mindmap-definition-I2QAS2VK-CV27wfks.js → mindmap-definition-I2QAS2VK-DmMlZUpg.js} +1 -1
  66. package/dist/site/assets/packet-JDAUHWVQ-Bq64t2Nq.js +1 -0
  67. package/dist/site/assets/{pegDiagram-FD4XPPHP-CxeieYHG.js → pegDiagram-FD4XPPHP-Dg_Jmvr8.js} +1 -1
  68. package/dist/site/assets/pie-XZMESJXO-62QUFLOf.js +1 -0
  69. package/dist/site/assets/{pieDiagram-J4AKIIQI-S021BZ2O.js → pieDiagram-J4AKIIQI-Cl6xtUfY.js} +1 -1
  70. package/dist/site/assets/{quadrantDiagram-XTYBLID2-CS3Wnh9t.js → quadrantDiagram-XTYBLID2-CPskrlLu.js} +1 -1
  71. package/dist/site/assets/radar-ABXABTNO-DcHFlqcv.js +1 -0
  72. package/dist/site/assets/railroad-I3PHUGI6-UN_KVEIT.js +1 -0
  73. package/dist/site/assets/{railroad-abnf-LNEFI6M7-lZG67lnF.js → railroad-abnf-LNEFI6M7-CBmAElE0.js} +1 -1
  74. package/dist/site/assets/{railroad-ebnf-DWYD2UWJ-BRsn72BC.js → railroad-ebnf-DWYD2UWJ-cz0Vnfoe.js} +1 -1
  75. package/dist/site/assets/{railroad-peg-JR7BVNR7-CtPpRSc3.js → railroad-peg-JR7BVNR7-CTpZf4Io.js} +1 -1
  76. package/dist/site/assets/{railroadDiagram-MRQ6NCDL-iaKQfjRw.js → railroadDiagram-MRQ6NCDL-BfRdrXVU.js} +1 -1
  77. package/dist/site/assets/{requirementDiagram-Y7LWUY3S-CMzSSfA0.js → requirementDiagram-Y7LWUY3S-Co7Z8efw.js} +1 -1
  78. package/dist/site/assets/{sankeyDiagram-WGJFYUXA-C-zNVN8E.js → sankeyDiagram-WGJFYUXA-B9pt8sRE.js} +1 -1
  79. package/dist/site/assets/{sequenceDiagram-5NDRBG5M-CTZLsRjA.js → sequenceDiagram-5NDRBG5M-6BxTaEsr.js} +1 -1
  80. package/dist/site/assets/{stateDiagram-v2-FJ4FJNEA-DnJQgyn2.js → stateDiagram-v2-FJ4FJNEA-B4sFxyl8.js} +1 -1
  81. package/dist/site/assets/{swimlanes-UMQ2AFYF-Cxof6TWX.js → swimlanes-UMQ2AFYF-BCLEQ3gh.js} +1 -1
  82. package/dist/site/assets/swimlanesDiagram-OMPLPG4O-CSFiCK4U.js +8 -0
  83. package/dist/site/assets/{timeline-definition-SEUHKTQE-CvE1EwLK.js → timeline-definition-SEUHKTQE-En4zD208.js} +1 -1
  84. package/dist/site/assets/treeView-D4JQ5SDB-Co5K409-.js +1 -0
  85. package/dist/site/assets/treemap-SAJKECNS-6nDAfcSQ.js +1 -0
  86. package/dist/site/assets/{usecaseDiagram-AFA6YXN4-CllyFV7U.js → usecaseDiagram-AFA6YXN4-BwnPKBeW.js} +1 -1
  87. package/dist/site/assets/{vennDiagram-NNMJR3RB-DrwAMqYF.js → vennDiagram-NNMJR3RB-BZaUT4ro.js} +1 -1
  88. package/dist/site/assets/wardley-7MLQ67FV-B_pofY38.js +1 -0
  89. package/dist/site/assets/{wardleyDiagram-S7YFUSEH-CzdqWBzS.js → wardleyDiagram-S7YFUSEH-Dg8pAabl.js} +1 -1
  90. package/dist/site/assets/{xychartDiagram-GGNKY7IX-DCr2dgbN.js → xychartDiagram-GGNKY7IX-Di4W3slj.js} +1 -1
  91. package/dist/site/index.html +2 -2
  92. package/package.json +2 -1
  93. package/dist/site/assets/BookReader-D6Y6-YiA.js +0 -2
  94. package/dist/site/assets/MermaidDiagram-BZ4xzlxF.js +0 -44
  95. package/dist/site/assets/cynefin-EF2NZ3EQ-DA8OIyiG.js +0 -1
  96. package/dist/site/assets/flowDiagram-MALGAFMO-DBtCHz69.js +0 -1
  97. package/dist/site/assets/gitGraph-VSP46ZUC-Bde1Q0wm.js +0 -1
  98. package/dist/site/assets/index-aLXzUwjX.css +0 -1
  99. package/dist/site/assets/index-c2f4iI83.js +0 -2
  100. package/dist/site/assets/info-OHQRW6UA-Dq-6TQob.js +0 -1
  101. package/dist/site/assets/packet-JDAUHWVQ-DyTXCyJi.js +0 -1
  102. package/dist/site/assets/pie-XZMESJXO-D41O9C3e.js +0 -1
  103. package/dist/site/assets/radar-ABXABTNO-BxXELdSz.js +0 -1
  104. package/dist/site/assets/railroad-I3PHUGI6-DiCj9Bvm.js +0 -1
  105. package/dist/site/assets/swimlanesDiagram-OMPLPG4O-CSKTfgXj.js +0 -8
  106. package/dist/site/assets/treeView-D4JQ5SDB-Cnco8mDb.js +0 -1
  107. package/dist/site/assets/treemap-SAJKECNS-B23_S7Go.js +0 -1
  108. package/dist/site/assets/wardley-7MLQ67FV-CPxB3VDK.js +0 -1
package/README.md CHANGED
@@ -26,7 +26,21 @@ Create `docs/field-notes/index.md`.
26
26
  This is my first 3D book.
27
27
  ```
28
28
 
29
- Add Markdown files in the same folder for more chapters. Add folders directly under `docs/` for more books.
29
+ `docs` 直下の各フォルダが1冊、その中のMarkdownが章になります。`docs` 直下に並べたMarkdownは、まとめて別の1冊になります。入れ子のフォルダは同じ本の章グループです。
30
+
31
+ ```text
32
+ docs/
33
+ ├── index.md # docs直下のMarkdownで1冊
34
+ ├── notes.md
35
+ └── field-notes/ # 別の1冊
36
+ ├── index.md # 本の導入・設定
37
+ ├── setup.md
38
+ └── examples/ # 同じ本の章グループ
39
+ ├── index.md
40
+ └── cli.md
41
+ ```
42
+
43
+ 各 `index.md` のYAMLに `chapters: [setup.md, examples/]` と書くと、導入の後を指定順に並べられます。未指定の章は後ろにファイル名順で続きます。本が7冊以上、またはカテゴリー・公開日を設定すると検索欄が表示されます。
30
44
 
31
45
  ```sh
32
46
  npx grimoire3d serve
@@ -0,0 +1,10 @@
1
+ import type { JSX, Ref } from "react";
2
+
3
+ export function BookCover(props: {
4
+ title: string;
5
+ src?: string;
6
+ compact?: string;
7
+ artwork?: string;
8
+ loading?: "eager" | "lazy";
9
+ titleRef?: Ref<HTMLSpanElement>;
10
+ }): JSX.Element;
@@ -0,0 +1,56 @@
1
+ import { createElement as element } from "react";
2
+
3
+ function bindingImage(src, compact, loading) {
4
+ return element(
5
+ "picture",
6
+ null,
7
+ compact &&
8
+ element("source", { media: "(max-width: 699px)", srcSet: compact }),
9
+ element("img", {
10
+ className: "volume-render",
11
+ src,
12
+ width: 600,
13
+ height: 760,
14
+ alt: "",
15
+ loading,
16
+ fetchPriority: "low",
17
+ decoding: "async",
18
+ })
19
+ );
20
+ }
21
+
22
+ export function BookCover({ title, src, compact, artwork, loading, titleRef }) {
23
+ const lettering = element(
24
+ "span",
25
+ { className: "volume-title", ref: titleRef },
26
+ title
27
+ );
28
+ const binding = src && bindingImage(src, compact, loading);
29
+ if (!artwork)
30
+ return element("span", { className: "volume-face" }, binding, lettering);
31
+
32
+ return element(
33
+ "span",
34
+ { className: "volume-face" },
35
+ binding,
36
+ src &&
37
+ element(
38
+ "span",
39
+ { className: "volume-unmarked", "aria-hidden": true },
40
+ bindingImage(src, compact, loading)
41
+ ),
42
+ element(
43
+ "span",
44
+ { className: "volume-cover-content" },
45
+ lettering,
46
+ element("img", {
47
+ className: "volume-cover-image",
48
+ src: artwork,
49
+ alt: "",
50
+ loading,
51
+ decoding: "async",
52
+ fetchPriority: "low",
53
+ })
54
+ )
55
+ );
56
+ }
package/cli/cli.js CHANGED
@@ -28,6 +28,7 @@ import { fileURLToPath } from "node:url";
28
28
  import { parseArgs } from "node:util";
29
29
  import { contentType, lookup } from "mime-types";
30
30
  import { readLibrary, readSettings } from "./content.js";
31
+ import { readHeadFile } from "./head-file.js";
31
32
  import { previewHead, writeStaticPages } from "./static-pages.js";
32
33
 
33
34
  const template = fileURLToPath(new URL("../dist/site/", import.meta.url));
@@ -80,7 +81,7 @@ function serializedLibrary(library) {
80
81
  ]);
81
82
  }
82
83
 
83
- async function writeStaticSite(cwd, outDir, library) {
84
+ async function writeStaticSite(cwd, outDir, library, headMarkup) {
84
85
  const output = resolve(cwd, outDir);
85
86
  const { locale } = library.manifest;
86
87
  const exists = await existingOutput(output, locale);
@@ -102,7 +103,7 @@ async function writeStaticSite(cwd, outDir, library) {
102
103
  await mkdir(dirname(path), { recursive: true });
103
104
  await copyFile(source, path);
104
105
  }
105
- await writeStaticPages(template, staging, library);
106
+ await writeStaticPages(template, staging, library, headMarkup);
106
107
  await writeFile(join(staging, marker), json(await listFiles(staging)));
107
108
  if (exists) await rename(output, backup);
108
109
  try {
@@ -325,7 +326,8 @@ async function main() {
325
326
  const output = await writeStaticSite(
326
327
  cwd,
327
328
  values["out-dir"] ?? settings.outDir ?? "dist",
328
- library
329
+ library,
330
+ await readHeadFile(cwd, settings.headFile)
329
331
  );
330
332
  const label = settings.locale === "ja" ? "書き出し先" : "Built to";
331
333
  console.log(`${label}: ${basename(output)}/ (${output})`);
package/cli/content.js CHANGED
@@ -36,26 +36,83 @@ async function readPages(root, directory, nested) {
36
36
  const entries = (
37
37
  await readdir(join(root, directory), { withFileTypes: true })
38
38
  )
39
- .filter((entry) => visibleEntry(entry.name))
39
+ .filter(
40
+ (entry) =>
41
+ visibleEntry(entry.name) &&
42
+ ((entry.isDirectory() && nested) ||
43
+ (entry.isFile() && isMarkdown(entry.name)))
44
+ )
40
45
  .sort((a, b) => sortNames(a.name, b.name));
41
- const pages = [];
42
- for (const entry of entries) {
46
+ const index = entries.find(
47
+ (entry) => entry.isFile() && /^index\.md$/i.test(entry.name)
48
+ );
49
+ const indexPath = index && posix.join(directory, index.name);
50
+ const introduction = index && {
51
+ path: indexPath,
52
+ ...readMarkdown(await readFile(join(root, indexPath), "utf8")),
53
+ };
54
+ const order = introduction?.metadata.chapters;
55
+ const selected = [];
56
+ if (order !== undefined) {
57
+ if (!Array.isArray(order))
58
+ throw new Error(
59
+ `${indexPath}: chapters must be a list of direct Markdown files or folders.`
60
+ );
61
+ const seen = new Set();
62
+ for (const item of order) {
63
+ const name = typeof item === "string" ? item.replace(/\/$/, "") : "";
64
+ const entry = entries.find((entry) => entry.name === name);
65
+ if (
66
+ !name ||
67
+ name.includes("/") ||
68
+ !entry ||
69
+ (item.endsWith("/") && !entry.isDirectory())
70
+ )
71
+ throw new Error(
72
+ `${indexPath}: chapters entry "${String(item)}" must name a direct Markdown file or folder in this book.`
73
+ );
74
+ if (seen.has(name))
75
+ throw new Error(
76
+ `${indexPath}: chapters contains duplicate entry "${name}".`
77
+ );
78
+ seen.add(name);
79
+ selected.push(entry);
80
+ }
81
+ }
82
+ const pages = introduction ? [introduction] : [];
83
+ for (const entry of [
84
+ ...selected,
85
+ ...entries.filter((entry) => !selected.includes(entry)),
86
+ ]) {
87
+ if (entry === index) continue;
43
88
  const path = posix.join(directory, entry.name);
44
- if (entry.isDirectory() && nested) {
89
+ if (entry.isDirectory()) {
45
90
  pages.push(...(await readPages(root, path, true)));
46
- } else if (entry.isFile() && isMarkdown(entry.name)) {
47
- const markdown = await readFile(join(root, path), "utf8");
48
- pages.push({ path, ...readMarkdown(markdown) });
91
+ } else {
92
+ pages.push({
93
+ path,
94
+ ...readMarkdown(await readFile(join(root, path), "utf8")),
95
+ });
49
96
  }
50
97
  }
51
98
  return pages;
52
99
  }
53
100
 
54
- function comparePages(a, b) {
55
- // Treat index.md as the first page of its folder, without reordering the folders.
56
- return sortNames(
57
- a.path.replace(/(^|\/)index\.md$/i, "$1!index.md"),
58
- b.path.replace(/(^|\/)index\.md$/i, "$1!index.md")
101
+ function readPublicationDate(index) {
102
+ const raw = index?.metadata.date;
103
+ const date = typeof raw === "string" ? raw.trim() : raw;
104
+ if (date == null || date === "") return undefined;
105
+
106
+ if (typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date)) {
107
+ const parsed = new Date(date);
108
+ if (
109
+ Number.isFinite(parsed.getTime()) &&
110
+ parsed.toISOString().slice(0, 10) === date
111
+ )
112
+ return date;
113
+ }
114
+ throw new Error(
115
+ `${index.path}: date must be a valid publication date in YYYY-MM-DD format.`
59
116
  );
60
117
  }
61
118
 
@@ -81,7 +138,13 @@ function describeBook(pages, folder, fallback) {
81
138
  id,
82
139
  title,
83
140
  cover,
84
- chapters: pages.sort(comparePages).map((page) => {
141
+ category: index?.metadata.category,
142
+ date: readPublicationDate(index),
143
+ coverImage: index?.metadata.coverImage && {
144
+ path: index.path,
145
+ value: index.metadata.coverImage,
146
+ },
147
+ chapters: pages.map((page) => {
85
148
  const group = posix.dirname(page.path);
86
149
  const inBook = folder ? page.path.slice(folder.length + 1) : page.path;
87
150
  const file = posix.basename(pageId(page.path));
@@ -143,6 +206,8 @@ export async function readSettings(cwd) {
143
206
  socialImage,
144
207
  author,
145
208
  magicMode,
209
+ footer,
210
+ headFile,
146
211
  } = settings;
147
212
  if (
148
213
  typeof settings !== "object" ||
@@ -180,6 +245,8 @@ export async function readSettings(cwd) {
180
245
  socialImage,
181
246
  author,
182
247
  magicMode,
248
+ footer: readFooter(footer),
249
+ headFile,
183
250
  siteUrl: siteUrl && normalizeSiteUrl(siteUrl),
184
251
  };
185
252
  }
@@ -197,6 +264,22 @@ function absoluteWebUrl(value) {
197
264
  return undefined;
198
265
  }
199
266
 
267
+ function readFooter(footer) {
268
+ if (footer === undefined) return undefined;
269
+ if (typeof footer?.label !== "string" || !footer.label.trim()) {
270
+ throw new Error("grimoire.yml: footer.label must be non-empty text.");
271
+ }
272
+ const { label, url } = footer;
273
+ if (url === undefined) return { label: label.trim() };
274
+ const link = typeof url === "string" ? absoluteWebUrl(url) : undefined;
275
+ if (!link) {
276
+ throw new Error(
277
+ "grimoire.yml: footer.url must be an absolute HTTP(S) URL."
278
+ );
279
+ }
280
+ return { label: label.trim(), url: link.href };
281
+ }
282
+
200
283
  function normalizeSiteUrl(value) {
201
284
  const url = absoluteWebUrl(value);
202
285
  if (!url || url.search || url.hash) {
@@ -305,9 +388,37 @@ export async function readLibrary(cwd, settings) {
305
388
  return image || undefined;
306
389
  }
307
390
  const socialImage = await socialAsset(settings.socialImage, "index.md");
391
+ const summaries = [];
308
392
  const publishedBooks = [];
309
393
  const documents = [];
310
- for (const { id, title, cover, chapters } of books) {
394
+ for (const {
395
+ id,
396
+ title,
397
+ cover,
398
+ category,
399
+ date,
400
+ coverImage,
401
+ chapters,
402
+ } of books) {
403
+ let artwork;
404
+ if (coverImage) {
405
+ const { path, value } = coverImage;
406
+ const extension = extname(value.split(/[?#]/, 1)[0]).toLowerCase();
407
+ if (
408
+ ![".avif", ".gif", ".jpeg", ".jpg", ".png", ".webp"].includes(extension)
409
+ ) {
410
+ throw new Error(
411
+ `${path}: coverImage must point to an AVIF, GIF, JPEG, PNG, or WebP file.`
412
+ );
413
+ }
414
+ artwork = await loadLink(value, { path }, links, docs, assets, issues);
415
+ if (!artwork?.startsWith("./content/")) {
416
+ throw new Error(
417
+ `${path}: coverImage "${value}" must be a readable local image inside docs/.`
418
+ );
419
+ }
420
+ }
421
+ summaries.push({ id, title, cover, category, date, coverImage: artwork });
311
422
  const pages = [];
312
423
  for (const chapter of chapters) {
313
424
  const {
@@ -340,6 +451,7 @@ export async function readLibrary(cwd, settings) {
340
451
  chapter: chapterId,
341
452
  title: chapterTitle,
342
453
  hasTitle: chapter.hasTitle,
454
+ noindex: chapter.metadata.noindex,
343
455
  description:
344
456
  chapter.metadata.description ||
345
457
  chapter.excerpt ||
@@ -364,7 +476,8 @@ export async function readLibrary(cwd, settings) {
364
476
  socialImage,
365
477
  author: settings.author,
366
478
  magicMode: settings.magicMode,
367
- books: books.map(({ id, title, cover }) => ({ id, title, cover })),
479
+ footer: settings.footer,
480
+ books: summaries,
368
481
  },
369
482
  books: publishedBooks,
370
483
  documents,
@@ -0,0 +1,133 @@
1
+ import { readFile, realpath, stat } from "node:fs/promises";
2
+ import { isAbsolute, relative, resolve, sep } from "node:path";
3
+ import { parse } from "parse5";
4
+
5
+ const managedMeta = new Set([
6
+ "author",
7
+ "description",
8
+ "grimoire-preview",
9
+ "grimoire-static",
10
+ "og:description",
11
+ "og:image",
12
+ "og:locale",
13
+ "og:site_name",
14
+ "og:title",
15
+ "og:type",
16
+ "og:url",
17
+ "twitter:card",
18
+ "viewport",
19
+ ]);
20
+ const headElements = new Set(["link", "meta", "script", "style"]);
21
+ const headStart = "<!doctype html><html><head>\n";
22
+
23
+ function managedTag(node) {
24
+ const attrs = Object.fromEntries(
25
+ node.attrs.map(({ name, value }) => [name, value])
26
+ );
27
+ if (node.tagName === "title" || node.tagName === "base")
28
+ return `<${node.tagName}>`;
29
+ if (node.tagName === "link") {
30
+ const rel = attrs.rel?.toLowerCase().trim().split(/\s+/) ?? [];
31
+ if (rel.includes("canonical")) return '<link rel="canonical">';
32
+ if (rel.includes("icon")) return '<link rel="icon">';
33
+ }
34
+ if (node.tagName === "meta") {
35
+ if ("charset" in attrs) return "<meta charset>";
36
+ if (attrs["http-equiv"]?.trim().toLowerCase() === "content-type")
37
+ return '<meta http-equiv="content-type">';
38
+ for (const attr of ["name", "property"]) {
39
+ const key = attrs[attr]?.trim().toLowerCase();
40
+ if (managedMeta.has(key)) return `<meta ${attr}="${key}">`;
41
+ }
42
+ }
43
+ }
44
+
45
+ function checkHeadFragment(markup, label) {
46
+ const fileError = (line, message) =>
47
+ new Error(`${label}:${Math.max(1, line - 1)}: ${message}`);
48
+ const document = parse(`${headStart}${markup}</head><body></body></html>`, {
49
+ sourceCodeLocationInfo: true,
50
+ onParseError(error) {
51
+ throw fileError(error.startLine, `Invalid HTML (${error.code}).`);
52
+ },
53
+ });
54
+ const html = document.childNodes.find(({ nodeName }) => nodeName === "html");
55
+ const head = html.childNodes.find(({ nodeName }) => nodeName === "head");
56
+ if (
57
+ head.sourceCodeLocation?.endTag?.startOffset !==
58
+ headStart.length + markup.length
59
+ ) {
60
+ throw new Error(
61
+ `${label}: Expected an HTML head fragment. Use metadata, links, scripts, or styles inside the file.`
62
+ );
63
+ }
64
+
65
+ for (const node of head.childNodes) {
66
+ if (
67
+ node.nodeName === "#comment" ||
68
+ (node.nodeName === "#text" && !node.value.trim())
69
+ )
70
+ continue;
71
+
72
+ const { startLine } = node.sourceCodeLocation;
73
+ const conflict = node.attrs && managedTag(node);
74
+ if (conflict) {
75
+ throw fileError(
76
+ startLine,
77
+ `${conflict} is managed by Grimoire3D. Use the existing site and chapter settings.`
78
+ );
79
+ }
80
+ if (!headElements.has(node.tagName)) {
81
+ throw fileError(
82
+ startLine,
83
+ "Expected a meta, link, script, or style tag."
84
+ );
85
+ }
86
+ }
87
+ }
88
+
89
+ function insideProject(project, path) {
90
+ const location = relative(project, path);
91
+ return !isAbsolute(location) && location.split(sep)[0] !== "..";
92
+ }
93
+
94
+ export async function readHeadFile(cwd, setting) {
95
+ if (setting === undefined) return "";
96
+ if (
97
+ typeof setting !== "string" ||
98
+ !setting.trim() ||
99
+ isAbsolute(setting) ||
100
+ /^[a-z][a-z\d+.-]*:/i.test(setting)
101
+ ) {
102
+ throw new Error(
103
+ "grimoire.yml: headFile must be a relative path within the project."
104
+ );
105
+ }
106
+
107
+ const label = `grimoire.yml: headFile ${JSON.stringify(setting)}`;
108
+ const project = await realpath(cwd);
109
+ const requested = resolve(project, setting);
110
+ const outside = () => new Error(`${label}: Use a path within the project.`);
111
+ if (!insideProject(project, requested)) throw outside();
112
+
113
+ const unreadable = (cause) =>
114
+ new Error(
115
+ `${label}: Cannot read the HTML file. Check that it exists and is readable.`,
116
+ { cause }
117
+ );
118
+ const path = await realpath(requested).catch((error) => {
119
+ throw unreadable(error);
120
+ });
121
+ if (!insideProject(project, path)) throw outside();
122
+
123
+ let markup;
124
+ try {
125
+ if (!(await stat(path)).isFile()) throw new Error("Expected a file.");
126
+ markup = (await readFile(path, "utf8")).replace(/^\uFEFF/, "");
127
+ } catch (error) {
128
+ throw unreadable(error);
129
+ }
130
+
131
+ checkHeadFragment(markup, label);
132
+ return markup;
133
+ }
@@ -0,0 +1,10 @@
1
+ import type { JSX } from "react";
2
+
3
+ export interface LibraryPublisher {
4
+ label: string;
5
+ url?: string;
6
+ }
7
+
8
+ export function LibraryFooter(props: {
9
+ publisher?: LibraryPublisher;
10
+ }): JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { createElement as element } from "react";
2
+
3
+ export function LibraryFooter({ publisher }) {
4
+ const label = publisher
5
+ ? element(
6
+ publisher.url ? "a" : "span",
7
+ { className: "library-publisher", href: publisher.url },
8
+ publisher.label
9
+ )
10
+ : null;
11
+ return element(
12
+ "footer",
13
+ { className: "library-footer" },
14
+ label,
15
+ element(
16
+ "a",
17
+ { href: "https://github.com/kkm-horikawa/grimoire3d" },
18
+ "Grimoire3D"
19
+ )
20
+ );
21
+ }
package/cli/markdown.js CHANGED
@@ -127,6 +127,17 @@ export function readMarkdown(source) {
127
127
  typeof metadata.socialImage === "string"
128
128
  ? metadata.socialImage.trim()
129
129
  : undefined,
130
+ category:
131
+ typeof metadata.category === "string"
132
+ ? metadata.category.trim() || undefined
133
+ : undefined,
134
+ date: metadata.date,
135
+ chapters: metadata.chapters,
136
+ noindex: metadata.noindex === true,
137
+ coverImage:
138
+ typeof metadata.coverImage === "string"
139
+ ? metadata.coverImage.trim() || undefined
140
+ : undefined,
130
141
  },
131
142
  excerpt: [...excerpt].slice(0, 170).join(""),
132
143
  markdown,
@@ -5,7 +5,9 @@ import { renderToStaticMarkup } from "react-dom/server";
5
5
  import Markdown, { defaultUrlTransform } from "react-markdown";
6
6
  import remarkDirective from "remark-directive";
7
7
  import remarkGfm from "remark-gfm";
8
+ import { BookCover } from "./book-cover.js";
8
9
  import { coverOptions, selectCover } from "./cover-options.js";
10
+ import { LibraryFooter } from "./library-footer.js";
9
11
  import { remarkGrimoire } from "./markup.js";
10
12
  import { readerPath, readLegacyRoute } from "./routes.js";
11
13
  import { videoEmbed } from "./video-url.js";
@@ -20,10 +22,12 @@ function escapeHtml(value) {
20
22
  );
21
23
  }
22
24
 
25
+ const noindexMeta = '<meta name="robots" content="noindex">';
26
+
23
27
  export function previewHead(manifest) {
24
28
  return [
25
29
  '<meta name="grimoire-preview" content="live">',
26
- '<meta name="robots" content="noindex">',
30
+ noindexMeta,
27
31
  manifest.description &&
28
32
  `<meta name="description" content="${escapeHtml(manifest.description)}">`,
29
33
  ]
@@ -47,6 +51,7 @@ function pageHead(site, page, route, prefix) {
47
51
  const metadata = [
48
52
  `<meta name="grimoire-static" content="${prefix}">`,
49
53
  canonical && `<link rel="canonical" href="${escapeHtml(canonical)}">`,
54
+ page.noindex && noindexMeta,
50
55
  description &&
51
56
  `<meta name="description" content="${escapeHtml(description)}">`,
52
57
  site.author && `<meta name="author" content="${escapeHtml(site.author)}">`,
@@ -184,8 +189,8 @@ function initialBookMarkup(book, chapter, locale) {
184
189
  };
185
190
  }
186
191
 
187
- function replaceShell(template, site, head, prefix, body, reader) {
188
- return template
192
+ function replaceShell(template, site, head, prefix, body, reader, headMarkup) {
193
+ const html = template
189
194
  .replace('<html lang="en">', `<html lang="${site.locale}">`)
190
195
  .replace(
191
196
  /<script type="module"[^>]*src="([^"]+)"[^>]*><\/script>/,
@@ -204,6 +209,12 @@ function replaceShell(template, site, head, prefix, body, reader) {
204
209
  () => `<title>${escapeHtml(head.title)}</title>\n${head.metadata}`
205
210
  )
206
211
  .replace('<div id="root"></div>', () => `<div id="root">${body}</div>`);
212
+ return headMarkup
213
+ ? html.replace(
214
+ /<head>(\s*<meta charset="[^"]+"\s*\/?>)?/i,
215
+ (start) => `${start}\n${headMarkup}\n`
216
+ )
217
+ : html;
207
218
  }
208
219
 
209
220
  function startAfterArtwork(entry, reader) {
@@ -255,6 +266,10 @@ function assetNamed(assets, prefix, name, ext = ".avif") {
255
266
 
256
267
  function staticShelf(site, prefix, assets, label) {
257
268
  const books = site.books.slice(0, 12);
269
+ // Enhance the entire bookshelf together when adding catalog controls or custom art.
270
+ const reuseShelfArt = !site.books.some(
271
+ (book) => book.category || book.date || book.coverImage
272
+ );
258
273
  const button = site.locale === "ja" ? "目録" : "Index";
259
274
  const titleStyle = (finish) =>
260
275
  finish.lettering
@@ -275,13 +290,23 @@ function staticShelf(site, prefix, assets, label) {
275
290
  `cover-${finish.base}-mobile`
276
291
  );
277
292
  const style = `--cover-filter:${finish.filter};${titleStyle(finish)}`;
278
- return `<div class="shelf-cell"><a class="volume" href="${prefix + escapeHtml(readerPath(book.id))}" aria-label="${escapeHtml(book.title)}" style="${style}">${cover ? `<picture>${mobileCover ? `<source media="(max-width: 699px)" srcset="${mobileCover}">` : ""}<img class="volume-render" src="${prefix}assets/${cover}" width="600" height="760" alt="" fetchpriority="low"${index > 2 ? ' loading="lazy"' : ""}></picture>` : ""}<span class="volume-title">${escapeHtml(book.title)}</span></a></div>`;
293
+ const face = renderToStaticMarkup(
294
+ element(BookCover, {
295
+ title: book.title,
296
+ src: cover && `${prefix}assets/${cover}`,
297
+ compact: mobileCover,
298
+ artwork: book.coverImage && prefix + book.coverImage.slice(2),
299
+ loading: index < 3 ? "eager" : "lazy",
300
+ })
301
+ );
302
+ return `<div class="shelf-cell"><a class="volume" href="${prefix + escapeHtml(readerPath(book.id))}" aria-label="${escapeHtml(book.title)}" style="${style}">${face}</a></div>`;
279
303
  })
280
304
  .join("");
281
305
  return `<main class="library"><header class="library-brand brand">${escapeHtml(site.title)}</header>
282
306
  <div class="library-heading${site.books.length > 6 ? " library-heading-sticky" : ""}"><h1>${label}</h1></div>
283
- <div class="shelf resting-shelf${site.books.length > 6 ? " shelf-many" : ""}"${books.length >= 3 && books.length <= 4 ? ' data-mobile-rows="2"' : ""}><div class="shelf-art" data-initial-shelf aria-hidden="true"></div><div class="shelf-grid">${covers}</div></div>
307
+ <div class="shelf resting-shelf${site.books.length > 6 ? " shelf-many" : ""}"${books.length >= 3 && books.length <= 4 ? ' data-mobile-rows="2"' : ""}><div class="shelf-art"${reuseShelfArt ? " data-initial-shelf" : ""} aria-hidden="true"></div><div class="shelf-grid">${covers}</div></div>
284
308
  ${site.books.length > 12 ? `<details><summary>${button}</summary>${linkList(site.books.map((book) => ({ title: book.title, href: prefix + readerPath(book.id) })))}</details>` : ""}
309
+ ${renderToStaticMarkup(element(LibraryFooter, { publisher: site.footer }))}
285
310
  </main>`;
286
311
  }
287
312
 
@@ -334,7 +359,12 @@ function staticChapter({ site, book, page, prefix, assets, libraryLabel }) {
334
359
  </main>`;
335
360
  }
336
361
 
337
- export async function writeStaticPages(templateDir, destination, library) {
362
+ export async function writeStaticPages(
363
+ templateDir,
364
+ destination,
365
+ library,
366
+ headMarkup = ""
367
+ ) {
338
368
  const template = await readFile(join(templateDir, "index.html"), "utf8");
339
369
  const site = library.manifest;
340
370
  const books = new Map(library.books.map((book) => [book.id, book]));
@@ -415,18 +445,27 @@ export async function writeStaticPages(templateDir, destination, library) {
415
445
  head,
416
446
  prefix,
417
447
  body(prefix),
418
- book ? reader : undefined
448
+ book ? reader : undefined,
449
+ headMarkup
419
450
  )
420
451
  );
421
- if (head.canonical) urls.push(head.canonical);
452
+ if (head.canonical && !page.noindex) urls.push(head.canonical);
422
453
  }
423
- await write(site, [], (prefix) =>
424
- staticShelf(site, prefix, assets, libraryLabel)
454
+ // A single-book site opens the first chapter at the site root as well.
455
+ const firstChapter = chapters.get(site.books[0]?.id)?.[0];
456
+ await write(
457
+ { ...site, noindex: !site.shelf && firstChapter?.noindex },
458
+ [],
459
+ (prefix) => staticShelf(site, prefix, assets, libraryLabel)
425
460
  );
426
461
  for (const book of site.books) {
427
462
  const pages = chapters.get(book.id) ?? [];
428
463
  await write(
429
- { title: book.title, description: pages[0]?.description },
464
+ {
465
+ title: book.title,
466
+ description: pages[0]?.description,
467
+ noindex: pages[0]?.noindex,
468
+ },
430
469
  ["read", book.id],
431
470
  (prefix) =>
432
471
  `<main class="static-reading"><nav><a href="${prefix}">${libraryLabel}</a></nav><h1>${escapeHtml(book.title)}</h1>${linkList(
@@ -452,7 +491,7 @@ export async function writeStaticPages(templateDir, destination, library) {
452
491
  );
453
492
  }
454
493
  }
455
- if (site.siteUrl) {
494
+ if (urls.length) {
456
495
  await writeFile(
457
496
  join(destination, "sitemap.xml"),
458
497
  `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.map((url) => ` <url><loc>${escapeHtml(url)}</loc></url>`).join("\n")}\n</urlset>\n`