grimoire3d 0.2.0-dev.785bb23 → 0.2.0-dev.d8e2119
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 +1 -15
- package/cli/content.js +16 -55
- package/cli/markdown.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,21 +26,7 @@ Create `docs/field-notes/index.md`.
|
|
|
26
26
|
This is my first 3D book.
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
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冊以上、またはカテゴリー・公開日を設定すると検索欄が表示されます。
|
|
29
|
+
Add Markdown files in the same folder for more chapters. Add folders directly under `docs/` for more books.
|
|
44
30
|
|
|
45
31
|
```sh
|
|
46
32
|
npx grimoire3d serve
|
package/cli/content.js
CHANGED
|
@@ -36,68 +36,29 @@ async function readPages(root, directory, nested) {
|
|
|
36
36
|
const entries = (
|
|
37
37
|
await readdir(join(root, directory), { withFileTypes: true })
|
|
38
38
|
)
|
|
39
|
-
.filter(
|
|
40
|
-
(entry) =>
|
|
41
|
-
visibleEntry(entry.name) &&
|
|
42
|
-
((entry.isDirectory() && nested) ||
|
|
43
|
-
(entry.isFile() && isMarkdown(entry.name)))
|
|
44
|
-
)
|
|
39
|
+
.filter((entry) => visibleEntry(entry.name))
|
|
45
40
|
.sort((a, b) => sortNames(a.name, b.name));
|
|
46
|
-
const
|
|
47
|
-
|
|
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;
|
|
41
|
+
const pages = [];
|
|
42
|
+
for (const entry of entries) {
|
|
88
43
|
const path = posix.join(directory, entry.name);
|
|
89
|
-
if (entry.isDirectory()) {
|
|
44
|
+
if (entry.isDirectory() && nested) {
|
|
90
45
|
pages.push(...(await readPages(root, path, true)));
|
|
91
|
-
} else {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
...readMarkdown(await readFile(join(root, path), "utf8")),
|
|
95
|
-
});
|
|
46
|
+
} else if (entry.isFile() && isMarkdown(entry.name)) {
|
|
47
|
+
const markdown = await readFile(join(root, path), "utf8");
|
|
48
|
+
pages.push({ path, ...readMarkdown(markdown) });
|
|
96
49
|
}
|
|
97
50
|
}
|
|
98
51
|
return pages;
|
|
99
52
|
}
|
|
100
53
|
|
|
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")
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
101
62
|
function readPublicationDate(index) {
|
|
102
63
|
const raw = index?.metadata.date;
|
|
103
64
|
const date = typeof raw === "string" ? raw.trim() : raw;
|
|
@@ -144,7 +105,7 @@ function describeBook(pages, folder, fallback) {
|
|
|
144
105
|
path: index.path,
|
|
145
106
|
value: index.metadata.coverImage,
|
|
146
107
|
},
|
|
147
|
-
chapters: pages.map((page) => {
|
|
108
|
+
chapters: pages.sort(comparePages).map((page) => {
|
|
148
109
|
const group = posix.dirname(page.path);
|
|
149
110
|
const inBook = folder ? page.path.slice(folder.length + 1) : page.path;
|
|
150
111
|
const file = posix.basename(pageId(page.path));
|
package/cli/markdown.js
CHANGED
|
@@ -132,7 +132,6 @@ export function readMarkdown(source) {
|
|
|
132
132
|
? metadata.category.trim() || undefined
|
|
133
133
|
: undefined,
|
|
134
134
|
date: metadata.date,
|
|
135
|
-
chapters: metadata.chapters,
|
|
136
135
|
noindex: metadata.noindex === true,
|
|
137
136
|
coverImage:
|
|
138
137
|
typeof metadata.coverImage === "string"
|
package/package.json
CHANGED