@dogsbay/ssg-cli 0.2.0-beta.178 → 0.2.0-beta.181

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.
@@ -1,11 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
3
3
  import {
4
- lib_default
5
- } from "./chunk-Z7WUDBZV.mjs";
6
- import {
4
+ lib_default,
7
5
  require_dist
8
- } from "./chunk-IZF74GZZ.mjs";
6
+ } from "./chunk-O3R3MASP.mjs";
9
7
  import {
10
8
  __toESM
11
9
  } from "./chunk-STRHO6SY.mjs";
@@ -7,23 +7,22 @@ import {
7
7
  } from "./chunk-OBUK53NJ.mjs";
8
8
  import {
9
9
  ConfigError,
10
+ MENU_FILE,
10
11
  PageClashError,
11
- TOPIC_MAP,
12
12
  assetVerdict,
13
13
  build,
14
14
  copiedPath,
15
15
  dataDirOf,
16
16
  defaultTables,
17
- filePagesIndex,
18
17
  insideProject,
19
18
  languageTables,
20
- memberPath,
19
+ memberPaths,
21
20
  parseConfig,
22
21
  projectFile,
23
22
  projectRoots,
23
+ readMenus,
24
24
  readProject,
25
25
  readText,
26
- readTopicMaps,
27
26
  rebuildUnitLazy,
28
27
  servedRoot,
29
28
  siteCssBuilder,
@@ -33,14 +32,16 @@ import {
33
32
  translationTables,
34
33
  versionsOf,
35
34
  writeTranslationStubs
36
- } from "./chunk-3O2UA2GP.mjs";
35
+ } from "./chunk-3ZUDN6IL.mjs";
37
36
  import {
38
37
  contentType
39
38
  } from "./chunk-CMGKSS45.mjs";
40
39
  import "./chunk-KFYMG4VB.mjs";
41
- import "./chunk-5APY2GH6.mjs";
40
+ import {
41
+ filePagesIndex
42
+ } from "./chunk-IERF2DNL.mjs";
42
43
  import "./chunk-YVSP26OS.mjs";
43
- import "./chunk-Z7WUDBZV.mjs";
44
+ import "./chunk-O3R3MASP.mjs";
44
45
  import {
45
46
  collectClasses,
46
47
  isRef,
@@ -224,6 +225,7 @@ async function openDevSession(input, o = {}) {
224
225
  return lazy ?? c;
225
226
  };
226
227
  const pageFor = (source) => unitOf(source)?.handle.pageForSource(source);
228
+ const pagesFor = (source) => unitOf(source)?.handle.pagesForSource(source) ?? [];
227
229
  const fresh = async (path) => {
228
230
  try {
229
231
  await get(path);
@@ -241,6 +243,7 @@ async function openDevSession(input, o = {}) {
241
243
  return buildProblem;
242
244
  },
243
245
  pageFor,
246
+ pagesFor,
244
247
  async record(path) {
245
248
  if (!o.dataLines) return void 0;
246
249
  const u = [...units.values()].find((x) => x.handle.pageOuts.includes(path));
@@ -254,8 +257,7 @@ async function openDevSession(input, o = {}) {
254
257
  const pages = new Set(filePagesIndex([...units.values()].flatMap((u) => u.handle.records()))[file] ?? []);
255
258
  if (options?.render === false) {
256
259
  for (const u of units.values()) for (const r of u.handle.bodyReaders(file)) pages.add(r);
257
- const own = pageFor(file);
258
- if (own) pages.add(own);
260
+ for (const own of pagesFor(file)) pages.add(own);
259
261
  }
260
262
  return [...pages].sort();
261
263
  },
@@ -324,6 +326,7 @@ async function openDevSession(input, o = {}) {
324
326
  const again = /* @__PURE__ */ new Map();
325
327
  const markStale = (page, u = unitForSitePath(page), rebuilt = false) => {
326
328
  stale.add(page);
329
+ for (const b of u?.handle.booksOf(page) ?? []) stale.add(b);
327
330
  const src = u?.handle.sourceForPage(page);
328
331
  if (src === void 0) return;
329
332
  marked.add(src);
@@ -364,7 +367,6 @@ async function openDevSession(input, o = {}) {
364
367
  mark("unit");
365
368
  continue;
366
369
  }
367
- if (TOPIC_MAP.test(p)) continue;
368
370
  if (config.staticDir && p.startsWith(config.staticDir + "/")) {
369
371
  const rel = p.slice(config.staticDir.length + 1);
370
372
  if (rel === "_headers" || rel === "_redirects" || !staticPathServed(rel)) continue;
@@ -407,6 +409,7 @@ async function openDevSession(input, o = {}) {
407
409
  }
408
410
  continue;
409
411
  }
412
+ if (MENU_FILE.test(p) && !NAV_FILES.test(p)) continue;
410
413
  const u = unitOf(p);
411
414
  if (!u) continue;
412
415
  const content = input.files.get(p);
@@ -415,12 +418,13 @@ async function openDevSession(input, o = {}) {
415
418
  const text = content === void 0 ? void 0 : await textOf(content);
416
419
  const same = page !== void 0 && text !== void 0 && u.handle.sameFrontMatter(p, text);
417
420
  const readers2 = (same || !page && u.handle.neverPage(p)) && u.handle.included(p) ? u.handle.includeReaders(p) : void 0;
421
+ const all = u.handle.pagesForSource(p);
418
422
  if (same && !u.handle.included(p)) {
419
- markStale(page, u);
423
+ for (const x of all) markStale(x, u);
420
424
  mark("page");
421
425
  } else if (readers2) {
422
426
  u.handle.forget(p);
423
- if (page) markStale(page, u);
427
+ for (const x of all) markStale(x, u);
424
428
  for (const r of readers2) markStale(r, u);
425
429
  mark("page");
426
430
  } else {
@@ -437,12 +441,14 @@ async function openDevSession(input, o = {}) {
437
441
  mark("unit");
438
442
  } else {
439
443
  mark("asset");
440
- const at = memberPath(u.unit, p)?.path ?? p.slice(sourceRoot(u.unit.source).length);
441
- const key = u.unit.prefix ? `${u.unit.prefix}/${at}` : at;
444
+ const held = memberPaths(u.unit, p).map((x) => x.path);
442
445
  const sanitizing = (config.html ?? input.defaultHtml ?? "keep") === "sanitize";
443
- if (key === "_headers" || key === "_redirects") continue;
444
- if (copiedPath(at) && await assetVerdict(at, content, input.untrusted === true, sanitizing) === "copy") out.set(key, content);
445
- else out.delete(key);
446
+ for (const at of held.length ? held : [p.slice(sourceRoot(u.unit.source).length)]) {
447
+ const key = u.unit.prefix ? `${u.unit.prefix}/${at}` : at;
448
+ if (key === "_headers" || key === "_redirects") continue;
449
+ if (copiedPath(at) && await assetVerdict(at, content, input.untrusted === true, sanitizing) === "copy") out.set(key, content);
450
+ else out.delete(key);
451
+ }
446
452
  }
447
453
  }
448
454
  if (lazy.size) for (const s of ctx.state.stubs) out.delete(s);
@@ -649,7 +655,7 @@ async function dev(projectDir, port, o = {}) {
649
655
  files.clear();
650
656
  for (const [k, v] of readProject(project, projectRoots(cfg), [outDir])) files.set(k, v);
651
657
  if (cfgName && text !== void 0) files.set(cfgName, text);
652
- navMaps = new Set(await readTopicMaps(project, cfg, files, [outDir]));
658
+ navMaps = new Set(await readMenus(project, cfg, files, [outDir]));
653
659
  return true;
654
660
  };
655
661
  await layout(cfgText);
@@ -741,9 +747,9 @@ data: ${data ?? generation}
741
747
  }
742
748
  }
743
749
  }
744
- if ([...changed].some((p) => TOPIC_MAP.test(p) || navMaps.has(p))) {
750
+ if ([...changed].some((p) => MENU_FILE.test(p) || navMaps.has(p))) {
745
751
  const before = new Set(files.keys());
746
- navMaps = new Set(await readTopicMaps(project, cfg, files, [outDir]));
752
+ navMaps = new Set(await readMenus(project, cfg, files, [outDir]));
747
753
  for (const k of files.keys()) if (!before.has(k)) changed.add(k);
748
754
  }
749
755
  } catch (e) {
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
3
+ import {
4
+ NOT_A_MENU_CODES,
5
+ menuToNav,
6
+ navFromMenu,
7
+ normalize,
8
+ oldStylePaths,
9
+ parseMenu,
10
+ resolveMenuFile,
11
+ slugFromPath
12
+ } from "./chunk-IERF2DNL.mjs";
13
+ import "./chunk-YVSP26OS.mjs";
14
+ import "./chunk-O3R3MASP.mjs";
15
+ import "./chunk-G6OTOD3B.mjs";
16
+ import "./chunk-STRHO6SY.mjs";
17
+
18
+ // src/core/menu.ts
19
+ var MENU_FILES = ["nav.yml", "nav.yaml", "nav.json"];
20
+ async function sourceMenu(path, contentRoot, read, variables, found, has) {
21
+ const root = normalize(path.replace(/^\.\//, ""));
22
+ const content = contentRoot.replace(/\/+$/, "");
23
+ const files = [];
24
+ const result = await resolveMenuFile(root, {
25
+ contentRoot: content,
26
+ variables,
27
+ loader: async (p) => {
28
+ const at = normalize(p);
29
+ if (at === ".." || at.startsWith("../") || at.startsWith("/")) throw new Error(`${p} is outside the project`);
30
+ const text = await read(at);
31
+ if (text === void 0) throw new Error("no such file");
32
+ files.push(at);
33
+ return text;
34
+ }
35
+ });
36
+ const errors = [...result.errors];
37
+ if (found) {
38
+ const why = errors.find((e) => e.file === root && NOT_A_MENU_CODES.has(e.code));
39
+ if (why) return { path: root, entries: [], files, errors: [], notAMenu: why };
40
+ }
41
+ if (!errors.some((e) => e.file === root && e.code === "load-failed")) {
42
+ const text = await read(root);
43
+ if (text !== void 0) errors.push(...await oldStylePaths(text, root, content, (p) => has(p.replace(/^\/+/, ""))));
44
+ }
45
+ return { path: root, entries: result.entries, files: result.files.length ? result.files : files, errors };
46
+ }
47
+ function menuError(menu) {
48
+ const problems = menu.errors.filter((e) => e.severity !== "warning");
49
+ if (!problems.length) return void 0;
50
+ const details = problems.map((e) => ` \u2717 ${e.file}${e.line ? `:${e.line}` : ""}: [${e.code}] ${e.message}`).join("\n");
51
+ return new Error(`The menu ${menu.path} has ${problems.length} problem(s):
52
+ ${details}
53
+ Check it with: dogsbay nav check ${menu.path}`);
54
+ }
55
+ function menuNav(entries, labelFor) {
56
+ return navFromMenu(menuToNav(entries, (file) => labelFor(slugFromPath(file))));
57
+ }
58
+ function navFromText(text, labelFor, baseDir = "", file = "nav file") {
59
+ const { entries, errors } = parseMenu(text, file);
60
+ const error = errors.find((e) => e.severity !== "warning");
61
+ if (error) throw new Error(`${file}${error.line ? `:${error.line}` : ""}: ${error.message}`);
62
+ const plain = (list) => list.map((e) => {
63
+ if (e.include !== void 0) throw new Error(`${file}${e.line ? `:${e.line}` : ""}: include: ${e.include} needs the site build, which reads included menu files`);
64
+ const out = { ...e };
65
+ if (out.file !== void 0) {
66
+ const f = out.file.replace(/^\/+/, "");
67
+ out.file = baseDir ? `${baseDir}/${f}` : f;
68
+ }
69
+ if (out.children) out.children = plain(out.children);
70
+ return out;
71
+ });
72
+ return navFromMenu(menuToNav(plain(entries), (f) => labelFor(slugFromPath(f))));
73
+ }
74
+ function parseNavYaml(text, labelFor, baseDir = "") {
75
+ return navFromText(text, labelFor, baseDir, "nav.yml");
76
+ }
77
+ function parseNavJson(text, labelFor) {
78
+ return navFromText(text, labelFor, "", "nav.json");
79
+ }
80
+ export {
81
+ MENU_FILES,
82
+ menuError,
83
+ menuNav,
84
+ navFromText,
85
+ parseNavJson,
86
+ parseNavYaml,
87
+ sourceMenu
88
+ };
@@ -4,9 +4,9 @@ import {
4
4
  copiedPath,
5
5
  parseConfig,
6
6
  readBuildFiles
7
- } from "./chunk-3O2UA2GP.mjs";
7
+ } from "./chunk-3ZUDN6IL.mjs";
8
8
  import "./chunk-KFYMG4VB.mjs";
9
- import "./chunk-5APY2GH6.mjs";
9
+ import "./chunk-IERF2DNL.mjs";
10
10
  import {
11
11
  UsageError,
12
12
  flag,
@@ -14,7 +14,7 @@ import {
14
14
  positional
15
15
  } from "./chunk-LNWQN7K7.mjs";
16
16
  import "./chunk-YVSP26OS.mjs";
17
- import "./chunk-Z7WUDBZV.mjs";
17
+ import "./chunk-O3R3MASP.mjs";
18
18
  import {
19
19
  TEXT_FILE,
20
20
  isLazyText,
@@ -9,17 +9,17 @@ import {
9
9
  releaseDiff,
10
10
  releaseExitCode,
11
11
  releaseRedirects
12
- } from "./chunk-VZBVWLWQ.mjs";
12
+ } from "./chunk-FTSK7GL6.mjs";
13
13
  import {
14
14
  buildUnits,
15
15
  parseConfig,
16
16
  readBuildFiles,
17
17
  versionsOf
18
- } from "./chunk-3O2UA2GP.mjs";
18
+ } from "./chunk-3ZUDN6IL.mjs";
19
19
  import "./chunk-KFYMG4VB.mjs";
20
- import "./chunk-5APY2GH6.mjs";
20
+ import "./chunk-IERF2DNL.mjs";
21
21
  import "./chunk-YVSP26OS.mjs";
22
- import "./chunk-Z7WUDBZV.mjs";
22
+ import "./chunk-O3R3MASP.mjs";
23
23
  import "./chunk-JABACD5T.mjs";
24
24
  import "./chunk-G6OTOD3B.mjs";
25
25
  import "./chunk-STRHO6SY.mjs";
package/cli.mjs CHANGED
@@ -37,16 +37,16 @@ async function main() {
37
37
  usage(1);
38
38
  }
39
39
  if (wantsHelp(args)) usage(0, cmd);
40
- if (cmd === "build") return (await import("./chunks/build-command-6VT3ZZKE.mjs")).runBuild(args, HIGHLIGHT_WORKER);
41
- if (cmd === "assemble") return (await import("./chunks/build-command-6VT3ZZKE.mjs")).runBuild(args, HIGHLIGHT_WORKER, { assemble: true });
42
- if (cmd === "check") return (await import("./chunks/check-command-JHIOF55J.mjs")).runCheck(args);
43
- if (cmd === "publish") return (await import("./chunks/publish-command-XYUBSAQD.mjs")).runPublish(args);
40
+ if (cmd === "build") return (await import("./chunks/build-command-VO7SKUVH.mjs")).runBuild(args, HIGHLIGHT_WORKER);
41
+ if (cmd === "assemble") return (await import("./chunks/build-command-VO7SKUVH.mjs")).runBuild(args, HIGHLIGHT_WORKER, { assemble: true });
42
+ if (cmd === "check") return (await import("./chunks/check-command-UVSGIYBI.mjs")).runCheck(args);
43
+ if (cmd === "publish") return (await import("./chunks/publish-command-7WTTDYPN.mjs")).runPublish(args);
44
44
  if (cmd === "release-diff") {
45
45
  const from = option(args, "--from")[0];
46
46
  const gitFrom = option(args, "--git-from")[0];
47
47
  const o = { from, gitFrom, json: flag(args, "--json"), write: flag(args, "--write"), candidates: flag(args, "--candidates"), strict: flag(args, "--strict") };
48
48
  const project = resolve(positional(args, "."));
49
- const { runReleaseDiff } = await import("./chunks/release-diff-ANIJOQNZ.mjs");
49
+ const { runReleaseDiff } = await import("./chunks/release-diff-GFTKWVAD.mjs");
50
50
  process.exitCode = await runReleaseDiff(project, o);
51
51
  return;
52
52
  }
@@ -58,7 +58,7 @@ async function main() {
58
58
  const llms = flag(args, "--llms");
59
59
  const project = resolve(positional(args, "."));
60
60
  const t0 = performance.now();
61
- const { dev, readyLine, serverUrl } = await import("./chunks/dev-5FQMGMCX.mjs");
61
+ const { dev, readyLine, serverUrl } = await import("./chunks/dev-LUUO2CTK.mjs");
62
62
  const { server } = await dev(project, port, { diagrams: !noDiagrams, lazy, search: noSearchDev ? false : void 0, llms, token: process.env.DOGSBAY_DEV_TOKEN || void 0, listening: (s) => console.log(readyLine(s)) });
63
63
  console.log(`dev server for ${project} at ${serverUrl(server)} (ready in ${Math.round(performance.now() - t0)} ms); watching for changes`);
64
64
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/ssg-cli",
3
- "version": "0.2.0-beta.178",
3
+ "version": "0.2.0-beta.181",
4
4
  "type": "module",
5
5
  "description": "The dogsbay-ssg command: build, check, preview and publish Dogsbay-MD documentation sites that work offline",
6
6
  "license": "Apache-2.0",
@@ -18,7 +18,7 @@
18
18
  "NOTICE"
19
19
  ],
20
20
  "dependencies": {
21
- "@dogsbay/icons": "0.2.0-beta.178",
21
+ "@dogsbay/icons": "0.2.0-beta.181",
22
22
  "@mermanjs/web-render": "0.9.3"
23
23
  },
24
24
  "publishConfig": {