@dooc-dev/dooc 0.0.4 → 0.0.5
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/dist/cli.js +41 -3
- package/dist/compiler/asset-references.d.ts +4 -0
- package/dist/compiler/asset-references.js +117 -0
- package/dist/compiler/bundle-urls.d.ts +1 -1
- package/dist/compiler/bundle-urls.js +15 -5
- package/dist/compiler/check.js +8 -5
- package/dist/compiler/code-languages.js +7 -2
- package/dist/compiler/compile.d.ts +5 -0
- package/dist/compiler/compile.js +105 -10
- package/dist/compiler/config.js +2 -1
- package/dist/compiler/export.d.ts +4 -0
- package/dist/compiler/export.js +140 -0
- package/dist/compiler/figures.js +4 -0
- package/dist/compiler/files.js +80 -41
- package/dist/compiler/fonts.js +4 -1
- package/dist/compiler/icons.d.ts +1 -1
- package/dist/compiler/icons.js +11 -2
- package/dist/compiler/ignored-files.d.ts +3 -0
- package/dist/compiler/ignored-files.js +68 -0
- package/dist/compiler/locales.js +13 -8
- package/dist/compiler/ops.d.ts +6 -0
- package/dist/compiler/ops.js +98 -7
- package/dist/compiler/subformats.d.ts +24 -0
- package/dist/compiler/subformats.js +299 -0
- package/dist/compiler/textfile.js +3 -0
- package/dist/compiler/theme-variants.js +5 -2
- package/dist/core/content-metadata.d.ts +15 -6
- package/dist/core/content-metadata.js +278 -17
- package/dist/core/content-types.d.ts +3 -1
- package/dist/core/figure-frame.js +19 -1
- package/dist/core/files.d.ts +2 -1
- package/dist/core/files.js +6 -8
- package/dist/core/flow-base-css.generated.js +1 -1
- package/dist/core/html.js +3 -3
- package/dist/core/icons.d.ts +3 -0
- package/dist/core/icons.js +3 -0
- package/dist/core/json-tools.d.ts +1 -0
- package/dist/core/json-tools.js +12 -0
- package/dist/core/routing.d.ts +5 -2
- package/dist/core/routing.js +17 -5
- package/dist/core/subformat-record.d.ts +3 -0
- package/dist/core/subformat-record.js +131 -0
- package/dist/core/subformats.d.ts +43 -0
- package/dist/core/subformats.js +81 -0
- package/dist/core/toc-ui.js +25 -23
- package/dist/edit.global.js +322 -95
- package/dist/mcp.js +50 -9
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/transport.d.ts +22 -0
- package/dist/plugins/transport.js +1 -0
- package/dist/plugins.global.js +128 -0
- package/dist/subformats.global.js +127 -0
- package/dist/ui.global.js +91 -38
- package/dist/viewer/build-plugins.d.ts +7 -0
- package/dist/viewer/build-plugins.js +70 -0
- package/dist/viewer/build.d.ts +9 -0
- package/dist/viewer/build.js +32 -5
- package/dist/viewer/editor-tools.d.ts +7 -7
- package/dist/viewer/editor-tools.js +36 -5
- package/dist/viewer/font-picker.js +5 -1
- package/dist/viewer/git-diff.d.ts +3 -0
- package/dist/viewer/git-diff.js +47 -0
- package/dist/viewer/hmr.js +4 -1
- package/dist/viewer/i18n.js +7 -5
- package/dist/viewer/language-picker.d.ts +2 -2
- package/dist/viewer/language-picker.js +26 -9
- package/dist/viewer/lazy-graph.d.ts +2 -0
- package/dist/viewer/lazy-graph.js +30 -0
- package/dist/viewer/locales/eng.json +72 -10
- package/dist/viewer/locales/jpn.json +73 -11
- package/dist/viewer/locales/zho.json +73 -11
- package/dist/viewer/nav-focus.js +8 -1
- package/dist/viewer/nav-update.d.ts +2 -0
- package/dist/viewer/nav-update.js +117 -0
- package/dist/viewer/plugin-style.d.ts +1 -0
- package/dist/viewer/plugin-style.js +82 -0
- package/dist/viewer/resize.d.ts +0 -2
- package/dist/viewer/resize.js +2 -98
- package/dist/viewer/resource-library.d.ts +10 -8
- package/dist/viewer/resource-library.js +179 -30
- package/dist/viewer/search.d.ts +4 -2
- package/dist/viewer/search.js +252 -53
- package/dist/viewer/serve.d.ts +10 -5
- package/dist/viewer/serve.js +789 -278
- package/dist/viewer/site-icon.js +13 -6
- package/dist/viewer/site-title.js +15 -2
- package/dist/viewer/textfile.d.ts +3 -0
- package/dist/viewer/textfile.js +19 -2
- package/dist/viewer/theme-picker.d.ts +2 -0
- package/dist/viewer/theme-picker.js +24 -8
- package/dist/viewer/workspace.d.ts +2 -0
- package/dist/viewer/workspace.js +46 -1
- package/package.json +24 -9
- package/dist/compiler/bundle.d.ts +0 -2
- package/dist/compiler/bundle.js +0 -100
package/dist/cli.js
CHANGED
|
@@ -12,8 +12,12 @@ const USAGE = `usage: dooc <command>
|
|
|
12
12
|
view [dooc.yaml] [port] open dooc in view mode
|
|
13
13
|
--viewer-plugins <module> inject an external viewer plugin module
|
|
14
14
|
build html [dooc.yaml] [out-dir] build bundle.html (default <project>/dist)
|
|
15
|
+
export [dooc.yaml] [out-dir] collect source dependencies into bundle.zip
|
|
15
16
|
build zip [dooc.yaml] [out-dir] build bundle.zip (default <project>/dist)
|
|
16
17
|
--url_preview embed|network URL handling for either format (default: embed)
|
|
18
|
+
--mode static|live HTML snapshot or runtime plugin API
|
|
19
|
+
--auth external host supplies live HTML authentication and transport
|
|
20
|
+
--source-url <url> source directory URL for card copy links in HTML
|
|
17
21
|
check [dooc.yaml] [options] JSON consistency report (check --help for options)
|
|
18
22
|
plugin pack <built-dir> [zip] package bundled JS and assets as a plugin ZIP
|
|
19
23
|
plugin add <zip> [dooc.yaml] [port] install a local plugin and print login links
|
|
@@ -226,22 +230,49 @@ Node API: import { checkSite } from "@dooc-dev/dooc/check".`);
|
|
|
226
230
|
}
|
|
227
231
|
break;
|
|
228
232
|
}
|
|
233
|
+
case "export": {
|
|
234
|
+
try {
|
|
235
|
+
if (args.length > 2)
|
|
236
|
+
throw new Error("export accepts a dooc.yaml path and an output directory");
|
|
237
|
+
const root = projectRoot(args[0]);
|
|
238
|
+
const out = join(resolve(args[1] ?? join(root, "dist")), "bundle.zip");
|
|
239
|
+
const { exportBundle } = await import("./compiler/export.js");
|
|
240
|
+
writeOut(out, exportBundle(root));
|
|
241
|
+
console.log(out);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
229
248
|
case "build": {
|
|
230
249
|
try {
|
|
231
250
|
const { positionals, values } = parseArgs({
|
|
232
251
|
args,
|
|
233
252
|
allowPositionals: true,
|
|
234
253
|
options: {
|
|
235
|
-
url_preview: { type: "string"
|
|
254
|
+
url_preview: { type: "string" },
|
|
255
|
+
mode: { type: "string" },
|
|
256
|
+
auth: { type: "string" },
|
|
257
|
+
"viewer-plugins": { type: "string" },
|
|
258
|
+
"source-url": { type: "string" },
|
|
236
259
|
help: { type: "boolean", short: "h" },
|
|
237
260
|
},
|
|
238
261
|
});
|
|
239
262
|
if (values.help) {
|
|
240
263
|
console.log(`usage: dooc build html [dooc.yaml] [out-dir] [--url_preview embed|network]
|
|
264
|
+
dooc build html [dooc.yaml] [out-dir] --mode static
|
|
265
|
+
dooc build html [dooc.yaml] [out-dir] --mode live --auth external
|
|
241
266
|
dooc build zip [dooc.yaml] [out-dir] [--url_preview embed|network]
|
|
242
267
|
|
|
243
268
|
A bundle is dooc.yaml and its managed content. Builds only the selected format.
|
|
244
269
|
Default output directory: <project>/dist. Source files are never rewritten.
|
|
270
|
+
Static builds resolve enabled local plugins using build-time credentials and embed their views.
|
|
271
|
+
Live HTML exposes window.dooc.setPluginTransport(request), without a login UI or credentials.
|
|
272
|
+
Use --viewer-plugins <module> to inject trusted build plugins; installed, enabled packages are discovered automatically.
|
|
273
|
+
Use dooc export for source dependencies without plugin execution or remote downloads.
|
|
274
|
+
--source-url <url> inject an HTTP(S) directory URL for card copy links (HTML only)
|
|
275
|
+
paths are relative to dooc.yaml; overrides GitHub origin/HEAD discovery
|
|
245
276
|
--url_preview embed snapshot URL content and assets into the selected artifact (default)
|
|
246
277
|
--url_preview network preserve URL references without downloading them at build time
|
|
247
278
|
|
|
@@ -261,13 +292,20 @@ Use --url_preview network with either format to build without downloading URL co
|
|
|
261
292
|
throw new Error("build format must be html | zip");
|
|
262
293
|
if (positionals.length > 3)
|
|
263
294
|
throw new Error(`build ${format} accepts a dooc.yaml path and an output directory`);
|
|
264
|
-
const urlPreview = values.url_preview;
|
|
295
|
+
const urlPreview = values.url_preview ?? (values.mode === "live" ? "network" : "embed");
|
|
265
296
|
if (urlPreview !== "embed" && urlPreview !== "network")
|
|
266
297
|
throw new Error("--url_preview must be embed | network");
|
|
267
298
|
const root = projectRoot(rootArg);
|
|
268
299
|
const out = join(resolve(outArg ?? join(root, "dist")), `bundle.${format}`);
|
|
269
300
|
const { buildBundle } = await import("./viewer/build.js");
|
|
270
|
-
const bundle = await buildBundle(root, {
|
|
301
|
+
const bundle = await buildBundle(root, {
|
|
302
|
+
format,
|
|
303
|
+
urlPreview,
|
|
304
|
+
mode: values.mode,
|
|
305
|
+
auth: values.auth,
|
|
306
|
+
pluginModule: values["viewer-plugins"],
|
|
307
|
+
sourceUrl: values["source-url"],
|
|
308
|
+
});
|
|
271
309
|
writeOut(out, bundle.data);
|
|
272
310
|
console.log(`${out} — ${bundle.docs} docs (url_preview=${urlPreview})`);
|
|
273
311
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { parseFragment } from "parse5";
|
|
2
|
+
import postcss from "postcss";
|
|
3
|
+
import valueParser from "postcss-value-parser";
|
|
4
|
+
const cssReferences = (source, replace) => {
|
|
5
|
+
const tree = postcss.parse(source);
|
|
6
|
+
const value = (source, imports = false) => {
|
|
7
|
+
const parsed = valueParser(source);
|
|
8
|
+
parsed.walk((node) => {
|
|
9
|
+
if (node.type === "function" && node.value.toLowerCase() === "url") {
|
|
10
|
+
const before = valueParser.stringify(node.nodes).replace(/^(['"])(.*)\1$/, "$2");
|
|
11
|
+
const next = replace(before, true);
|
|
12
|
+
if (next !== before)
|
|
13
|
+
node.nodes = valueParser(JSON.stringify(next)).nodes;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (node.type === "function" && /^(?:-webkit-)?image-set$/i.test(node.value))
|
|
17
|
+
for (const child of node.nodes)
|
|
18
|
+
if (child.type === "string")
|
|
19
|
+
child.value = replace(child.value, true);
|
|
20
|
+
});
|
|
21
|
+
const first = parsed.nodes.find((node) => node.type !== "space" && node.type !== "comment");
|
|
22
|
+
if (imports && first?.type === "string")
|
|
23
|
+
first.value = replace(first.value, true);
|
|
24
|
+
return parsed.toString();
|
|
25
|
+
};
|
|
26
|
+
tree.walkDecls((node) => {
|
|
27
|
+
node.value = value(node.value);
|
|
28
|
+
});
|
|
29
|
+
tree.walkAtRules((node) => {
|
|
30
|
+
node.params = value(node.params, node.name.toLowerCase() === "import");
|
|
31
|
+
});
|
|
32
|
+
return tree.toString();
|
|
33
|
+
};
|
|
34
|
+
/** Visit real asset URLs and preserve surrounding markup, examples and scripts. */
|
|
35
|
+
export const assetReferences = (source, extension, replace) => {
|
|
36
|
+
if (extension === "css")
|
|
37
|
+
return cssReferences(source, replace);
|
|
38
|
+
const changes = [];
|
|
39
|
+
const walk = (parent) => {
|
|
40
|
+
for (const node of parent.childNodes) {
|
|
41
|
+
if (!("tagName" in node))
|
|
42
|
+
continue;
|
|
43
|
+
for (const attr of node.attrs) {
|
|
44
|
+
let next = attr.value;
|
|
45
|
+
if (["src", "poster", "background"].includes(attr.name) ||
|
|
46
|
+
(attr.name === "data" && node.tagName === "object") ||
|
|
47
|
+
["href", "xlink:href"].includes(attr.name))
|
|
48
|
+
next = replace(attr.value, !["a", "area", "base"].includes(node.tagName));
|
|
49
|
+
else if (attr.name === "srcdoc")
|
|
50
|
+
next = assetReferences(attr.value, "html", replace);
|
|
51
|
+
else if (attr.name === "style")
|
|
52
|
+
next = cssReferences(attr.value, replace);
|
|
53
|
+
else if (["srcset", "imagesrcset"].includes(attr.name)) {
|
|
54
|
+
let rest = attr.value;
|
|
55
|
+
next = "";
|
|
56
|
+
while (rest) {
|
|
57
|
+
const space = /^[\s,]*/.exec(rest)?.[0] ?? "";
|
|
58
|
+
next += space;
|
|
59
|
+
rest = rest.slice(space.length);
|
|
60
|
+
const token = /^\S+/.exec(rest)?.[0];
|
|
61
|
+
if (!token)
|
|
62
|
+
break;
|
|
63
|
+
const url = token.replace(/,+$/, "");
|
|
64
|
+
next += replace(url, true) + token.slice(url.length);
|
|
65
|
+
rest = rest.slice(token.length);
|
|
66
|
+
if (!token.endsWith(",")) {
|
|
67
|
+
const descriptor = /^[^,]*,?/.exec(rest)?.[0] ?? "";
|
|
68
|
+
next += descriptor;
|
|
69
|
+
rest = rest.slice(descriptor.length);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (next === attr.value)
|
|
74
|
+
continue;
|
|
75
|
+
const name = attr.prefix ? `${attr.prefix}:${attr.name}` : attr.name;
|
|
76
|
+
const location = node.sourceCodeLocation?.attrs?.[name];
|
|
77
|
+
if (!location)
|
|
78
|
+
throw new Error(`Cannot update attribute: ${name}`);
|
|
79
|
+
const raw = source.slice(location.startOffset, location.endOffset);
|
|
80
|
+
const head = /^[^=]+\s*=\s*/.exec(raw)?.[0];
|
|
81
|
+
if (!head)
|
|
82
|
+
throw new Error(`Cannot update attribute: ${name}`);
|
|
83
|
+
const quote = raw[head.length] === "'" ? "'" : '"';
|
|
84
|
+
const escaped = next
|
|
85
|
+
.replaceAll("&", "&")
|
|
86
|
+
.replaceAll("<", "<")
|
|
87
|
+
.replaceAll(quote, quote === '"' ? """ : "'");
|
|
88
|
+
changes.push({
|
|
89
|
+
from: location.startOffset,
|
|
90
|
+
to: location.endOffset,
|
|
91
|
+
text: head + quote + escaped + quote,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (node.tagName === "style")
|
|
95
|
+
for (const child of node.childNodes) {
|
|
96
|
+
if (!("value" in child))
|
|
97
|
+
continue;
|
|
98
|
+
const next = cssReferences(child.value, replace);
|
|
99
|
+
if (next === child.value)
|
|
100
|
+
continue;
|
|
101
|
+
const location = child.sourceCodeLocation;
|
|
102
|
+
if (!location)
|
|
103
|
+
throw new Error("Cannot update style content");
|
|
104
|
+
changes.push({
|
|
105
|
+
from: location.startOffset,
|
|
106
|
+
to: location.endOffset,
|
|
107
|
+
text: next,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
walk("content" in node ? node.content : node);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
walk(parseFragment(source, { sourceCodeLocationInfo: true }));
|
|
114
|
+
for (const change of changes.sort((a, b) => b.from - a.from))
|
|
115
|
+
source = source.slice(0, change.from) + change.text + source.slice(change.to);
|
|
116
|
+
return source;
|
|
117
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZipEntry } from "./zip.js";
|
|
2
2
|
/** Snapshot embedded URLs and their declarative assets without changing the source bundle. */
|
|
3
|
-
export declare const embedBundleUrls: (root: string, entries: readonly ZipEntry[]) => Promise<ZipEntry[]>;
|
|
3
|
+
export declare const embedBundleUrls: (root: string, entries: readonly ZipEntry[], resolvePlugin?: (url: string) => Promise<string | undefined>) => Promise<ZipEntry[]>;
|
|
@@ -7,6 +7,7 @@ import valueParser from "postcss-value-parser";
|
|
|
7
7
|
import { embeddedImages, parseMdast } from "../core/markdown.js";
|
|
8
8
|
import { isRemoteTextfile } from "../core/textfile.js";
|
|
9
9
|
import { collectRefs } from "./dialect.js";
|
|
10
|
+
import { assertNotIgnored } from "./ignored-files.js";
|
|
10
11
|
import { readManifest } from "./manifest.js";
|
|
11
12
|
import { fetchPublicFile } from "./public-file.js";
|
|
12
13
|
import { textfilePath } from "./textfile.js";
|
|
@@ -32,14 +33,15 @@ const types = {
|
|
|
32
33
|
const extension = (source) => posix.extname(new URL(source).pathname).slice(1).toLowerCase();
|
|
33
34
|
const decode = (data) => new TextDecoder("utf-8", { fatal: true }).decode(data);
|
|
34
35
|
/** Snapshot embedded URLs and their declarative assets without changing the source bundle. */
|
|
35
|
-
export const embedBundleUrls = async (root, entries) => {
|
|
36
|
+
export const embedBundleUrls = async (root, entries, resolvePlugin) => {
|
|
36
37
|
const result = new Map(entries.map((entry) => [entry.name, { ...entry }]));
|
|
37
38
|
const figures = new Set(entries
|
|
38
39
|
.filter((entry) => /\.(md|callouth)$/.test(entry.name))
|
|
39
40
|
.flatMap((entry) => collectRefs(parseMdast(decode(entry.data))).figures));
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const manifest = readManifest(root);
|
|
42
|
+
for (const file of [manifest.icon, ...Object.values(manifest.themeIcons ?? {})])
|
|
43
|
+
if (file)
|
|
44
|
+
figures.add(file);
|
|
43
45
|
const cache = new Map();
|
|
44
46
|
const sources = new Map();
|
|
45
47
|
const pending = new Set();
|
|
@@ -68,6 +70,8 @@ export const embedBundleUrls = async (root, entries) => {
|
|
|
68
70
|
try {
|
|
69
71
|
let source = sources.get(key);
|
|
70
72
|
if (!source) {
|
|
73
|
+
if (url.protocol === "bundle:")
|
|
74
|
+
assertNotIgnored(root, decodeURIComponent(url.pathname.slice(1)));
|
|
71
75
|
if (url.protocol === "https:" && ++downloads > 256)
|
|
72
76
|
throw new Error("Bundle exceeds 256 remote assets");
|
|
73
77
|
let type = "";
|
|
@@ -263,7 +267,13 @@ export const embedBundleUrls = async (root, entries) => {
|
|
|
263
267
|
if (remote.ref)
|
|
264
268
|
throw new Error("Git URL embeds require a public HTTPS file URL");
|
|
265
269
|
const url = keyOf(remote.url, image.url);
|
|
266
|
-
const
|
|
270
|
+
const plugin = await resolvePlugin?.(url.href);
|
|
271
|
+
const asset = plugin === undefined
|
|
272
|
+
? await resource(url, false)
|
|
273
|
+
: {
|
|
274
|
+
data: Buffer.from(await markup(plugin, url.href)),
|
|
275
|
+
type: "text/html",
|
|
276
|
+
};
|
|
267
277
|
const ext = Object.entries(types).find(([, type]) => type === asset.type)?.[0] ??
|
|
268
278
|
(extension(url.href) || "txt");
|
|
269
279
|
const name = `files/bundle/${createHash("sha256").update(url.href).digest("hex")}.${ext}`;
|
package/dist/compiler/check.js
CHANGED
|
@@ -199,7 +199,9 @@ export const checkSite = (root, options = {}) => {
|
|
|
199
199
|
else if (!report.themes.includes(theme))
|
|
200
200
|
add("THEME_UNDECLARED", "warning", `themes/${theme}`, "Theme variant is not enabled by the site declaration and will not be displayed.", { theme });
|
|
201
201
|
}
|
|
202
|
-
const docs = new Map(flattenTree(manifest.tree)
|
|
202
|
+
const docs = new Map(flattenTree(manifest.tree)
|
|
203
|
+
.filter((node) => !node.subformat)
|
|
204
|
+
.map(({ id }) => [docFile(id, manifest.files), id]));
|
|
203
205
|
const visited = new Set();
|
|
204
206
|
const checkedThemes = new Set();
|
|
205
207
|
const checkAsset = (file, context, withThemes = true) => {
|
|
@@ -410,10 +412,11 @@ export const checkSite = (root, options = {}) => {
|
|
|
410
412
|
add("FILE_UNREADABLE", "error", file, messageOf(error));
|
|
411
413
|
}
|
|
412
414
|
}
|
|
413
|
-
for (const file of
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
415
|
+
for (const file of [
|
|
416
|
+
manifest.icon,
|
|
417
|
+
...Object.values(manifest.themeIcons ?? {}),
|
|
418
|
+
...Object.values(manifest.files?.icons ?? {}),
|
|
419
|
+
])
|
|
417
420
|
if (file)
|
|
418
421
|
checkAsset(file, { language: sourceLanguage }, false);
|
|
419
422
|
if (has("render")) {
|
|
@@ -3,6 +3,7 @@ import { join, relative, resolve } from "node:path";
|
|
|
3
3
|
import { languageAliasNames, languageNames } from "@shikijs/langs";
|
|
4
4
|
import { bundledLanguages } from "shiki/langs";
|
|
5
5
|
import { CODE_LANGS, CODE_TEMPLATES } from "../core/taxonomy.js";
|
|
6
|
+
import { ignoredFiles } from "./ignored-files.js";
|
|
6
7
|
export const CODE_LANGUAGES_DIR = ".dooc/code-languages";
|
|
7
8
|
const supported = new Set([
|
|
8
9
|
...languageNames,
|
|
@@ -79,9 +80,13 @@ export const loadCodeGrammars = async (names) => {
|
|
|
79
80
|
/** Renderer-owned registrations; Markdown content is never changed. */
|
|
80
81
|
export const loadCodeLanguages = async (root) => {
|
|
81
82
|
const directory = join(root, CODE_LANGUAGES_DIR);
|
|
83
|
+
const files = existsSync(directory)
|
|
84
|
+
? readdirSync(directory).filter((file) => file.endsWith(".json"))
|
|
85
|
+
: [];
|
|
86
|
+
const ignored = ignoredFiles(root, files.map((file) => `${CODE_LANGUAGES_DIR}/${file}`));
|
|
82
87
|
const extra = existsSync(directory)
|
|
83
|
-
?
|
|
84
|
-
.filter((file) =>
|
|
88
|
+
? files
|
|
89
|
+
.filter((file) => !ignored.has(`${CODE_LANGUAGES_DIR}/${file}`))
|
|
85
90
|
.sort()
|
|
86
91
|
.flatMap((file) => readGrammars(join(directory, file)))
|
|
87
92
|
: [];
|
|
@@ -9,6 +9,8 @@ export declare const collectDocLinks: (body: string) => string[];
|
|
|
9
9
|
/** Source text and diagnostics for editing. key = CompiledDoc.file. */
|
|
10
10
|
export interface DocSource {
|
|
11
11
|
terms: TermEntry[];
|
|
12
|
+
/** Files already discovered during parsing, used by the viewer's change watcher. */
|
|
13
|
+
referencedFiles: string[];
|
|
12
14
|
/**
|
|
13
15
|
* Raw text on disk (including front-matter). The editor's initial value and the base for
|
|
14
16
|
* detecting external changes.
|
|
@@ -28,9 +30,12 @@ export interface DocSource {
|
|
|
28
30
|
errors: string[];
|
|
29
31
|
}
|
|
30
32
|
export interface Compiled {
|
|
33
|
+
subformats?: import("../core/subformats.js").Subformat[];
|
|
31
34
|
previews: PreviewSettings;
|
|
32
35
|
title?: string;
|
|
33
36
|
icon?: string;
|
|
37
|
+
/** Theme name → site icon from themes/<theme>/<icon file>. */
|
|
38
|
+
iconVariants?: Record<string, string>;
|
|
34
39
|
/** Display order follows dooc.yaml. Invalid sources retain their diagnostics for editing. */
|
|
35
40
|
docs: CompiledDoc[];
|
|
36
41
|
terms: TermEntry[];
|
package/dist/compiler/compile.js
CHANGED
|
@@ -18,9 +18,11 @@ import { createFileCache, createSigCache, dirSig, fileSig } from "./file-cache.j
|
|
|
18
18
|
import { projectFiles } from "./files.js";
|
|
19
19
|
import { toBlocks } from "./from-mdast.js";
|
|
20
20
|
import { loadIcons, squareSvg } from "./icons.js";
|
|
21
|
+
import { assertNotIgnored, ignoredFiles } from "./ignored-files.js";
|
|
21
22
|
import { contentLanguageCode, isContentLanguage } from "./language-codes.js";
|
|
22
23
|
import { siteContentLanguages, translationFile } from "./locales.js";
|
|
23
24
|
import { parseManifestText } from "./manifest.js";
|
|
25
|
+
import { loadSubformat, parseSubformatRecord, validateSubformatRecord } from "./subformats.js";
|
|
24
26
|
import { parseTermSource } from "./terms.js";
|
|
25
27
|
import { readTextfile, selectTextfileRange } from "./textfile.js";
|
|
26
28
|
import { TextfileUnavailable } from "./textfile-remote.js";
|
|
@@ -50,6 +52,7 @@ const parseFile = (raw, previews, file) => {
|
|
|
50
52
|
const figureFiles = refs.figures;
|
|
51
53
|
return {
|
|
52
54
|
raw,
|
|
55
|
+
referencedFiles: [...refs.textfiles, ...refs.figures, ...refs.terms],
|
|
53
56
|
parsed,
|
|
54
57
|
blocks,
|
|
55
58
|
toc,
|
|
@@ -239,7 +242,8 @@ export const createCompiler = (root, options = {}) => {
|
|
|
239
242
|
!siteContentLanguages(root, manifest).includes(options.locale))
|
|
240
243
|
throw new Error(`Language ${options.locale} is not declared in dooc.yaml languages`);
|
|
241
244
|
const themes = siteThemes(root, manifest);
|
|
242
|
-
const
|
|
245
|
+
const paths = projectFiles(root);
|
|
246
|
+
const visualFiles = paths
|
|
243
247
|
.map((file) => file.path)
|
|
244
248
|
.filter((file) => /\.(svg|html|png|webp|gif|mp4|webm|jpe?g)$/.test(file));
|
|
245
249
|
const { figures, errors: figErrors } = figuresCache.get(dirSig(figuresDir) +
|
|
@@ -251,9 +255,12 @@ export const createCompiler = (root, options = {}) => {
|
|
|
251
255
|
const previews = parsePreviewSettings(options.previews ?? defaultPreviewSettings());
|
|
252
256
|
let title;
|
|
253
257
|
let icon;
|
|
258
|
+
let iconVariants;
|
|
254
259
|
let iconFile;
|
|
255
260
|
const files = [];
|
|
256
|
-
if (!existsSync(contentDir) &&
|
|
261
|
+
if (!existsSync(contentDir) &&
|
|
262
|
+
!manifest.files &&
|
|
263
|
+
!flattenTree(manifest.tree).some((node) => node.subformat)) {
|
|
257
264
|
siteErrors.push(`${contentDir}: content/ is missing`);
|
|
258
265
|
}
|
|
259
266
|
else {
|
|
@@ -263,13 +270,23 @@ export const createCompiler = (root, options = {}) => {
|
|
|
263
270
|
docCache = createFileCache();
|
|
264
271
|
previewKey = nextPreviewKey;
|
|
265
272
|
}
|
|
266
|
-
title =
|
|
273
|
+
title =
|
|
274
|
+
manifest.titles?.[options.locale ?? contentLanguageCode(defaultLang)] ??
|
|
275
|
+
manifestTitle;
|
|
267
276
|
iconFile = manifestIcon;
|
|
268
277
|
if (iconFile) {
|
|
269
278
|
try {
|
|
270
279
|
icon = squareSvg(readTextfile(root, iconFile));
|
|
271
280
|
if (!icon)
|
|
272
281
|
throw new Error("expected an SVG with a viewBox or width and height");
|
|
282
|
+
const variants = Object.entries(manifest.themeIcons ?? themeVariants(root, iconFile, themes));
|
|
283
|
+
if (variants.length)
|
|
284
|
+
iconVariants = Object.fromEntries(variants.map(([theme, file]) => {
|
|
285
|
+
const svg = squareSvg(readTextfile(root, file));
|
|
286
|
+
if (!svg)
|
|
287
|
+
throw new Error(`${file}: expected an SVG with a viewBox or width and height`);
|
|
288
|
+
return [theme, svg];
|
|
289
|
+
}));
|
|
273
290
|
}
|
|
274
291
|
catch (error) {
|
|
275
292
|
siteErrors.push(`${MANIFEST_FILE}: icon ${iconFile}: ${error instanceof Error ? error.message : error}`);
|
|
@@ -278,9 +295,13 @@ export const createCompiler = (root, options = {}) => {
|
|
|
278
295
|
siteErrors.push(...manifestErrors);
|
|
279
296
|
// Directly under content/: flat <id>.md files only (no folders).
|
|
280
297
|
const onDisk = new Set();
|
|
281
|
-
|
|
298
|
+
const contentEntries = existsSync(contentDir)
|
|
282
299
|
? readdirSync(contentDir, { withFileTypes: true })
|
|
283
|
-
: []
|
|
300
|
+
: [];
|
|
301
|
+
const ignoredContent = ignoredFiles(root, contentEntries.map((entry) => `content/${entry.name}`));
|
|
302
|
+
for (const entry of contentEntries) {
|
|
303
|
+
if (ignoredContent.has(`content/${entry.name}`))
|
|
304
|
+
continue;
|
|
284
305
|
if (entry.name.startsWith(".")) {
|
|
285
306
|
continue;
|
|
286
307
|
}
|
|
@@ -294,7 +315,9 @@ export const createCompiler = (root, options = {}) => {
|
|
|
294
315
|
onDisk.add(id);
|
|
295
316
|
}
|
|
296
317
|
// Manifest pre-order is the display order.
|
|
297
|
-
for (const { id, parent } of flattenTree(tree)) {
|
|
318
|
+
for (const { id, parent, subformat } of flattenTree(tree)) {
|
|
319
|
+
if (subformat)
|
|
320
|
+
continue;
|
|
298
321
|
const rel = docFile(id, manifest.files);
|
|
299
322
|
if (rel.startsWith("content/")) {
|
|
300
323
|
const diskId = docIdOfFile(rel.slice("content/".length));
|
|
@@ -304,6 +327,7 @@ export const createCompiler = (root, options = {}) => {
|
|
|
304
327
|
let path;
|
|
305
328
|
try {
|
|
306
329
|
path = textfilePath(root, rel);
|
|
330
|
+
assertNotIgnored(root, rel);
|
|
307
331
|
}
|
|
308
332
|
catch (error) {
|
|
309
333
|
siteErrors.push(`${rel}: ${error}`);
|
|
@@ -320,6 +344,7 @@ export const createCompiler = (root, options = {}) => {
|
|
|
320
344
|
try {
|
|
321
345
|
const translated = textfilePath(root, file);
|
|
322
346
|
if (existsSync(translated)) {
|
|
347
|
+
assertNotIgnored(root, file);
|
|
323
348
|
parsed = docCache.get(translated, (raw) => parseFile(raw, previews, rel));
|
|
324
349
|
language = options.locale;
|
|
325
350
|
}
|
|
@@ -339,7 +364,12 @@ export const createCompiler = (root, options = {}) => {
|
|
|
339
364
|
if (!file.startsWith("figures/"))
|
|
340
365
|
siteErrors.push(...figErrors.filter((error) => error.startsWith(`${file}:`)));
|
|
341
366
|
// Icons are small, so read them every time (no cache).
|
|
342
|
-
const { icons, errors: iconErrors } = loadIcons(root, new Set(
|
|
367
|
+
const { icons, errors: iconErrors } = loadIcons(root, new Set([
|
|
368
|
+
...files.map((f) => f.doc.id),
|
|
369
|
+
...flattenTree(manifest.tree)
|
|
370
|
+
.filter((node) => node.subformat)
|
|
371
|
+
.map((node) => node.id),
|
|
372
|
+
]), iconFile, manifest.files, Object.values(manifest.themeIcons ?? {}));
|
|
343
373
|
siteErrors.push(...iconErrors);
|
|
344
374
|
for (const { doc } of files) {
|
|
345
375
|
const icon = icons.get(doc.id);
|
|
@@ -348,9 +378,6 @@ export const createCompiler = (root, options = {}) => {
|
|
|
348
378
|
}
|
|
349
379
|
}
|
|
350
380
|
const docs = files.map((f) => f.doc);
|
|
351
|
-
if (docs.length === 0) {
|
|
352
|
-
siteErrors.push(`${contentDir}: no docs`);
|
|
353
|
-
}
|
|
354
381
|
const ctx = {
|
|
355
382
|
docs,
|
|
356
383
|
figures: new Map(figures.map((f) => [f.name, f])),
|
|
@@ -363,18 +390,85 @@ export const createCompiler = (root, options = {}) => {
|
|
|
363
390
|
errors.push(...errs.map((e) => `${doc.file}: ${e}`));
|
|
364
391
|
sources.set(doc.file, {
|
|
365
392
|
terms: parsed.parsed.terms,
|
|
393
|
+
referencedFiles: parsed.referencedFiles,
|
|
366
394
|
raw: parsed.raw,
|
|
367
395
|
frontmatter: parsed.parsed.frontmatter,
|
|
368
396
|
lines: parsed.lines,
|
|
369
397
|
errors: errs,
|
|
370
398
|
});
|
|
371
399
|
}
|
|
400
|
+
for (const node of flattenTree(manifest.tree).filter((node) => node.subformat)) {
|
|
401
|
+
const config = manifest.subformats?.find((format) => format.ext === node.subformat);
|
|
402
|
+
if (!config)
|
|
403
|
+
continue;
|
|
404
|
+
const file = `subformat:${config.ext}`;
|
|
405
|
+
const title = node.title ?? config.ext;
|
|
406
|
+
const pageErrors = [];
|
|
407
|
+
const collection = {
|
|
408
|
+
...config,
|
|
409
|
+
fields: [],
|
|
410
|
+
records: [],
|
|
411
|
+
};
|
|
412
|
+
try {
|
|
413
|
+
assertNotIgnored(root, config.schema);
|
|
414
|
+
if (!paths.some((file) => file.path === config.schema))
|
|
415
|
+
throw new Error("Subformat schema is not available in the workspace");
|
|
416
|
+
const loaded = loadSubformat(root, config);
|
|
417
|
+
collection.fields = loaded.fields;
|
|
418
|
+
collection.template = loaded.template;
|
|
419
|
+
collection.defaultFolder = manifest.defaultSubformatFolder;
|
|
420
|
+
for (const record of paths.filter((file) => file.extension === config.ext && file.path !== config.schema)) {
|
|
421
|
+
try {
|
|
422
|
+
const content = readTextfile(root, record.path);
|
|
423
|
+
const data = parseSubformatRecord(content, config.format);
|
|
424
|
+
validateSubformatRecord(loaded, data);
|
|
425
|
+
collection.records.push({ file: record.path, content, data });
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
pageErrors.push(`${record.path}: ${error instanceof Error ? error.message : error}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
pageErrors.push(`${config.schema}: ${error instanceof Error ? error.message : error}`);
|
|
434
|
+
}
|
|
435
|
+
docs.push({
|
|
436
|
+
id: node.id,
|
|
437
|
+
parent: node.parent,
|
|
438
|
+
title,
|
|
439
|
+
file,
|
|
440
|
+
lang: defaultLang,
|
|
441
|
+
subformat: collection,
|
|
442
|
+
icon: icons.get(node.id),
|
|
443
|
+
body: "",
|
|
444
|
+
blocks: [],
|
|
445
|
+
toc: [],
|
|
446
|
+
refs: { figures: [], terms: [] },
|
|
447
|
+
});
|
|
448
|
+
sources.set(file, {
|
|
449
|
+
terms: [],
|
|
450
|
+
referencedFiles: [],
|
|
451
|
+
raw: "",
|
|
452
|
+
frontmatter: { title },
|
|
453
|
+
lines: [],
|
|
454
|
+
errors: pageErrors,
|
|
455
|
+
});
|
|
456
|
+
errors.push(...pageErrors);
|
|
457
|
+
}
|
|
458
|
+
const order = flattenTree(manifest.tree).map((node) => node.id);
|
|
459
|
+
docs.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
|
|
460
|
+
if (!docs.length) {
|
|
461
|
+
siteErrors.push(`${contentDir}: no docs`);
|
|
462
|
+
errors.push(`${contentDir}: no docs`);
|
|
463
|
+
}
|
|
372
464
|
return {
|
|
373
465
|
previews,
|
|
466
|
+
subformats: manifest.subformats,
|
|
374
467
|
...(manifest.languages ? { contentLanguages: manifest.languages } : {}),
|
|
375
468
|
...(manifest.themes ? { themes: manifest.themes } : {}),
|
|
376
469
|
...(title === undefined ? {} : { title }),
|
|
377
470
|
...(icon === undefined ? {} : { icon }),
|
|
471
|
+
...(iconVariants === undefined ? {} : { iconVariants }),
|
|
378
472
|
docs,
|
|
379
473
|
terms: [...termMap(files.flatMap(({ parsed }) => parsed.parsed.terms)).values()],
|
|
380
474
|
figures,
|
|
@@ -399,6 +493,7 @@ export const compileDraft = (ctx, file, raw) => {
|
|
|
399
493
|
doc: toDoc(known?.id ?? "", known?.parent, file, parsed, ctx.defaultLang ?? DEFAULT_LANG),
|
|
400
494
|
source: {
|
|
401
495
|
terms: parsed.parsed.terms,
|
|
496
|
+
referencedFiles: parsed.referencedFiles,
|
|
402
497
|
raw,
|
|
403
498
|
frontmatter: parsed.parsed.frontmatter,
|
|
404
499
|
lines: parsed.lines,
|
package/dist/compiler/config.js
CHANGED
|
@@ -6,6 +6,7 @@ import { existsSync } from "node:fs";
|
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
8
|
import { isLangTag } from "../core/language.js";
|
|
9
|
+
import { ignoredFiles } from "./ignored-files.js";
|
|
9
10
|
export const CONFIG_FILE = "docs.config.mjs";
|
|
10
11
|
const FUNCTION_KEYS = ["isTermBoundary", "compareTerms", "lint"];
|
|
11
12
|
const checkAdapter = (value, i) => {
|
|
@@ -30,7 +31,7 @@ const checkAdapter = (value, i) => {
|
|
|
30
31
|
/** Reads docs.config.mjs; defaults when absent. Throws with a readable message when invalid. */
|
|
31
32
|
export const loadDocsConfig = async (root) => {
|
|
32
33
|
const file = join(root, CONFIG_FILE);
|
|
33
|
-
if (!existsSync(file)) {
|
|
34
|
+
if (!existsSync(file) || ignoredFiles(root, [CONFIG_FILE]).has(CONFIG_FILE)) {
|
|
34
35
|
return {
|
|
35
36
|
languages: [],
|
|
36
37
|
};
|