grimoire3d 0.0.0-dev.997a5eb → 0.0.0-dev.b2eaeeb
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/README.md +28 -124
- package/cli/cli.js +348 -0
- package/cli/content.js +382 -0
- package/cli/cover-options.d.ts +15 -0
- package/cli/cover-options.js +105 -0
- package/cli/markdown.js +139 -0
- package/cli/markup.d.ts +3 -0
- package/cli/markup.js +60 -0
- package/cli/routes.d.ts +6 -0
- package/cli/routes.js +19 -0
- package/cli/static-pages.js +467 -0
- package/cli/video-url.d.ts +5 -0
- package/cli/video-url.js +51 -0
- package/dist/BookViewer-CwCn-LTn.js +332 -0
- package/dist/components/BookModel.d.ts +20 -0
- package/dist/components/BookViewer.d.ts +17 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +5 -0
- package/dist/grimoire3d.css +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/main.d.ts +1 -0
- package/dist/site/assets/BookReader-BxKrexRZ.js +2 -0
- package/dist/site/assets/BookScene-DN1_Kxe3.js +4045 -0
- package/dist/site/assets/MermaidDiagram-Dma3Cwvn.js +312 -0
- package/dist/site/assets/PageMarkdown-C-gI_dXg.js +37 -0
- package/dist/site/assets/abnfDiagram-S7VZAUFO-BIA2ezcb.js +1 -0
- package/dist/site/assets/alcove-cyX4Tv3E.avif +0 -0
- package/dist/site/assets/architectureDiagram-YGSQEFNW-DMB5UtEZ.js +36 -0
- package/dist/site/assets/blockDiagram-APKKGZFW-CeBSUSaW.js +140 -0
- package/dist/site/assets/bpmnIcons-APHXDYXF-ByGoYv9M.js +1 -0
- package/dist/site/assets/c4Diagram-KJ2TOQU5-BmBo2PHu.js +38 -0
- package/dist/site/assets/catalog-07-UR91A.avif +0 -0
- package/dist/site/assets/chunk-2Q5K7J3B-BDgDFVbx.js +1 -0
- package/dist/site/assets/chunk-5VM5RSS4-CCNs5Q1j.js +15 -0
- package/dist/site/assets/chunk-HFQBQIA3-B8uXoLoT.js +1 -0
- package/dist/site/assets/chunk-JWPE2WC7-BiKy7CcD.js +1 -0
- package/dist/site/assets/chunk-KQLB2F66-D_kpUTKA.js +2 -0
- package/dist/site/assets/chunk-KS47KZWR-C_s_qnHf.js +1 -0
- package/dist/site/assets/chunk-OY52VR5R-D8f7gl4W.js +88 -0
- package/dist/site/assets/chunk-TU62E6Q5-Bm44Znlj.js +1 -0
- package/dist/site/assets/chunk-XXDRQBXY-ChLLr56_.js +1 -0
- package/dist/site/assets/classDiagram-v2-L25IHNXF-DwKi-r2i.js +217 -0
- package/dist/site/assets/cose-bilkent-JH36ORCC-8N6YUm1i.js +1 -0
- package/dist/site/assets/cover-blue-Bh8Xp4T5.avif +0 -0
- package/dist/site/assets/cover-blue-mobile-YcuYIg0I.avif +0 -0
- package/dist/site/assets/cover-green-By13JjUx.avif +0 -0
- package/dist/site/assets/cover-green-mobile-BNTgNt7v.avif +0 -0
- package/dist/site/assets/cover-red-mobile-DHOCz3wI.avif +0 -0
- package/dist/site/assets/cover-red-qvZEk3PI.avif +0 -0
- package/dist/site/assets/cynefin-EF2NZ3EQ-Df5ATUPb.js +141 -0
- package/dist/site/assets/cynefinDiagram-L36ESFBY-DmAbfxAU.js +62 -0
- package/dist/site/assets/cytoscape.esm-BHa1VTXv.js +321 -0
- package/dist/site/assets/d3-scale-4DPf7zan.js +1 -0
- package/dist/site/assets/dagre-SPEB5RXH-B_2grAE7.js +4 -0
- package/dist/site/assets/diagram-3B7GL73J-C9FXwDlf.js +200 -0
- package/dist/site/assets/diagram-DNEMPZML-DflAT3gr.js +24 -0
- package/dist/site/assets/diagram-L3MUGCDN-B04gjrM_.js +41 -0
- package/dist/site/assets/diagram-LA4NIPWU-cfWJg8HX.js +24 -0
- package/dist/site/assets/diagram-MHCOC4E2-jRbOs2Df.js +3 -0
- package/dist/site/assets/diagram-XPFHEONP-yR45xV59.js +30 -0
- package/dist/site/assets/ebnfDiagram-UZSYDL2S-DlmNJUx4.js +1 -0
- package/dist/site/assets/elk-XV6XMXQE-cHLdRN7u.js +27 -0
- package/dist/site/assets/erDiagram-EYBAPDEH-7HsRsmBI.js +99 -0
- package/dist/site/assets/es-DoLiZPBX.js +2 -0
- package/dist/site/assets/favicon-C9YRygge.png +0 -0
- package/dist/site/assets/flowDiagram-MALGAFMO-DoJjw4RA.js +213 -0
- package/dist/site/assets/ganttDiagram-23REXITY-D2uZtX_8.js +292 -0
- package/dist/site/assets/gitGraphDiagram-STJD7YCW-CjftfLRK.js +106 -0
- package/dist/site/assets/graph-D8UmR1vK.js +1 -0
- package/dist/site/assets/index-CqcyU6rA.js +1 -0
- package/dist/site/assets/index-DWW-KDWe.css +1 -0
- package/dist/site/assets/infoDiagram-KBXO4MBG-HN-1tqq1.js +2 -0
- package/dist/site/assets/ishikawaDiagram-M35NCXHK-DcnRwsO0.js +70 -0
- package/dist/site/assets/journeyDiagram-OPLOXDXO-CMZGp8mG.js +139 -0
- package/dist/site/assets/kanban-definition-BZKZHSQY-C9vGS-EW.js +89 -0
- package/dist/site/assets/katex-DLSO0Xi6.js +257 -0
- package/dist/site/assets/mindmap-definition-I2QAS2VK-R2SGME7R.js +98 -0
- package/dist/site/assets/mobile-cabinet-BUr9vtlo.avif +0 -0
- package/dist/site/assets/mobile-cabinet-sm-pauJUfRH.avif +0 -0
- package/dist/site/assets/mobile-paper-DF0CuLes.avif +0 -0
- package/dist/site/assets/mobile-paper-sm-77eJHX6h.avif +0 -0
- package/dist/site/assets/open-nWGD2hyb.glb +0 -0
- package/dist/site/assets/pegDiagram-FD4XPPHP-eDMY4Hpd.js +1 -0
- package/dist/site/assets/pieDiagram-J4AKIIQI-DoHNiqwi.js +39 -0
- package/dist/site/assets/quadrantDiagram-XTYBLID2-Bz5idec8.js +7 -0
- package/dist/site/assets/railroadDiagram-MRQ6NCDL-DHJisW8P.js +1 -0
- package/dist/site/assets/requirementDiagram-Y7LWUY3S-5aETRIZz.js +84 -0
- package/dist/site/assets/resting-amber-BSjsErIg.avif +0 -0
- package/dist/site/assets/resting-black-DDQ4XMJI.avif +0 -0
- package/dist/site/assets/resting-blue-DDOT8IQ8.avif +0 -0
- package/dist/site/assets/resting-green-DkRrV8eX.avif +0 -0
- package/dist/site/assets/resting-ivory-CEqoG5yI.avif +0 -0
- package/dist/site/assets/resting-plum-B-8tkSmP.avif +0 -0
- package/dist/site/assets/resting-red-D0hLpMpz.avif +0 -0
- package/dist/site/assets/resting-slate-CH8Z_Rky.avif +0 -0
- package/dist/site/assets/resting-teal-CGt6jFmT.avif +0 -0
- package/dist/site/assets/resting-walnut-t3WgHgUO.avif +0 -0
- package/dist/site/assets/sankeyDiagram-WGJFYUXA-C7O4v9rg.js +40 -0
- package/dist/site/assets/search-stage-B8cH1AE_.avif +0 -0
- package/dist/site/assets/search-stage-mobile-BZ58ew4F.avif +0 -0
- package/dist/site/assets/sequenceDiagram-5NDRBG5M-D4sVU6s6.js +169 -0
- package/dist/site/assets/sizeCapture-INFHLROL-Bi2DkFS3.js +1 -0
- package/dist/site/assets/stateDiagram-v2-FJ4FJNEA-WqXK7YOd.js +291 -0
- package/dist/site/assets/swimlanes-UMQ2AFYF-Czo9WyoV.js +1 -0
- package/dist/site/assets/swimlanesDiagram-OMPLPG4O-BH5aEx0X.js +8 -0
- package/dist/site/assets/three-core-Dkab0Vtn.js +40 -0
- package/dist/site/assets/timeline-definition-SEUHKTQE-KGKDZW_q.js +120 -0
- package/dist/site/assets/usecaseDiagram-AFA6YXN4-S0_9S22K.js +370 -0
- package/dist/site/assets/vennDiagram-NNMJR3RB-DJOjLlbA.js +34 -0
- package/dist/site/assets/wardleyDiagram-S7YFUSEH-BnzYzY-n.js +78 -0
- package/dist/site/assets/xychartDiagram-GGNKY7IX-CKOVznoa.js +7 -0
- package/dist/site/index.html +14 -0
- package/dist/types/index.d.ts +163 -0
- package/package.json +27 -11
- package/dist/grimoire3d.js +0 -82131
- package/dist/grimoire3d.umd.cjs +0 -4470
package/cli/routes.d.ts
ADDED
package/cli/routes.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** @param {string} book @param {string} [chapter] */
|
|
2
|
+
export function readerPath(book, chapter) {
|
|
3
|
+
return `read/${[book, ...(chapter?.split("/") ?? [])].map(encodeURIComponent).join("/")}/`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** @param {string} hash */
|
|
7
|
+
export function readLegacyRoute(hash) {
|
|
8
|
+
const [path, search] = hash.slice(1).split("?", 2);
|
|
9
|
+
try {
|
|
10
|
+
const [, book, chapter] = (path ?? "").split("/");
|
|
11
|
+
return {
|
|
12
|
+
book: book ? decodeURIComponent(book) : undefined,
|
|
13
|
+
page: chapter ? decodeURIComponent(chapter) : undefined,
|
|
14
|
+
anchor: new URLSearchParams(search).get("anchor"),
|
|
15
|
+
};
|
|
16
|
+
} catch {
|
|
17
|
+
return { book: undefined, page: undefined, anchor: null };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { createElement as element } from "react";
|
|
4
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
5
|
+
import Markdown, { defaultUrlTransform } from "react-markdown";
|
|
6
|
+
import remarkDirective from "remark-directive";
|
|
7
|
+
import remarkGfm from "remark-gfm";
|
|
8
|
+
import { coverOptions, selectCover } from "./cover-options.js";
|
|
9
|
+
import { remarkGrimoire } from "./markup.js";
|
|
10
|
+
import { readerPath, readLegacyRoute } from "./routes.js";
|
|
11
|
+
import { videoEmbed } from "./video-url.js";
|
|
12
|
+
|
|
13
|
+
function escapeHtml(value) {
|
|
14
|
+
return String(value).replace(
|
|
15
|
+
/[&<>"']/g,
|
|
16
|
+
(symbol) =>
|
|
17
|
+
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[
|
|
18
|
+
symbol
|
|
19
|
+
]
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function previewHead(manifest) {
|
|
24
|
+
return [
|
|
25
|
+
'<meta name="grimoire-preview" content="live">',
|
|
26
|
+
'<meta name="robots" content="noindex">',
|
|
27
|
+
manifest.description &&
|
|
28
|
+
`<meta name="description" content="${escapeHtml(manifest.description)}">`,
|
|
29
|
+
]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.join("\n");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function pageHead(site, page, route, prefix) {
|
|
35
|
+
const canonical = site.siteUrl && new URL(route, site.siteUrl).href;
|
|
36
|
+
const title =
|
|
37
|
+
page.title !== site.title ? `${page.title} · ${site.title}` : site.title;
|
|
38
|
+
const description = page.description || site.description;
|
|
39
|
+
const image = page.socialImage || site.socialImage;
|
|
40
|
+
const imageUrl =
|
|
41
|
+
image &&
|
|
42
|
+
(site.siteUrl
|
|
43
|
+
? new URL(image, site.siteUrl).href
|
|
44
|
+
: image.startsWith("./")
|
|
45
|
+
? prefix + image.slice(2)
|
|
46
|
+
: image);
|
|
47
|
+
const metadata = [
|
|
48
|
+
`<meta name="grimoire-static" content="${prefix}">`,
|
|
49
|
+
canonical && `<link rel="canonical" href="${escapeHtml(canonical)}">`,
|
|
50
|
+
description &&
|
|
51
|
+
`<meta name="description" content="${escapeHtml(description)}">`,
|
|
52
|
+
site.author && `<meta name="author" content="${escapeHtml(site.author)}">`,
|
|
53
|
+
...Object.entries({
|
|
54
|
+
"og:type": page.chapter ? "article" : "website",
|
|
55
|
+
"og:title": title,
|
|
56
|
+
"og:site_name": site.title,
|
|
57
|
+
"og:description": description,
|
|
58
|
+
"og:url": canonical,
|
|
59
|
+
"og:image": imageUrl,
|
|
60
|
+
"og:locale": site.locale === "ja" ? "ja_JP" : "en_US",
|
|
61
|
+
})
|
|
62
|
+
.filter(([, value]) => value)
|
|
63
|
+
.map(
|
|
64
|
+
([key, value]) =>
|
|
65
|
+
`<meta property="${key}" content="${escapeHtml(value)}">`
|
|
66
|
+
),
|
|
67
|
+
`<meta name="twitter:card" content="${imageUrl ? "summary_large_image" : "summary"}">`,
|
|
68
|
+
];
|
|
69
|
+
if (canonical) {
|
|
70
|
+
const data = page.chapter
|
|
71
|
+
? {
|
|
72
|
+
"@context": "https://schema.org",
|
|
73
|
+
"@type": "Article",
|
|
74
|
+
headline: page.title,
|
|
75
|
+
mainEntityOfPage: canonical,
|
|
76
|
+
url: canonical,
|
|
77
|
+
inLanguage: site.locale,
|
|
78
|
+
description,
|
|
79
|
+
image: imageUrl,
|
|
80
|
+
author: site.author
|
|
81
|
+
? { "@type": "Person", name: site.author }
|
|
82
|
+
: undefined,
|
|
83
|
+
}
|
|
84
|
+
: {
|
|
85
|
+
"@context": "https://schema.org",
|
|
86
|
+
"@type": route ? "CollectionPage" : "WebSite",
|
|
87
|
+
name: page.title,
|
|
88
|
+
url: canonical,
|
|
89
|
+
inLanguage: site.locale,
|
|
90
|
+
description,
|
|
91
|
+
};
|
|
92
|
+
metadata.push(
|
|
93
|
+
`<script type="application/ld+json">${JSON.stringify(data).replace(/</g, "\\u003c")}</script>`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return { title, canonical, metadata: metadata.filter(Boolean).join("\n") };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function markdownContent(page, locale, prefix, anchors = true) {
|
|
100
|
+
const components = Object.fromEntries(
|
|
101
|
+
["h1", "h2", "h3", "h4", "h5", "h6"].map((tag) => [
|
|
102
|
+
tag,
|
|
103
|
+
({ node, children }) =>
|
|
104
|
+
element(
|
|
105
|
+
tag,
|
|
106
|
+
{
|
|
107
|
+
id: anchors
|
|
108
|
+
? page.headingIds?.[node?.position?.start.offset]
|
|
109
|
+
: undefined,
|
|
110
|
+
},
|
|
111
|
+
children
|
|
112
|
+
),
|
|
113
|
+
])
|
|
114
|
+
);
|
|
115
|
+
components.img = ({ src, alt, title }) => {
|
|
116
|
+
if (!src) return element("span", null, alt);
|
|
117
|
+
const embed = videoEmbed(src);
|
|
118
|
+
if (embed) return element("a", { href: src }, alt || embed.provider);
|
|
119
|
+
if (/\.mp4(?:[?#]|$)/i.test(src)) {
|
|
120
|
+
return element("video", {
|
|
121
|
+
src,
|
|
122
|
+
controls: true,
|
|
123
|
+
preload: "metadata",
|
|
124
|
+
playsInline: true,
|
|
125
|
+
"aria-label": alt || title,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return element("img", { src, alt: alt || "", title, loading: "lazy" });
|
|
129
|
+
};
|
|
130
|
+
return renderToStaticMarkup(
|
|
131
|
+
element(
|
|
132
|
+
Markdown,
|
|
133
|
+
{
|
|
134
|
+
components,
|
|
135
|
+
remarkPlugins: [remarkGfm, remarkDirective, [remarkGrimoire, locale]],
|
|
136
|
+
urlTransform(url) {
|
|
137
|
+
let target = page.links[url];
|
|
138
|
+
try {
|
|
139
|
+
target ??= page.links[decodeURI(url)];
|
|
140
|
+
} catch {}
|
|
141
|
+
if (target === "") return undefined;
|
|
142
|
+
if (target?.startsWith("#/")) {
|
|
143
|
+
const { book, page: chapter, anchor } = readLegacyRoute(target);
|
|
144
|
+
if (!book) return prefix;
|
|
145
|
+
return (
|
|
146
|
+
prefix +
|
|
147
|
+
readerPath(book, chapter) +
|
|
148
|
+
(anchor ? `#${encodeURIComponent(anchor)}` : "")
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return target?.startsWith("./")
|
|
152
|
+
? prefix + target.slice(2)
|
|
153
|
+
: defaultUrlTransform(url);
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
page.markdown
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function initialBookMarkup(book, chapter, locale) {
|
|
162
|
+
if (!book) return undefined;
|
|
163
|
+
const first = Math.max(
|
|
164
|
+
0,
|
|
165
|
+
book.pages.findIndex((page) => page.id === chapter)
|
|
166
|
+
);
|
|
167
|
+
const other = first % 2 === 0 ? first + 1 : first - 1;
|
|
168
|
+
return {
|
|
169
|
+
...book,
|
|
170
|
+
pages: book.pages.map((page, index) => {
|
|
171
|
+
if (
|
|
172
|
+
(index !== first && index !== other) ||
|
|
173
|
+
page.group ||
|
|
174
|
+
page.markdown.includes("![") ||
|
|
175
|
+
Object.keys(page.links).length
|
|
176
|
+
)
|
|
177
|
+
return page;
|
|
178
|
+
const preparedHtml = markdownContent(page, locale, "./");
|
|
179
|
+
// Interactive media, wide tables and diagrams are enhanced by the reader when needed.
|
|
180
|
+
if (/<(?:video|img|table)\b|language-mermaid/.test(preparedHtml))
|
|
181
|
+
return page;
|
|
182
|
+
return { ...page, preparedHtml };
|
|
183
|
+
}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function replaceShell(template, site, head, prefix, body, reader) {
|
|
188
|
+
return template
|
|
189
|
+
.replace('<html lang="en">', `<html lang="${site.locale}">`)
|
|
190
|
+
.replace(
|
|
191
|
+
/<script type="module"[^>]*src="([^"]+)"[^>]*><\/script>/,
|
|
192
|
+
(_, source) =>
|
|
193
|
+
startAfterArtwork(
|
|
194
|
+
prefix + source.replace(/^\.\//, ""),
|
|
195
|
+
reader ? `${prefix}assets/${reader}` : undefined
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
.replace(
|
|
199
|
+
/\b(src|href)="\.\/assets\//g,
|
|
200
|
+
(_, attribute) => `${attribute}="${prefix}assets/`
|
|
201
|
+
)
|
|
202
|
+
.replace(
|
|
203
|
+
/<title>[^<]*<\/title>/,
|
|
204
|
+
() => `<title>${escapeHtml(head.title)}</title>\n${head.metadata}`
|
|
205
|
+
)
|
|
206
|
+
.replace('<div id="root"></div>', () => `<div id="root">${body}</div>`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function startAfterArtwork(entry, reader) {
|
|
210
|
+
const path = JSON.stringify(entry);
|
|
211
|
+
const readerPath = JSON.stringify(reader ?? "");
|
|
212
|
+
return `<script type="module">
|
|
213
|
+
const events = ["pointerdown","keydown"];
|
|
214
|
+
let started = false;
|
|
215
|
+
function start() {
|
|
216
|
+
if (started) return;
|
|
217
|
+
started = true;
|
|
218
|
+
for (const event of events) window.removeEventListener(event,start,true);
|
|
219
|
+
const reader = ${readerPath};
|
|
220
|
+
if (reader) {
|
|
221
|
+
const preload = document.createElement("link");
|
|
222
|
+
preload.rel = "modulepreload";
|
|
223
|
+
preload.href = reader;
|
|
224
|
+
document.head.append(preload);
|
|
225
|
+
}
|
|
226
|
+
void import(${path});
|
|
227
|
+
}
|
|
228
|
+
const art = [...document.querySelectorAll("link[data-first-art]")].find(link => matchMedia(link.media).matches);
|
|
229
|
+
if (!art || !matchMedia("(max-width: 699px)").matches) start();
|
|
230
|
+
else {
|
|
231
|
+
for (const event of events) window.addEventListener(event,start,{capture:true,once:true});
|
|
232
|
+
const image = new Image();
|
|
233
|
+
const painted = () => requestAnimationFrame(() => requestAnimationFrame(start));
|
|
234
|
+
// The CSS background owns the decode. Wait for its bytes without decoding another bitmap.
|
|
235
|
+
image.addEventListener("load", painted, { once:true });
|
|
236
|
+
image.addEventListener("error", painted, { once:true });
|
|
237
|
+
image.src = art.href;
|
|
238
|
+
}
|
|
239
|
+
</script>`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function linkList(items) {
|
|
243
|
+
return `<ul>${items.map(({ href, title }) => `<li><a href="${escapeHtml(href)}">${escapeHtml(title)}</a></li>`).join("")}</ul>`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function assetNamed(assets, prefix, name, ext = ".avif") {
|
|
247
|
+
const asset = assets.find(
|
|
248
|
+
(file) =>
|
|
249
|
+
file.startsWith(`${name}-`) &&
|
|
250
|
+
!file.startsWith(`${name}-sm-`) &&
|
|
251
|
+
file.endsWith(ext)
|
|
252
|
+
);
|
|
253
|
+
return asset ? `${prefix}assets/${asset}` : undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function staticShelf(site, prefix, assets, label) {
|
|
257
|
+
const books = site.books.slice(0, 12);
|
|
258
|
+
const button = site.locale === "ja" ? "目録" : "Index";
|
|
259
|
+
const titleStyle = (finish) =>
|
|
260
|
+
finish.lettering
|
|
261
|
+
? `--cover-lettering:${finish.lettering};--cover-title-shadow:0 1px 1px #fbe9c6b0;`
|
|
262
|
+
: "";
|
|
263
|
+
const covers = books
|
|
264
|
+
.map((book, index) => {
|
|
265
|
+
const finish = coverOptions[selectCover(book.id, book.cover)];
|
|
266
|
+
const cover = assets.find(
|
|
267
|
+
(file) =>
|
|
268
|
+
file.startsWith(`cover-${finish.base}-`) &&
|
|
269
|
+
!file.startsWith(`cover-${finish.base}-mobile-`) &&
|
|
270
|
+
file.endsWith(".avif")
|
|
271
|
+
);
|
|
272
|
+
const mobileCover = assetNamed(
|
|
273
|
+
assets,
|
|
274
|
+
prefix,
|
|
275
|
+
`cover-${finish.base}-mobile`
|
|
276
|
+
);
|
|
277
|
+
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>`;
|
|
279
|
+
})
|
|
280
|
+
.join("");
|
|
281
|
+
return `<main class="library"><header class="library-brand brand">${escapeHtml(site.title)}</header>
|
|
282
|
+
<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>
|
|
284
|
+
${site.books.length > 12 ? `<details><summary>${button}</summary>${linkList(site.books.map((book) => ({ title: book.title, href: prefix + readerPath(book.id) })))}</details>` : ""}
|
|
285
|
+
</main>`;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function staticChapter({ site, book, page, prefix, assets, libraryLabel }) {
|
|
289
|
+
const index = Math.max(
|
|
290
|
+
0,
|
|
291
|
+
book.pages.findIndex((sheet) => sheet.id === page.chapter)
|
|
292
|
+
);
|
|
293
|
+
const left = index % 2 === 0;
|
|
294
|
+
const paired = book.pages[index + (left ? 1 : -1)];
|
|
295
|
+
const finish = selectCover(
|
|
296
|
+
book.id,
|
|
297
|
+
book.cover ?? (!site.shelf ? "red" : undefined)
|
|
298
|
+
);
|
|
299
|
+
const option = coverOptions[finish];
|
|
300
|
+
const background = assetNamed(assets, prefix, `resting-${finish}`);
|
|
301
|
+
const label = site.locale === "ja" ? "目次" : "Contents";
|
|
302
|
+
const magic = site.locale === "ja" ? "超魔導" : "Spell mode";
|
|
303
|
+
const previous = book.pages[index - 1];
|
|
304
|
+
const next = book.pages[index + 1];
|
|
305
|
+
function linkTo(sheet, symbol, alt) {
|
|
306
|
+
const path =
|
|
307
|
+
sheet &&
|
|
308
|
+
prefix +
|
|
309
|
+
readerPath(book.id, sheet.id) +
|
|
310
|
+
(sheet.section ? `#${encodeURIComponent(sheet.section.id)}` : "");
|
|
311
|
+
return path
|
|
312
|
+
? `<a class="turn-button" href="${escapeHtml(path)}" aria-label="${alt}">${symbol}</a>`
|
|
313
|
+
: `<button class="turn-button" disabled aria-label="${alt}">${symbol}</button>`;
|
|
314
|
+
}
|
|
315
|
+
return `<main class="reader static-reader">
|
|
316
|
+
<header class="reader-header"${site.magicMode ? ' data-magic-control="true"' : ""}>
|
|
317
|
+
<a class="brand" href="${prefix}">${libraryLabel}</a>
|
|
318
|
+
${site.magicMode ? `<span data-fallback-magic>${magic}</span>` : ""}
|
|
319
|
+
<a class="contents-button" href="${prefix + escapeHtml(readerPath(book.id))}">${label}</a>
|
|
320
|
+
</header>
|
|
321
|
+
<div class="reader-stage" data-frame="reading" data-binding="${finish}" style="--leather-edge:${option.edge};--leather-filter:${option.mobile}">
|
|
322
|
+
<div class="book-fallback" data-initial-book="${escapeHtml(book.id)}" aria-hidden="true">${background ? `<div class="book-resting" style="background-image:url('${background}')"></div>` : ""}</div>
|
|
323
|
+
<div class="book-sheet book-sheet--right${left ? " static-main-left" : ""}">
|
|
324
|
+
<article class="page-text">${page.hasTitle ? "" : `<h1>${escapeHtml(page.title)}</h1>`}${markdownContent(page, site.locale, prefix)}</article>
|
|
325
|
+
<span class="folio-number" aria-hidden="true">${index + 1}</span>
|
|
326
|
+
</div>
|
|
327
|
+
${paired ? `<div class="book-sheet book-sheet--${left ? "right" : "left"} static-neighbor"><article class="page-text">${markdownContent(paired, site.locale, prefix, false)}</article><span class="folio-number" aria-hidden="true">${index + (left ? 2 : 0)}</span></div>` : ""}
|
|
328
|
+
</div>
|
|
329
|
+
<nav class="reader-pagination" aria-label="${label}">
|
|
330
|
+
${linkTo(previous, "‹", site.locale === "ja" ? "前のページ" : "Previous page")}
|
|
331
|
+
<div class="reading-position"><span>${escapeHtml(page.title)}</span><span>${index + 1} / ${book.pages.length}</span></div>
|
|
332
|
+
${linkTo(next, "›", site.locale === "ja" ? "次のページ" : "Next page")}
|
|
333
|
+
</nav>
|
|
334
|
+
</main>`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export async function writeStaticPages(templateDir, destination, library) {
|
|
338
|
+
const template = await readFile(join(templateDir, "index.html"), "utf8");
|
|
339
|
+
const site = library.manifest;
|
|
340
|
+
const books = new Map(library.books.map((book) => [book.id, book]));
|
|
341
|
+
const assets = await readdir(join(templateDir, "assets")).catch((error) => {
|
|
342
|
+
if (error.code === "ENOENT") return [];
|
|
343
|
+
throw error;
|
|
344
|
+
});
|
|
345
|
+
const reader = assets.find((name) => /^BookReader-.*\.js$/.test(name));
|
|
346
|
+
const libraryLabel = site.locale === "ja" ? "書架" : "Library";
|
|
347
|
+
const urls = [];
|
|
348
|
+
const chapters = new Map();
|
|
349
|
+
for (const page of library.documents) {
|
|
350
|
+
const list = chapters.get(page.book) ?? [];
|
|
351
|
+
list.push(page);
|
|
352
|
+
chapters.set(page.book, list);
|
|
353
|
+
}
|
|
354
|
+
async function write(page, segments, body) {
|
|
355
|
+
const prefix = "../".repeat(segments.length) || "./";
|
|
356
|
+
const route =
|
|
357
|
+
segments.map(encodeURIComponent).join("/") + (segments.length ? "/" : "");
|
|
358
|
+
const head = pageHead(site, page, route, prefix);
|
|
359
|
+
const book = books.get(
|
|
360
|
+
segments[1] ?? (!site.shelf ? site.books[0]?.id : undefined)
|
|
361
|
+
);
|
|
362
|
+
const initial = JSON.stringify({
|
|
363
|
+
library: site,
|
|
364
|
+
book: initialBookMarkup(book, page.chapter, site.locale),
|
|
365
|
+
}).replace(/</g, "\\u003c");
|
|
366
|
+
head.metadata += `
|
|
367
|
+
<script type="application/json" id="grimoire-initial">${initial}</script>`;
|
|
368
|
+
if (book) {
|
|
369
|
+
const cover = selectCover(
|
|
370
|
+
book.id,
|
|
371
|
+
book.cover ?? (!site.shelf ? "red" : undefined)
|
|
372
|
+
);
|
|
373
|
+
const resting = assets.find(
|
|
374
|
+
(name) => name.startsWith(`resting-${cover}-`) && name.endsWith(".avif")
|
|
375
|
+
);
|
|
376
|
+
if (resting)
|
|
377
|
+
head.metadata += `
|
|
378
|
+
<link rel="preload" as="image" data-first-art fetchpriority="high" media="(min-width: 700px)" href="${prefix}assets/${resting}">`;
|
|
379
|
+
const mobilePaper = assetNamed(assets, prefix, "mobile-paper");
|
|
380
|
+
const smallPaper = assetNamed(assets, prefix, "mobile-paper-sm");
|
|
381
|
+
if (mobilePaper)
|
|
382
|
+
head.metadata += `
|
|
383
|
+
<link rel="preload" as="image" data-first-art fetchpriority="high" media="(481px <= width < 700px)" href="${mobilePaper}">`;
|
|
384
|
+
if (smallPaper)
|
|
385
|
+
head.metadata += `
|
|
386
|
+
<link rel="preload" as="image" data-first-art fetchpriority="high" media="(max-width: 480px)" href="${smallPaper}">`;
|
|
387
|
+
}
|
|
388
|
+
if (!segments.length && site.shelf) {
|
|
389
|
+
const alcove = assetNamed(assets, prefix, "alcove");
|
|
390
|
+
const cabinet =
|
|
391
|
+
site.books.length === 3 || site.books.length === 4
|
|
392
|
+
? assetNamed(assets, prefix, "mobile-cabinet")
|
|
393
|
+
: alcove;
|
|
394
|
+
if (alcove)
|
|
395
|
+
head.metadata += `
|
|
396
|
+
<link rel="preload" as="image" data-first-art fetchpriority="high" media="(min-width: 700px)" href="${alcove}">`;
|
|
397
|
+
const smallCabinet =
|
|
398
|
+
cabinet === alcove
|
|
399
|
+
? undefined
|
|
400
|
+
: assetNamed(assets, prefix, "mobile-cabinet-sm");
|
|
401
|
+
if (cabinet)
|
|
402
|
+
head.metadata += `
|
|
403
|
+
<link rel="preload" as="image" data-first-art fetchpriority="high" media="${smallCabinet ? "(481px <= width < 700px)" : "(max-width: 699px)"}" href="${cabinet}">`;
|
|
404
|
+
if (smallCabinet)
|
|
405
|
+
head.metadata += `
|
|
406
|
+
<link rel="preload" as="image" data-first-art fetchpriority="high" media="(max-width: 480px)" href="${smallCabinet}">`;
|
|
407
|
+
}
|
|
408
|
+
const directory = join(destination, ...segments);
|
|
409
|
+
await mkdir(directory, { recursive: true });
|
|
410
|
+
await writeFile(
|
|
411
|
+
join(directory, "index.html"),
|
|
412
|
+
replaceShell(
|
|
413
|
+
template,
|
|
414
|
+
site,
|
|
415
|
+
head,
|
|
416
|
+
prefix,
|
|
417
|
+
body(prefix),
|
|
418
|
+
book ? reader : undefined
|
|
419
|
+
)
|
|
420
|
+
);
|
|
421
|
+
if (head.canonical) urls.push(head.canonical);
|
|
422
|
+
}
|
|
423
|
+
await write(site, [], (prefix) =>
|
|
424
|
+
staticShelf(site, prefix, assets, libraryLabel)
|
|
425
|
+
);
|
|
426
|
+
for (const book of site.books) {
|
|
427
|
+
const pages = chapters.get(book.id) ?? [];
|
|
428
|
+
await write(
|
|
429
|
+
{ title: book.title, description: pages[0]?.description },
|
|
430
|
+
["read", book.id],
|
|
431
|
+
(prefix) =>
|
|
432
|
+
`<main class="static-reading"><nav><a href="${prefix}">${libraryLabel}</a></nav><h1>${escapeHtml(book.title)}</h1>${linkList(
|
|
433
|
+
pages.map((page) => ({
|
|
434
|
+
href: prefix + readerPath(book.id, page.chapter),
|
|
435
|
+
title: page.title,
|
|
436
|
+
}))
|
|
437
|
+
)}</main>`
|
|
438
|
+
);
|
|
439
|
+
for (const page of pages) {
|
|
440
|
+
await write(
|
|
441
|
+
page,
|
|
442
|
+
["read", book.id, ...page.chapter.split("/")],
|
|
443
|
+
(prefix) =>
|
|
444
|
+
staticChapter({
|
|
445
|
+
site,
|
|
446
|
+
book: books.get(book.id),
|
|
447
|
+
page,
|
|
448
|
+
prefix,
|
|
449
|
+
assets,
|
|
450
|
+
libraryLabel,
|
|
451
|
+
})
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (site.siteUrl) {
|
|
456
|
+
await writeFile(
|
|
457
|
+
join(destination, "sitemap.xml"),
|
|
458
|
+
`<?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`
|
|
459
|
+
);
|
|
460
|
+
if (new URL(site.siteUrl).pathname === "/") {
|
|
461
|
+
await writeFile(
|
|
462
|
+
join(destination, "robots.txt"),
|
|
463
|
+
`User-agent: *\nSitemap: ${new URL("sitemap.xml", site.siteUrl)}\n`
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
package/cli/video-url.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** @param {string} value */
|
|
2
|
+
export function videoEmbed(value) {
|
|
3
|
+
let url;
|
|
4
|
+
try {
|
|
5
|
+
url = new URL(value);
|
|
6
|
+
} catch {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
if (url.protocol !== "https:" || url.username || url.password || url.port)
|
|
10
|
+
return undefined;
|
|
11
|
+
|
|
12
|
+
const [, first, second, extra] = url.pathname.replace(/\/$/, "").split("/");
|
|
13
|
+
let id;
|
|
14
|
+
switch (url.hostname) {
|
|
15
|
+
case "youtu.be":
|
|
16
|
+
if (!second) id = first;
|
|
17
|
+
break;
|
|
18
|
+
case "youtube.com":
|
|
19
|
+
case "www.youtube.com":
|
|
20
|
+
case "m.youtube.com":
|
|
21
|
+
case "www.youtube-nocookie.com":
|
|
22
|
+
if (first === "watch" && !second) id = url.searchParams.get("v");
|
|
23
|
+
if (
|
|
24
|
+
(first === "embed" || first === "shorts" || first === "live") &&
|
|
25
|
+
!extra
|
|
26
|
+
)
|
|
27
|
+
id = second;
|
|
28
|
+
break;
|
|
29
|
+
case "vimeo.com":
|
|
30
|
+
case "www.vimeo.com":
|
|
31
|
+
case "player.vimeo.com": {
|
|
32
|
+
if (extra) return undefined;
|
|
33
|
+
const player = url.hostname === "player.vimeo.com";
|
|
34
|
+
const video =
|
|
35
|
+
player && first === "video" ? second : player ? undefined : first;
|
|
36
|
+
if (!video || !/^\d+$/.test(video)) return undefined;
|
|
37
|
+
const source = new URL(`https://player.vimeo.com/video/${video}`);
|
|
38
|
+
const access = player ? url.searchParams.get("h") : second;
|
|
39
|
+
if (access && /^[a-z\d]+$/i.test(access))
|
|
40
|
+
source.searchParams.set("h", access);
|
|
41
|
+
return { source: source.href, provider: "Vimeo" };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!id || !/^[\w-]{11}$/.test(id)) return undefined;
|
|
45
|
+
const source = new URL(`https://www.youtube-nocookie.com/embed/${id}`);
|
|
46
|
+
source.searchParams.set("playsinline", "1");
|
|
47
|
+
const start = url.searchParams.get("start") ?? url.searchParams.get("t");
|
|
48
|
+
if (start && /^\d{1,6}s?$/.test(start))
|
|
49
|
+
source.searchParams.set("start", start.replace(/s$/, ""));
|
|
50
|
+
return { source: source.href, provider: "YouTube" };
|
|
51
|
+
}
|