grimoire3d 0.3.2-dev.701f532 → 0.3.2-dev.7da6938
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 +11 -1
- package/cli/cli.js +24 -12
- package/cli/content.js +64 -15
- package/cli/markdown.js +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,14 +8,22 @@ Turn Markdown into 3D books you can open and flip through in a browser.
|
|
|
8
8
|
|
|
9
9
|
[Read the documentation](https://kkm-horikawa.github.io/grimoire3d/)
|
|
10
10
|
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
Run `npx grimoire3d serve` from your project directory and open the URL it prints. Grimoire3D looks for Markdown in the `docs/` folder directly under that directory by default. Existing Markdown works without a scaffold. See the [configuration guide](https://kkm-horikawa.github.io/grimoire3d/read/publishing/metadata/) when you want to customize the library.
|
|
14
|
+
|
|
15
|
+
If your Markdown lives in `handbook/`, add `--docs-dir handbook` to either `serve` or `build`.
|
|
16
|
+
|
|
11
17
|
## Install
|
|
12
18
|
|
|
13
|
-
Use a maintained Node.js 22, 24, or 26 release.
|
|
19
|
+
Use a maintained Node.js 22, 24, or 26 release. To pin the CLI for your project, add it as a development dependency.
|
|
14
20
|
|
|
15
21
|
```sh
|
|
16
22
|
npm install --save-dev grimoire3d
|
|
17
23
|
```
|
|
18
24
|
|
|
25
|
+
For a global installation, run `npm install -g grimoire3d`, then use `grimo serve` or `grimo build`.
|
|
26
|
+
|
|
19
27
|
## Write and preview
|
|
20
28
|
|
|
21
29
|
Create `docs/field-notes/index.md`.
|
|
@@ -28,6 +36,8 @@ This is my first 3D book.
|
|
|
28
36
|
|
|
29
37
|
Each folder directly under `docs/` becomes a book, and its Markdown files become chapters. Loose Markdown files directly in `docs/` share a separate book. Nested folders form chapter groups within the same book.
|
|
30
38
|
|
|
39
|
+
Books use the title or top-level heading in their `index.md`, then the first heading in their `README.md`. The default title is **Overview** for loose files and the folder name for each folder book.
|
|
40
|
+
|
|
31
41
|
```text
|
|
32
42
|
docs/
|
|
33
43
|
├── index.md # Book of loose Markdown files
|
package/cli/cli.js
CHANGED
|
@@ -140,8 +140,10 @@ function snapshot(library) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function serve(cwd, port, initial) {
|
|
143
|
+
function serve(cwd, port, initial, docsDir) {
|
|
144
144
|
let current = snapshot(initial);
|
|
145
|
+
let watchedDirectory = initial.docsDirectory;
|
|
146
|
+
let docsWatcher = watch(watchedDirectory, { recursive: true }, schedule);
|
|
145
147
|
let timer;
|
|
146
148
|
let changes = 0;
|
|
147
149
|
const clients = new Set();
|
|
@@ -151,8 +153,18 @@ function serve(cwd, port, initial) {
|
|
|
151
153
|
async function refresh() {
|
|
152
154
|
const revision = ++changes;
|
|
153
155
|
try {
|
|
154
|
-
const library = await readLibrary(cwd, await readSettings(cwd));
|
|
156
|
+
const library = await readLibrary(cwd, await readSettings(cwd), docsDir);
|
|
155
157
|
if (revision !== changes) return;
|
|
158
|
+
if (library.docsDirectory !== watchedDirectory) {
|
|
159
|
+
const nextWatcher = watch(
|
|
160
|
+
library.docsDirectory,
|
|
161
|
+
{ recursive: true },
|
|
162
|
+
schedule
|
|
163
|
+
);
|
|
164
|
+
docsWatcher.close();
|
|
165
|
+
docsWatcher = nextWatcher;
|
|
166
|
+
watchedDirectory = library.docsDirectory;
|
|
167
|
+
}
|
|
156
168
|
current = snapshot(library);
|
|
157
169
|
showIssues(library);
|
|
158
170
|
} catch (error) {
|
|
@@ -166,12 +178,9 @@ function serve(cwd, port, initial) {
|
|
|
166
178
|
clearTimeout(timer);
|
|
167
179
|
timer = setTimeout(() => void refresh(), 140);
|
|
168
180
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (name === "grimoire.yml") schedule();
|
|
173
|
-
}),
|
|
174
|
-
];
|
|
181
|
+
const settingsWatcher = watch(cwd, (_event, name) => {
|
|
182
|
+
if (name === "grimoire.yml") schedule();
|
|
183
|
+
});
|
|
175
184
|
|
|
176
185
|
const server = createServer(async (request, response) => {
|
|
177
186
|
try {
|
|
@@ -285,7 +294,8 @@ function serve(cwd, port, initial) {
|
|
|
285
294
|
});
|
|
286
295
|
const stopWatchers = () => {
|
|
287
296
|
clearTimeout(timer);
|
|
288
|
-
|
|
297
|
+
docsWatcher.close();
|
|
298
|
+
settingsWatcher.close();
|
|
289
299
|
};
|
|
290
300
|
server.on("error", (error) => {
|
|
291
301
|
stopWatchers();
|
|
@@ -307,12 +317,13 @@ async function main() {
|
|
|
307
317
|
options: {
|
|
308
318
|
help: { type: "boolean", short: "h" },
|
|
309
319
|
port: { type: "string" },
|
|
320
|
+
"docs-dir": { type: "string" },
|
|
310
321
|
"out-dir": { type: "string" },
|
|
311
322
|
},
|
|
312
323
|
});
|
|
313
324
|
if (!command || values.help) {
|
|
314
325
|
console.log(
|
|
315
|
-
"grimoire3d serve [--port 3000]\ngrimoire3d build [--out-dir dist]"
|
|
326
|
+
"grimoire3d serve [--docs-dir docs] [--port 3000]\ngrimoire3d build [--docs-dir docs] [--out-dir dist]"
|
|
316
327
|
);
|
|
317
328
|
return;
|
|
318
329
|
}
|
|
@@ -320,7 +331,8 @@ async function main() {
|
|
|
320
331
|
throw new Error(`Unknown command: ${command}. See --help.`);
|
|
321
332
|
const cwd = process.cwd();
|
|
322
333
|
const settings = await readSettings(cwd);
|
|
323
|
-
const
|
|
334
|
+
const docsDir = values["docs-dir"];
|
|
335
|
+
const library = await readLibrary(cwd, settings, docsDir);
|
|
324
336
|
showIssues(library);
|
|
325
337
|
if (command === "build") {
|
|
326
338
|
const output = await writeStaticSite(
|
|
@@ -341,7 +353,7 @@ async function main() {
|
|
|
341
353
|
: "--port must be an integer from 0 to 65535."
|
|
342
354
|
);
|
|
343
355
|
}
|
|
344
|
-
serve(cwd, port, library);
|
|
356
|
+
serve(cwd, port, library, docsDir);
|
|
345
357
|
}
|
|
346
358
|
|
|
347
359
|
main().catch((error) => {
|
package/cli/content.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
basename,
|
|
4
|
+
extname,
|
|
5
|
+
isAbsolute,
|
|
6
|
+
join,
|
|
7
|
+
posix,
|
|
8
|
+
relative,
|
|
9
|
+
resolve,
|
|
10
|
+
sep,
|
|
11
|
+
} from "node:path";
|
|
3
12
|
import { parse } from "yaml";
|
|
4
13
|
import { coverOptions } from "./cover-options.js";
|
|
5
14
|
import { readMarkdown } from "./markdown.js";
|
|
@@ -116,13 +125,22 @@ function readPublicationDate(index) {
|
|
|
116
125
|
);
|
|
117
126
|
}
|
|
118
127
|
|
|
119
|
-
function describeBook(pages, folder, fallback) {
|
|
128
|
+
function describeBook(pages, folder, fallback, configuredTitle) {
|
|
120
129
|
const index = pages.find(
|
|
121
130
|
(page) =>
|
|
122
131
|
page.path.toLowerCase() === posix.join(folder, "index.md").toLowerCase()
|
|
123
132
|
);
|
|
133
|
+
const readme = pages.find(
|
|
134
|
+
(page) =>
|
|
135
|
+
page.path.toLowerCase() === posix.join(folder, "README.md").toLowerCase()
|
|
136
|
+
);
|
|
124
137
|
const id = folder || rootId;
|
|
125
|
-
const title =
|
|
138
|
+
const title =
|
|
139
|
+
index?.metadata.title ||
|
|
140
|
+
index?.heading ||
|
|
141
|
+
configuredTitle ||
|
|
142
|
+
readme?.firstHeading ||
|
|
143
|
+
fallback;
|
|
126
144
|
const cover = index?.metadata.cover;
|
|
127
145
|
if (cover && !Object.hasOwn(coverOptions, cover)) {
|
|
128
146
|
throw new Error(
|
|
@@ -200,6 +218,7 @@ export async function readSettings(cwd) {
|
|
|
200
218
|
const {
|
|
201
219
|
locale = "en",
|
|
202
220
|
title,
|
|
221
|
+
docsDir,
|
|
203
222
|
outDir,
|
|
204
223
|
description,
|
|
205
224
|
siteUrl,
|
|
@@ -220,10 +239,13 @@ export async function readSettings(cwd) {
|
|
|
220
239
|
}
|
|
221
240
|
if (
|
|
222
241
|
(title !== undefined && typeof title !== "string") ||
|
|
223
|
-
|
|
242
|
+
[docsDir, outDir].some(
|
|
243
|
+
(value) =>
|
|
244
|
+
value !== undefined && (typeof value !== "string" || !value.trim())
|
|
245
|
+
)
|
|
224
246
|
) {
|
|
225
247
|
throw new Error(
|
|
226
|
-
"grimoire.yml: title and outDir must be text / title
|
|
248
|
+
"grimoire.yml: title, docsDir and outDir must be text / title、docsDir、outDir は文字列で指定してください。"
|
|
227
249
|
);
|
|
228
250
|
}
|
|
229
251
|
if (
|
|
@@ -240,6 +262,7 @@ export async function readSettings(cwd) {
|
|
|
240
262
|
return {
|
|
241
263
|
locale,
|
|
242
264
|
title,
|
|
265
|
+
docsDir,
|
|
243
266
|
outDir,
|
|
244
267
|
description,
|
|
245
268
|
socialImage,
|
|
@@ -336,26 +359,50 @@ async function loadLink(url, page, links, docs, assets, issues) {
|
|
|
336
359
|
}
|
|
337
360
|
}
|
|
338
361
|
|
|
339
|
-
|
|
362
|
+
async function projectTitle(cwd) {
|
|
363
|
+
const filename = join(cwd, "package.json");
|
|
364
|
+
try {
|
|
365
|
+
const name = JSON.parse(await readFile(filename, "utf8"))?.name;
|
|
366
|
+
if (typeof name === "string" && name.trim()) return name.trim();
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (error.code !== "ENOENT" && !(error instanceof SyntaxError)) throw error;
|
|
369
|
+
}
|
|
370
|
+
return basename(cwd);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export async function readLibrary(
|
|
374
|
+
cwd,
|
|
375
|
+
settings,
|
|
376
|
+
docsDir = settings.docsDir ?? "docs"
|
|
377
|
+
) {
|
|
340
378
|
const { locale, title } = settings;
|
|
341
|
-
|
|
342
|
-
|
|
379
|
+
if (!docsDir.trim()) throw new Error("--docs-dir must name a directory.");
|
|
380
|
+
const docs = await realpath(resolve(cwd, docsDir)).catch((error) => {
|
|
381
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code))
|
|
382
|
+
throw missingMarkdown(locale, docsDir);
|
|
343
383
|
throw error;
|
|
344
384
|
});
|
|
345
|
-
const entries = (
|
|
385
|
+
const entries = (
|
|
386
|
+
await readdir(docs, { withFileTypes: true }).catch((error) => {
|
|
387
|
+
if (error.code === "ENOTDIR") throw missingMarkdown(locale, docsDir);
|
|
388
|
+
throw error;
|
|
389
|
+
})
|
|
390
|
+
)
|
|
346
391
|
.filter((entry) => entry.isDirectory() && visibleEntry(entry.name))
|
|
347
392
|
.sort((a, b) => sortNames(a.name, b.name));
|
|
348
393
|
const books = [];
|
|
349
394
|
const rootPages = await readPages(docs, "", false);
|
|
350
395
|
if (rootPages.length)
|
|
351
|
-
books.push(
|
|
396
|
+
books.push(
|
|
397
|
+
describeBook(rootPages, "", locale === "ja" ? "概要" : "Overview", title)
|
|
398
|
+
);
|
|
352
399
|
|
|
353
400
|
for (const { name } of entries) {
|
|
354
401
|
const pages = await readPages(docs, name, true);
|
|
355
402
|
if (pages.length)
|
|
356
403
|
books.push(describeBook(pages, name, titleFromPath(name)));
|
|
357
404
|
}
|
|
358
|
-
if (!books.length) throw missingMarkdown(locale);
|
|
405
|
+
if (!books.length) throw missingMarkdown(locale, docsDir);
|
|
359
406
|
|
|
360
407
|
const shelf = books.some((book) => book.id !== rootId);
|
|
361
408
|
const assets = new Map();
|
|
@@ -467,10 +514,11 @@ export async function readLibrary(cwd, settings) {
|
|
|
467
514
|
publishedBooks.push({ id, title, cover, pages });
|
|
468
515
|
}
|
|
469
516
|
return {
|
|
517
|
+
docsDirectory: docs,
|
|
470
518
|
manifest: {
|
|
471
519
|
locale,
|
|
472
520
|
shelf,
|
|
473
|
-
title: title ??
|
|
521
|
+
title: title ?? (await projectTitle(cwd)),
|
|
474
522
|
description: settings.description,
|
|
475
523
|
siteUrl: settings.siteUrl,
|
|
476
524
|
socialImage,
|
|
@@ -486,10 +534,11 @@ export async function readLibrary(cwd, settings) {
|
|
|
486
534
|
};
|
|
487
535
|
}
|
|
488
536
|
|
|
489
|
-
function missingMarkdown(locale) {
|
|
537
|
+
function missingMarkdown(locale, docsDir) {
|
|
538
|
+
const index = join(docsDir, "index.md");
|
|
490
539
|
return new Error(
|
|
491
540
|
locale === "ja"
|
|
492
|
-
?
|
|
493
|
-
:
|
|
541
|
+
? `${docsDir} に Markdown がありません。${index} に「# 最初の本」と書いてください。`
|
|
542
|
+
: `No Markdown in ${docsDir}. Start with "# My first book" in ${index}.`
|
|
494
543
|
);
|
|
495
544
|
}
|
package/cli/markdown.js
CHANGED
|
@@ -121,6 +121,7 @@ export function readMarkdown(source) {
|
|
|
121
121
|
: "";
|
|
122
122
|
return {
|
|
123
123
|
heading: headings.get(heading)?.title,
|
|
124
|
+
firstHeading: headings.values().next().value?.title,
|
|
124
125
|
metadata: {
|
|
125
126
|
cover:
|
|
126
127
|
typeof metadata.cover === "string" ? metadata.cover.trim() : undefined,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grimoire3d",
|
|
3
|
-
"version": "0.3.2-dev.
|
|
3
|
+
"version": "0.3.2-dev.7da6938",
|
|
4
4
|
"description": "3D magical book documentation generator - Transform your docs into an interactive grimoire",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -121,6 +121,7 @@
|
|
|
121
121
|
]
|
|
122
122
|
},
|
|
123
123
|
"bin": {
|
|
124
|
-
"grimoire3d": "./cli/cli.js"
|
|
124
|
+
"grimoire3d": "./cli/cli.js",
|
|
125
|
+
"grimo": "./cli/cli.js"
|
|
125
126
|
}
|
|
126
127
|
}
|