ssqch 0.10.0 → 0.11.0

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.
Files changed (95) hide show
  1. package/bundled/completions/bash +62 -16
  2. package/bundled/completions/elvish +28 -12
  3. package/bundled/completions/fish +36 -23
  4. package/bundled/completions/powershell +30 -12
  5. package/bundled/completions/zsh +40 -19
  6. package/bundled/docs/agents.md +12 -1
  7. package/bundled/docs/build-summary.md +31 -1
  8. package/bundled/docs/comparing-builds.md +37 -5
  9. package/bundled/docs/configuring.md +30 -5
  10. package/bundled/docs/field-guide.md +1 -1
  11. package/bundled/docs/github-pages.md +1 -1
  12. package/bundled/docs/index.md +1 -1
  13. package/bundled/docs/known-gaps.md +1 -1
  14. package/bundled/docs/markdown.md +63 -5
  15. package/bundled/docs/multilingual.md +20 -3
  16. package/bundled/docs/nav.yml +1 -0
  17. package/bundled/docs/netlify.md +2 -2
  18. package/bundled/docs/plugins.md +4 -4
  19. package/bundled/docs/seo.md +39 -1
  20. package/bundled/docs/template-languages.md +6 -4
  21. package/bundled/docs/templates.md +3 -3
  22. package/bundled/docs/trailheads/from-eleventy.md +25 -13
  23. package/bundled/docs/trailheads/from-hugo.md +103 -0
  24. package/bundled/docs/trailheads/from-jekyll.md +49 -15
  25. package/bundled/docs/trailheads/from-mkdocs.md +54 -9
  26. package/bundled/docs/trailheads/from-zola.md +2 -2
  27. package/bundled/docs/trailheads.md +22 -5
  28. package/bundled/docs/where-values-come-from.md +1 -1
  29. package/bundled/mkdocs/404.jinja +6 -0
  30. package/bundled/ssqch.d.ts +78 -18
  31. package/lib/assets.js +11 -12
  32. package/lib/{chunk-3HHRKG33.js → chunk-2L3HR67O.js} +71 -19
  33. package/lib/{chunk-LCPSKHAV.js → chunk-2QTJTEBV.js} +1 -1
  34. package/lib/{chunk-RVBNVGZV.js → chunk-3HZZY3Y7.js} +5 -6
  35. package/lib/{chunk-RKFZSVNF.js → chunk-3K237XAX.js} +10 -11
  36. package/lib/{chunk-HXCLCXRT.js → chunk-443ZQLVX.js} +5 -3
  37. package/lib/{chunk-Q4LFTYK2.js → chunk-5ELAUHRL.js} +20 -20
  38. package/lib/{chunk-SA5KSJ4Y.js → chunk-A75EVUJX.js} +10 -12
  39. package/lib/{chunk-BGCBSQ4A.js → chunk-AIMEXBTK.js} +163 -29
  40. package/lib/{chunk-Y2ESFAAD.js → chunk-B5E27PLU.js} +10 -41
  41. package/lib/{chunk-RJFWTW2Y.js → chunk-CMJ7X5WW.js} +3 -3
  42. package/lib/{chunk-NKXEPHRZ.js → chunk-ERAIEV3O.js} +106 -4
  43. package/lib/{chunk-E5UB2YY7.js → chunk-FCM3NYFR.js} +11 -9
  44. package/lib/{chunk-3EPHKJEG.js → chunk-GJNIQAIH.js} +8 -8
  45. package/lib/{chunk-CB6YFUXU.js → chunk-GLJQ4C76.js} +40 -21
  46. package/lib/{chunk-DDV6JEC2.js → chunk-GS5B3CBW.js} +1 -1
  47. package/lib/chunk-H5K2ZE7B.js +219 -0
  48. package/lib/{chunk-NFJJKDRI.js → chunk-HFSWUTXX.js} +1 -1
  49. package/lib/{chunk-4Q6WMTER.js → chunk-HWW5NCVJ.js} +1 -1
  50. package/lib/{chunk-LAV3DEY4.js → chunk-I3HYKEEW.js} +1 -1
  51. package/lib/{chunk-JWCCVTTR.js → chunk-IOBC665M.js} +2 -4
  52. package/lib/chunk-JC54PHIT.js +7992 -0
  53. package/lib/{chunk-2LEOPLTZ.js → chunk-KCF2Z6N7.js} +3 -5
  54. package/lib/{chunk-DMVJ53SM.js → chunk-KZZS4W2V.js} +15 -15
  55. package/lib/{chunk-RM5Q3KFB.js → chunk-LJOURBYT.js} +14 -13
  56. package/lib/chunk-OQGXZYZS.js +45 -0
  57. package/lib/chunk-OSBEH67S.js +6296 -0
  58. package/lib/{chunk-DW7VMJEZ.js → chunk-QJ5ZFTML.js} +14 -13
  59. package/lib/{chunk-NUUEOGLZ.js → chunk-QLUTNR37.js} +11 -11
  60. package/lib/{chunk-HGJ5VWUR.js → chunk-RBNPBTDP.js} +1 -1
  61. package/lib/{chunk-F65YUXZ7.js → chunk-RIAOXEXC.js} +10 -4
  62. package/lib/chunk-RVXGUMFI.js +21 -0
  63. package/lib/{chunk-N4O5MDIB.js → chunk-RYIWYWRQ.js} +5 -7
  64. package/lib/{chunk-EEJDLCD3.js → chunk-RZYAIX2R.js} +12 -11
  65. package/lib/{chunk-7HXCQEGA.js → chunk-V2FSMOFX.js} +3 -3
  66. package/lib/{chunk-HDQ4SRWM.js → chunk-X2GAVYV2.js} +525 -75
  67. package/lib/chunk-XS4EJSEK.js +279 -0
  68. package/lib/chunk-YCOTX2VM.js +37 -0
  69. package/lib/{chunk-QMA7CK7B.js → chunk-Z44IAMNG.js} +137 -32
  70. package/lib/chunk-Z5OP43HU.js +2945 -0
  71. package/lib/{chunk-JXZT5L7W.js → chunk-ZINLHOX4.js} +2 -3
  72. package/lib/{chunk-SRNLKWXL.js → chunk-ZR3JYLFB.js} +893 -12382
  73. package/lib/cli.js +82 -41
  74. package/lib/elements.js +11 -12
  75. package/lib/image.js +11 -11
  76. package/lib/links.js +11 -12
  77. package/lib/minify.js +71 -13
  78. package/lib/redirects.js +11 -12
  79. package/lib/rss.js +13 -11
  80. package/lib/sass.js +13 -245
  81. package/lib/sitemap.js +19 -18
  82. package/lib/ssqch.js +6 -5
  83. package/package.json +1 -1
  84. package/types/index.d.ts +59 -13
  85. package/types/minify.d.ts +15 -3
  86. package/types/sass.d.ts +2 -0
  87. package/types/sitemap.d.ts +2 -2
  88. package/wasm/markdown.wasm +0 -0
  89. package/wasm/minify.wasm +0 -0
  90. package/wasm/sass.wasm +0 -0
  91. package/lib/chunk-5DNDSNTP.js +0 -1541
  92. package/lib/chunk-VJWQSYEG.js +0 -119
  93. package/lib/chunk-ZM6TU2JB.js +0 -1287
  94. /package/lib/{chunk-BGCBSQ4A.js.LEGAL.txt → chunk-AIMEXBTK.js.LEGAL.txt} +0 -0
  95. /package/lib/{chunk-SRNLKWXL.js.LEGAL.txt → chunk-ZR3JYLFB.js.LEGAL.txt} +0 -0
@@ -3,19 +3,96 @@ const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  dirsOf,
5
5
  shownOutput
6
- } from "./chunk-DDV6JEC2.js";
6
+ } from "./chunk-GS5B3CBW.js";
7
7
  import {
8
8
  FIRST_SITING,
9
9
  LEFT_NO_TRACE,
10
10
  RECOVERED
11
11
  } from "./chunk-UU43WIZG.js";
12
12
  import {
13
- relative
14
- } from "./chunk-VJWQSYEG.js";
13
+ relative,
14
+ warning
15
+ } from "./chunk-AIMEXBTK.js";
15
16
 
16
17
  // src/report.ts
17
18
  import fs from "node:fs";
18
19
  import path from "node:path";
20
+
21
+ // src/profile.ts
22
+ var SLOW_MS = 1e3;
23
+ var KINDS = ["pages", "templates", "layouts", "engines", "filters", "transforms", "data", "collections", "hooks"];
24
+ var SINGULAR = { pages: "page", templates: "template", layouts: "layout", engines: "template engine", filters: "filter", transforms: "transform", data: "data", collections: "collection", hooks: "hook" };
25
+ var isPromise = (v) => typeof v?.then === "function";
26
+ var Profile = class {
27
+ /** `--profile`: time everything. Otherwise only the site's own functions, for `slow-call`. */
28
+ detailed;
29
+ /** The page being rendered, which a slow call is said to be working on (pages render one at a time). */
30
+ at;
31
+ stats = new Map(KINDS.map((k) => [k, /* @__PURE__ */ new Map()]));
32
+ constructor(detailed) {
33
+ this.detailed = detailed;
34
+ }
35
+ /** Records one call of `name`, which took `ms`. */
36
+ add(kind, name, ms, own, from, at = this.at, async = false) {
37
+ if (!this.detailed && !(own && ms >= SLOW_MS)) return;
38
+ const of = this.stats.get(kind);
39
+ let stat = of.get(name);
40
+ if (!stat) of.set(name, stat = { calls: 0, ms: 0, own, from, slowCalls: 0, async: false });
41
+ stat.calls++;
42
+ if (async) stat.async = true;
43
+ stat.ms += ms;
44
+ if (ms >= SLOW_MS && stat.slowCalls++ === 0) [stat.firstSlow, stat.firstSlowAt] = [ms, at];
45
+ }
46
+ /** Runs `call` and records its time, until it returns or, for a promise, settles. */
47
+ time(kind, name, own, call, from) {
48
+ const at = this.at;
49
+ const start = performance.now();
50
+ const out = call();
51
+ if (isPromise(out)) {
52
+ const done = () => this.add(kind, name, performance.now() - start, own, from, at, true);
53
+ out.then(done, done);
54
+ } else this.add(kind, name, performance.now() - start, own, from, at);
55
+ return out;
56
+ }
57
+ /** `fn`, timed whenever it's called (with the `this` it's called with: Nunjucks passes its context). */
58
+ wrap(kind, name, fn, own, from) {
59
+ const profile = this;
60
+ return function(...args) {
61
+ return profile.time(kind, name, own, () => fn.apply(this, args), from);
62
+ };
63
+ }
64
+ /** Whether a function of this kind is timed: every one with `--profile`, the site's own without. */
65
+ times(own) {
66
+ return this.detailed || own;
67
+ }
68
+ /** The `slow-call` warnings: one for each of the site's own functions with a call of a second or more. */
69
+ slowCalls() {
70
+ const out = [];
71
+ for (const kind of KINDS) {
72
+ for (const [name, s] of this.stats.get(kind)) {
73
+ if (!s.own || s.slowCalls === 0) continue;
74
+ const what = kind === "hooks" ? name : `${SINGULAR[kind]} \`${name}\``;
75
+ const from = s.from ? ` (from ${s.from})` : "";
76
+ const at = s.firstSlowAt ? ` working on ${s.firstSlowAt}` : "";
77
+ const more = s.slowCalls > 1 ? `, the first of ${s.slowCalls} calls that took over a second` : "";
78
+ out.push(warning("slow-call", `${what}${from} took ${seconds(s.firstSlow)}${at}${more}. \`ssqch build --profile\` shows where a build's time goes`));
79
+ }
80
+ }
81
+ return out;
82
+ }
83
+ /** Every kind's list, slowest first (by total time, then name). Empty without `--profile`. */
84
+ report() {
85
+ const out = {};
86
+ for (const kind of KINDS) {
87
+ const list = this.detailed ? [...this.stats.get(kind)].map(([name, s]) => ({ name, calls: s.calls, ms: s.ms, async: s.async })) : [];
88
+ out[kind] = list.sort((a, b) => b.ms - a.ms || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
89
+ }
90
+ return out;
91
+ }
92
+ };
93
+ var seconds = (ms) => `${(ms / 1e3).toFixed(1)} s`;
94
+
95
+ // src/report.ts
19
96
  function summary(config, report, recovered = false) {
20
97
  const dirs = dirsOf(config);
21
98
  const nothing = report.templates === 0 && report.drafts === 0 && report.pagesWritten === 0;
@@ -126,11 +203,36 @@ function fixed(v, digits) {
126
203
  if (last % 2 === 0) return down;
127
204
  return v.toFixed(digits);
128
205
  }
206
+ var PROFILE_TOP = 10;
207
+ function profileText(profile) {
208
+ const titles = { pages: "Pages", templates: "Templates (pages)", layouts: "Layouts (renders)", engines: "Template engines (renders)", filters: "Filters (calls)", transforms: "Transforms (pages)", data: "Data", collections: "Collections", hooks: "Hooks" };
209
+ const withCalls = /* @__PURE__ */ new Set(["templates", "layouts", "engines", "filters", "transforms"]);
210
+ let out = "Profile: where the time went, slowest first (a call's time includes the calls it makes)\n";
211
+ if (KINDS.some((kind) => profile[kind].some((e) => e.async))) out += "Async ones are timed until they settle, and overlap: their totals can add up to more than the build took\n";
212
+ for (const kind of KINDS) {
213
+ const list = profile[kind];
214
+ if (!list.length) continue;
215
+ out += ` ${titles[kind]}
216
+ `;
217
+ const shown = list.slice(0, PROFILE_TOP);
218
+ const width = Math.max(...shown.map((e) => duration(e.ms).length));
219
+ for (const e of shown) {
220
+ const notes = [...withCalls.has(kind) ? [count(e.calls)] : [], ...e.async ? ["async"] : []];
221
+ out += ` ${duration(e.ms).padStart(width)} ${e.name}${notes.length ? ` (${notes.join(", ")})` : ""}
222
+ `;
223
+ }
224
+ if (list.length > PROFILE_TOP) out += ` ...and ${count(list.length - PROFILE_TOP)} more (--format json lists them all)
225
+ `;
226
+ }
227
+ return out;
228
+ }
129
229
 
130
230
  export {
231
+ Profile,
131
232
  summary,
132
233
  count,
133
234
  bytes,
134
235
  duration,
135
- fixed
236
+ fixed,
237
+ profileText
136
238
  };
@@ -3,35 +3,37 @@ const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  BUILTINS,
5
5
  DEFAULTS,
6
+ EngineCache,
6
7
  configOptions,
7
8
  findConfig,
8
9
  loadConfig,
9
10
  meant,
10
11
  tomlKeyLine
11
- } from "./chunk-QMA7CK7B.js";
12
- import "./chunk-LCPSKHAV.js";
13
- import "./chunk-NKXEPHRZ.js";
12
+ } from "./chunk-Z44IAMNG.js";
13
+ import "./chunk-2QTJTEBV.js";
14
+ import "./chunk-ERAIEV3O.js";
14
15
  import "./chunk-AD3HAW3W.js";
16
+ import "./chunk-YCOTX2VM.js";
15
17
  import {
16
18
  CONFIG_FILES,
17
19
  dirsOf,
18
20
  parseEnvironment,
19
21
  shownDir,
20
22
  shownOutput
21
- } from "./chunk-DDV6JEC2.js";
22
- import "./chunk-5DNDSNTP.js";
23
+ } from "./chunk-GS5B3CBW.js";
24
+ import "./chunk-JC54PHIT.js";
25
+ import "./chunk-HFSWUTXX.js";
23
26
  import "./chunk-FVZ5JBRI.js";
24
- import "./chunk-NFJJKDRI.js";
25
27
  import "./chunk-UU43WIZG.js";
26
- import "./chunk-JWCCVTTR.js";
28
+ import "./chunk-IOBC665M.js";
27
29
  import "./chunk-CMUWRPSQ.js";
28
- import "./chunk-BGCBSQ4A.js";
29
- import "./chunk-VJWQSYEG.js";
30
+ import "./chunk-AIMEXBTK.js";
30
31
  import "./chunk-I3PS26CI.js";
31
32
  export {
32
33
  BUILTINS,
33
34
  CONFIG_FILES,
34
35
  DEFAULTS,
36
+ EngineCache,
35
37
  configOptions,
36
38
  dirsOf,
37
39
  findConfig,
@@ -2,24 +2,24 @@ import { createRequire as __ssqchCreateRequire } from "node:module";
2
2
  const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  starterEngines
5
- } from "./chunk-Y2ESFAAD.js";
5
+ } from "./chunk-B5E27PLU.js";
6
6
  import {
7
7
  DEFAULTS,
8
8
  configOptions
9
- } from "./chunk-QMA7CK7B.js";
9
+ } from "./chunk-Z44IAMNG.js";
10
10
  import {
11
11
  VERSION
12
12
  } from "./chunk-AD3HAW3W.js";
13
13
  import {
14
14
  CONFIG_FILES
15
- } from "./chunk-DDV6JEC2.js";
15
+ } from "./chunk-GS5B3CBW.js";
16
16
  import {
17
17
  red
18
- } from "./chunk-BGCBSQ4A.js";
18
+ } from "./chunk-AIMEXBTK.js";
19
19
 
20
20
  // src/commands/capabilities.ts
21
21
  var MODULE_EXPORTS = [
22
- ["ssqch", ["defineConfig", "markdown", "readData", "files", "slugify", "slugger"]],
22
+ ["ssqch", ["defineConfig", "markdown", "readData", "files", "slugify", "slugger", "safe"]],
23
23
  ["ssqch/image", ["imagePlugin", "image", "imageUrl"]],
24
24
  ["ssqch/rss", ["rssPlugin", "getNewestCollectionItemDate", "dateToRfc3339", "dateToRfc822", "absoluteUrl", "htmlToAbsoluteUrls", "feedHtml"]],
25
25
  ["ssqch/assets", ["assetsPlugin"]],
@@ -28,7 +28,7 @@ var MODULE_EXPORTS = [
28
28
  ["ssqch/redirects", ["redirectsPlugin"]],
29
29
  ["ssqch/sass", ["sassPlugin"]],
30
30
  ["ssqch/elements", ["elementsPlugin"]],
31
- ["ssqch/minify", ["minifyPlugin", "minify"]]
31
+ ["ssqch/minify", ["minifyPlugin", "minify", "minifyCss"]]
32
32
  ];
33
33
  var NODE_MODULES = ["fs", "fs/promises", "path", "path/posix", "url", "process", "buffer", "crypto", "module", "util", "events", "os", "assert", "assert/strict", "timers", "timers/promises", "string_decoder", "http", "https", "http2", "net", "tls", "dns", "child_process", "worker_threads", "cluster", "readline", "zlib", "vm", "stream", "tty", "perf_hooks"];
34
34
  function modules() {
@@ -73,7 +73,7 @@ async function capabilities(commands) {
73
73
  imageFormats: avif ? ["avif", "webp", "jpeg", "png", "gif", "svg"] : ["webp", "jpeg", "png", "gif", "svg"],
74
74
  starters: ["site", "docs"],
75
75
  starterEngines: starterEngines(),
76
- importers: ["eleventy", "zola"]
76
+ importers: ["eleventy", "jekyll", "zola", "hugo", "mkdocs"]
77
77
  };
78
78
  }
79
79
  function text(caps) {
@@ -96,7 +96,7 @@ function text(caps) {
96
96
  row("Globals", caps.globals.join(", "));
97
97
  row("Image formats", caps.imageFormats.join(", "));
98
98
  row("Starters", `${caps.starters.join(", ")} (in ${caps.starterEngines.join(", ")})`);
99
- row("Importers", caps.importers.join(", "));
99
+ row("Scout reads", caps.importers.join(", "));
100
100
  return out + "\n--format json has all of it, with each module's exports.\n";
101
101
  }
102
102
  async function runCapabilities(format, commands) {
@@ -2,30 +2,30 @@ import { createRequire as __ssqchCreateRequire } from "node:module";
2
2
  const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  withBase
5
- } from "./chunk-QMA7CK7B.js";
5
+ } from "./chunk-Z44IAMNG.js";
6
6
  import {
7
7
  slugOptions,
8
+ slugText,
8
9
  slugWith
9
- } from "./chunk-5DNDSNTP.js";
10
+ } from "./chunk-JC54PHIT.js";
10
11
  import {
11
12
  BuildError,
13
+ compareText,
12
14
  isPlainObject
13
- } from "./chunk-BGCBSQ4A.js";
14
- import {
15
- compareText
16
- } from "./chunk-VJWQSYEG.js";
15
+ } from "./chunk-AIMEXBTK.js";
17
16
 
18
17
  // src/content.ts
19
18
  var HEADING = /<h([1-6])(\s[^>]*)?>(.*?)<\/h[1-6]\s*>/gis;
20
19
  var ID_ATTR = /(?:^|\s)id\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i;
21
20
  var TAG = /<(\/?)([A-Za-z][A-Za-z0-9-]*)([^>]*)>|<!--.*?-->/gs;
22
21
  var HIDDEN = /\saria-hidden\s*=\s*["']?true/i;
23
- var CODE = /<!--.*?-->|<(pre|code|script|style|template|textarea)\b.*?<\/(?:pre|code|script|style|template|textarea)\s*>/gis;
22
+ var CODE = /<!--.*?-->|<(pre|script|style|template|textarea)\b.*?<\/(?:pre|script|style|template|textarea)\s*>/gis;
23
+ var CODE_WITH_HEADING = /<code\b(?:(?!<\/code\s*>).)*?<h[1-6][\s>](?:(?!<\/code\s*>).)*<\/code\s*>/gis;
24
24
  var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
25
25
  function headings(html) {
26
26
  if (!html.includes("<h") && !html.includes("<H")) return [];
27
27
  const out = [];
28
- for (const found of html.replace(CODE, "").matchAll(HEADING)) {
28
+ for (const found of html.replace(CODE, "").replace(CODE_WITH_HEADING, "").matchAll(HEADING)) {
29
29
  const id = ID_ATTR.exec(found[2] ?? "");
30
30
  const value = id ? id[1] ?? id[2] ?? id[3] : void 0;
31
31
  out.push({ level: Number(found[1]), id: value === void 0 ? void 0 : decodeEntities(value), text: htmlText(found[3]) });
@@ -287,19 +287,31 @@ function totalCompare(a, b) {
287
287
  return 0;
288
288
  }
289
289
  var get = (v, key) => isPlainObject(v) ? v[key] : void 0;
290
- function fromPages(items) {
291
- let nodes = [];
290
+ var NAV_OWN = /* @__PURE__ */ new Set(["title", "key", "parent", "order", "url", ...CHILD_KEYS]);
291
+ function fromPages(items, options = {}) {
292
+ const nodes = [];
292
293
  for (const item of items) {
293
294
  const data = get(item, "data");
294
295
  const nav = get(data, "nav");
295
296
  if (nav === void 0 || nav === null || nav === false) continue;
296
297
  const navTitle = get(nav, "title");
297
- const title = typeof navTitle === "string" ? navTitle : String(get(data, "title"));
298
298
  const navKey = get(nav, "key");
299
+ const pageTitle = get(data, "title");
300
+ const title = typeof navTitle === "string" ? navTitle : pageTitle !== void 0 && pageTitle !== null ? String(pageTitle) : typeof navKey === "string" ? navKey : "";
299
301
  const key = typeof navKey === "string" ? navKey : title;
300
302
  const parent = get(nav, "parent");
301
303
  const order = get(nav, "order");
302
- nodes.push({ key, parent: typeof parent === "string" ? parent : void 0, order: typeof order === "number" ? order : Number.MAX_VALUE, entry: { title, url: get(item, "url"), key } });
304
+ const navUrl = get(nav, "url");
305
+ const extra = isPlainObject(nav) ? Object.fromEntries(Object.entries(nav).filter(([k]) => !NAV_OWN.has(k))) : {};
306
+ nodes.push({ key, parent: typeof parent === "string" ? parent : void 0, order: typeof order === "number" ? order : Number.MAX_VALUE, entry: { ...extra, title, url: typeof navUrl === "string" ? navUrl : get(item, "url"), key } });
307
+ }
308
+ const keys = new Set(nodes.map((n) => n.key));
309
+ for (const n of [...nodes]) {
310
+ if (n.parent === void 0 || keys.has(n.parent)) continue;
311
+ keys.add(n.parent);
312
+ const siblings = nodes.filter((m) => m.parent === n.parent);
313
+ const order = Math.min(...siblings.map((m) => m.order));
314
+ nodes.push({ key: n.parent, parent: void 0, order, entry: { title: n.parent, key: n.parent } });
303
315
  }
304
316
  const build = (parent, depth) => {
305
317
  if (depth > 32) return [];
@@ -307,23 +319,21 @@ function fromPages(items) {
307
319
  level.sort((a, b) => totalCompare(a.order, b.order) || compareText(a.entry.title, b.entry.title));
308
320
  return level.map((n) => ({ ...n.entry, children: build(n.key, depth + 1) }));
309
321
  };
310
- const keys = new Set(nodes.map((n) => n.key));
311
- nodes = nodes.map((n) => n.parent !== void 0 && !keys.has(n.parent) ? { ...n, parent: void 0 } : n);
312
- return build(void 0, 0);
322
+ return options.root === void 0 ? build(void 0, 0) : build(options.root, 1);
313
323
  }
314
324
 
315
325
  // src/filters.ts
316
326
  var BUILTIN_FILTERS = [
317
327
  ["markdown", '`markdown(text)` renders Markdown with the site\'s options; `markdown(text, "inline")` without the `<p>`.'],
318
- ["toc", "`toc(page.headings)` is a table of contents; `toc(page.headings, { from: 2, to: 4, ordered: true })` picks the levels, and `id`, `class`, `sublistClass`, `itemClass` (`{level}` is the heading's) and `linkClass` set the markup's."],
328
+ ["toc", "`toc(page.headings)` is a table of contents (or `toc(html)`, from HTML's headings); `toc(page.headings, { from: 2, to: 4, ordered: true })` picks the levels, and `id`, `class`, `sublistClass`, `itemClass` (`{level}` is the heading's) and `linkClass` set the markup's."],
319
329
  ["navTree", "`navTree(nav, page.url)` marks a navigation tree's entries `current`, `ancestor` or `open`."],
320
330
  ["navPager", "`navPager(nav, page.url)` is `{ previous, next }` in reading order."],
321
331
  ["navBreadcrumbs", "`navBreadcrumbs(nav, page.url)` is the entries from the top down to the page."],
322
- ["pagesTree", "`pagesTree(collections.docs)` builds a navigation tree from pages' `nav` front matter."],
332
+ ["pagesTree", '`pagesTree(collections.docs)` builds a navigation tree from pages\' `nav` front matter; `pagesTree(collections.all, { root: "Feature" })` (or `pagesTree(collections.all, "Feature")`) is the tree below one key.'],
323
333
  ["highlight", "`highlight(code, lang)` is highlighted HTML for inside a `<code>`, with `hl-*` classes."],
324
334
  ["readingTime", "`readingTime(content)` is the minutes it takes to read some HTML, at 200 words a minute."],
325
335
  ["withBase", '`withBase("/feed.xml")` puts the site\'s `base` in front of a URL, for places outside HTML attributes.'],
326
- ["slugify", '`slugify("Pine Cone Crunch!")` is `pine-cone-crunch`: lowercase letters and digits, with a dash for each run of anything else; `slugify(title, { separator: "_" })` uses another separator, and `apostrophes: "separate"` splits words at an apostrophe instead of dropping it.']
336
+ ["slugify", '`slugify("Pine Cone Crunch!")` is `pine-cone-crunch`: lowercase letters and digits, with a dash for each run of anything else; `slugify(title, { separator: "_" })` uses another separator, `apostrophes: "separate"` splits words at an apostrophe instead of dropping it, `ascii: true` takes accents off and spells out symbols as the slugify package does (`Sj\xF6gren & co` is `sjogren-and-co`), and `stripTags: true` drops HTML tags first.']
327
337
  ];
328
338
  function builtinFilters(markdown, config) {
329
339
  const filters = /* @__PURE__ */ new Map();
@@ -340,10 +350,19 @@ function builtinFilters(markdown, config) {
340
350
  filters.set("navTree", (...args) => treeOf(args[0], urlArg(args)));
341
351
  filters.set("navPager", (...args) => pagerOf(args[0], urlArg(args)));
342
352
  filters.set("navBreadcrumbs", (...args) => breadcrumbsOf(args[0], urlArg(args)));
343
- filters.set("pagesTree", (...args) => fromPages(Array.isArray(args[0]) ? args[0] : []));
353
+ filters.set("pagesTree", (...args) => {
354
+ const option = args[1];
355
+ let root;
356
+ if (typeof option === "string") root = option;
357
+ else if (isPlainObject(option)) {
358
+ for (const key of Object.keys(option)) if (key !== "root") throw new BuildError(`pagesTree: unknown option \`${key}\` (options: root)`);
359
+ if (option.root !== void 0 && option.root !== null) root = String(option.root);
360
+ }
361
+ return fromPages(Array.isArray(args[0]) ? args[0] : [], { root });
362
+ });
344
363
  filters.set("slugify", (text, option) => {
345
364
  const [separator, apostrophes] = slugOptions(option);
346
- return slugWith(String(text), separator, apostrophes);
365
+ return slugWith(slugText(String(text), option), separator, apostrophes);
347
366
  });
348
367
  filters.set("readingTime", (text, wordsPerMinute) => {
349
368
  const wpm = typeof wordsPerMinute === "number" && wordsPerMinute > 0 ? wordsPerMinute : 200;
@@ -352,7 +371,7 @@ function builtinFilters(markdown, config) {
352
371
  });
353
372
  const TOC_MARKUP = ["id", "class", "sublistClass", "itemClass", "linkClass"];
354
373
  filters.set("toc", (list, option, last) => {
355
- const headings2 = Array.isArray(list) ? list : [];
374
+ const headings2 = Array.isArray(list) ? list : typeof list === "string" || list !== null && typeof list === "object" && typeof list.toString === "function" && !isPlainObject(list) ? headings(String(list)) : [];
356
375
  let [from, to, ordered] = [2, 3, false];
357
376
  const markup = {};
358
377
  if (isPlainObject(option)) {
@@ -2,7 +2,7 @@ import { createRequire as __ssqchCreateRequire } from "node:module";
2
2
  const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  slashes
5
- } from "./chunk-VJWQSYEG.js";
5
+ } from "./chunk-AIMEXBTK.js";
6
6
 
7
7
  // src/dirs.ts
8
8
  import fs from "node:fs";
@@ -0,0 +1,219 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ commandLine
5
+ } from "./chunk-HWW5NCVJ.js";
6
+ import {
7
+ compareRuns,
8
+ runsText
9
+ } from "./chunk-X2GAVYV2.js";
10
+ import {
11
+ compareText,
12
+ red
13
+ } from "./chunk-AIMEXBTK.js";
14
+
15
+ // src/commands/baseline.ts
16
+ import { spawnSync } from "node:child_process";
17
+ import fs from "node:fs";
18
+ import path from "node:path";
19
+ var FALLBACK_TIME = Date.UTC(2026, 0, 1) / 1e3;
20
+ function baselineTime(root, rev = "HEAD") {
21
+ const inGit = git(root, ["rev-parse", "--is-inside-work-tree"]).status === 0;
22
+ return inGit ? Number(git(root, ["log", "-1", "--format=%ct", rev]).stdout.toString().trim()) || FALLBACK_TIME : FALLBACK_TIME;
23
+ }
24
+ var BaselineError = class extends Error {
25
+ };
26
+ var git = (root, args) => spawnSync("git", ["-C", root, ...args], { encoding: "buffer", maxBuffer: 1 << 30 });
27
+ async function runBaseline(options) {
28
+ const say = (line) => {
29
+ if (!options.quiet) process.stderr.write(`${line}
30
+ `);
31
+ };
32
+ const root = path.resolve(options.root);
33
+ const work = path.join(root, ".cache", "ssqch", "baseline-copies");
34
+ const worktrees = [];
35
+ try {
36
+ if (!options.command.trim()) throw new BaselineError('give the old generator\'s build command: `ssqch baseline "npx @11ty/eleventy"`');
37
+ if (!Number.isInteger(options.runs) || options.runs < 1) throw new BaselineError(`--runs ${options.runs}: give a number of builds, 1 or more`);
38
+ if (path.isAbsolute(options.from) || options.from.split(/[\\/]/).includes("..")) throw new BaselineError(`--from ${options.from}: the folder the command writes, inside the site's folder (\`_site\`)`);
39
+ const inGit = git(root, ["rev-parse", "--is-inside-work-tree"]).status === 0;
40
+ if (options.commit !== void 0 && !inGit) throw new BaselineError(`--commit ${options.commit}: ${root} isn't in a git repository`);
41
+ const rev = options.commit ?? "HEAD";
42
+ const time = baselineTime(root, rev);
43
+ if (options.commit !== void 0 && git(root, ["rev-parse", "--verify", "--quiet", `${options.commit}^{commit}`]).status !== 0) throw new BaselineError(`--commit ${options.commit}: no such commit`);
44
+ const patch = options.patch === void 0 ? void 0 : path.resolve(options.patch);
45
+ if (patch !== void 0 && !fs.statSync(patch, { throwIfNoEntry: false })?.isFile()) throw new BaselineError(`--patch ${options.patch}: no such file (a patch, as \`git diff > fix.patch\` writes)`);
46
+ if (path.isAbsolute(options.to) || options.to.split(/[\\/]/).includes("..")) throw new BaselineError(`--to ${options.to}: a name inside the site's folder (\`ref\`, or \`.refs/jekyll\`)`);
47
+ let command = options.command;
48
+ let clock = "TZ=UTC, SOURCE_DATE_EPOCH and every file's time pinned; a generator that reads its own clock isn't, so pin it in its config if the builds vary";
49
+ const jekyll = /\bjekyll\s+build\b/.test(command);
50
+ if (jekyll) {
51
+ const pin = path.join(work, "..", "baseline-time.yml");
52
+ fs.mkdirSync(path.dirname(pin), { recursive: true });
53
+ fs.writeFileSync(pin, `# Written by ssqch baseline: Jekyll's site.time, pinned.
54
+ time: ${new Date(time * 1e3).toISOString().replace("T", " ").replace(/\.\d+Z$/, " +0000")}
55
+ `);
56
+ const given = /--config(=|\s+)(\S+)/.exec(command);
57
+ if (given) {
58
+ command = command.replace(given[0], `--config${given[1]}${given[2]},${JSON.stringify(pin)}`);
59
+ clock = `TZ=UTC, SOURCE_DATE_EPOCH, every file's time and Jekyll's site.time pinned (a time: of its own, after --config ${given[2]})`;
60
+ } else {
61
+ command = command.replace(/\bjekyll\s+build\b/, (m) => `${m} --config _config.yml,${JSON.stringify(pin)}`);
62
+ clock = "TZ=UTC, SOURCE_DATE_EPOCH, every file's time and Jekyll's site.time pinned (with --config _config.yml and a time: of its own)";
63
+ }
64
+ }
65
+ const copyInstalls = options.copyInstalls || /\bhugo\b/.test(options.command);
66
+ fs.rmSync(work, { recursive: true, force: true });
67
+ fs.mkdirSync(work, { recursive: true });
68
+ const names = [];
69
+ for (let run = 1; run <= options.runs; run++) {
70
+ const copy = path.join(work, `run-${run}`);
71
+ if (options.commit !== void 0) {
72
+ const added = git(root, ["worktree", "add", "--detach", "--force", copy, options.commit]);
73
+ if (added.status !== 0) throw new BaselineError(`couldn't check out ${options.commit}: ${added.stderr.toString().trim()}`);
74
+ worktrees.push(copy);
75
+ } else {
76
+ const untracked = copyWorkingTree(root, copy, inGit, [options.from, ".cache", "node_modules"], options.to);
77
+ if (run === 1 && untracked.length) {
78
+ const folders = [...new Set(untracked.map((rel) => rel.includes("/") ? `${rel.slice(0, rel.indexOf("/"))}/` : rel))].sort(compareText);
79
+ process.stderr.write(`warn: ${untracked.length === 1 ? "1 file git doesn't track goes" : `${untracked.length} files git doesn't track go`} into the copies too (${folders.slice(0, 4).join(", ")}${folders.length > 4 ? ", ..." : ""}), as the old generator reads the working tree; a fresh checkout wouldn't have ${untracked.length === 1 ? "it" : "them"}. Add ${untracked.length === 1 ? "it" : "them"} to git or .gitignore, or build a commit (\`--commit HEAD\`)
80
+ `);
81
+ }
82
+ }
83
+ if (patch !== void 0) {
84
+ const applied = spawnSync("git", ["apply", "--whitespace=nowarn", patch], { cwd: copy, encoding: "utf8", env: { ...process.env, GIT_CEILING_DIRECTORIES: path.dirname(copy) } });
85
+ if (applied.status !== 0) throw new BaselineError(`--patch ${options.patch}: didn't apply to ${options.commit ?? "the working tree"}: ${(applied.stderr || applied.error?.message || "").trim()}`);
86
+ }
87
+ pinTimes(copy, time);
88
+ for (const rel of installs(root, options.link)) {
89
+ const from = path.join(root, ...rel.split("/"));
90
+ const to = path.join(copy, ...rel.split("/"));
91
+ if (!fs.existsSync(from) || fs.existsSync(to)) continue;
92
+ fs.mkdirSync(path.dirname(to), { recursive: true });
93
+ const dir = fs.statSync(from).isDirectory();
94
+ if (dir && copyInstalls) fs.cpSync(from, to, { recursive: true, verbatimSymlinks: true, mode: fs.constants.COPYFILE_FICLONE });
95
+ else if (dir) fs.symlinkSync(from, to, process.platform === "win32" ? "junction" : "dir");
96
+ else fs.copyFileSync(from, to);
97
+ }
98
+ say(`Building ${run} of ${options.runs}: ${command}`);
99
+ const { file, args, options: spawnOptions } = commandLine(command, copy, { TZ: "UTC", SOURCE_DATE_EPOCH: String(time) });
100
+ const result = spawnSync(file, args, { ...spawnOptions, stdio: ["ignore", options.quiet ? "ignore" : process.stderr, options.quiet ? "ignore" : process.stderr] });
101
+ if (result.error) throw new BaselineError(`couldn't run \`${options.command}\`: ${result.error.message}`);
102
+ if (result.status !== 0) throw new BaselineError(`\`${options.command}\` failed in build ${run} (exit code ${result.status ?? result.signal}); its output is above`);
103
+ const built = path.join(copy, options.from);
104
+ if (!fs.statSync(built, { throwIfNoEntry: false })?.isDirectory()) throw new BaselineError(`\`${options.command}\` wrote no ${options.from}/ in build ${run}: give the folder it writes with --from (Eleventy and Jekyll write _site, Hugo public, Astro dist)`);
105
+ if (run === 1 && jekyll) {
106
+ const home = path.join(built, "index.html");
107
+ const text = fs.statSync(home, { throwIfNoEntry: false })?.isFile() ? fs.readFileSync(home, "utf8") : "";
108
+ if (text.includes("github.com/pages/")) process.stderr.write("warn: Jekyll's build has `https://github.com/pages/...` URLs: jekyll-github-metadata couldn't tell which repository this is, so `site.url` is wrong on every page. Give it the repository (`PAGES_REPO_NWO=owner/repo`, and `JEKYLL_GITHUB_TOKEN` if it asks), or `url:` in a config of your own\n");
109
+ }
110
+ const name = `${options.to}-${run}`;
111
+ const target = path.join(root, ...name.split("/"));
112
+ fs.rmSync(target, { recursive: true, force: true });
113
+ fs.mkdirSync(path.dirname(target), { recursive: true });
114
+ fs.renameSync(built, target);
115
+ names.push(name);
116
+ }
117
+ for (let run = options.runs + 1; fs.existsSync(path.join(root, `${options.to}-${run}`)); run++) fs.rmSync(path.join(root, `${options.to}-${run}`), { recursive: true, force: true });
118
+ const shown = names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
119
+ say(`Base camp is set: ${shown}, built from ${options.commit ?? "the working tree"}${options.patch !== void 0 ? ` and ${options.patch}` : ""} with ${clock}.`);
120
+ let code = 0;
121
+ let reference = names[0];
122
+ const common = path.join(root, `${options.to}-common`);
123
+ fs.rmSync(common, { recursive: true, force: true });
124
+ if (names.length > 1) {
125
+ const report = await compareRuns(names.map((n) => path.join(root, n)), { exact: false, ignore: [], only: void 0, lines: 10 });
126
+ process.stdout.write(runsText({ ...report, runs: names }, 10, process.stdout.isTTY === true));
127
+ code = report.varies.length ? 1 : 0;
128
+ reference = names[report.typical];
129
+ if (report.varies.length && names.length >= 3) {
130
+ fs.cpSync(path.join(root, names[report.typical]), common, { recursive: true, verbatimSymlinks: true });
131
+ for (const v of report.varies) {
132
+ const [most] = v.versions;
133
+ const own = v.files[report.typical];
134
+ if (own !== void 0) fs.rmSync(path.join(common, own), { force: true });
135
+ if (most.missing) continue;
136
+ const from = v.files[most.runs[0]];
137
+ fs.mkdirSync(path.dirname(path.join(common, from)), { recursive: true });
138
+ fs.copyFileSync(path.join(root, names[most.runs[0]], from), path.join(common, from));
139
+ }
140
+ reference = `${options.to}-common`;
141
+ say(`Wrote ${reference}: each file's most common version of the ${names.length} builds, to compare ssqch's with.`);
142
+ }
143
+ }
144
+ process.stdout.write(`
145
+ Next: build with ssqch into an empty folder, then \`ssqch diff ${reference} <ssqch's output>\`${code ? ", with an --ignore for what varies above" : ""}, and fix the biggest group first. The whole loop: \`ssqch docs "moving a site with an agent"\`.
146
+ `);
147
+ return code;
148
+ } catch (e) {
149
+ process.stderr.write(`${red("error:")} ${e instanceof BaselineError ? e.message : e instanceof Error ? e.message : String(e)}
150
+ `);
151
+ return 2;
152
+ } finally {
153
+ for (const tree of worktrees) git(root, ["worktree", "remove", "--force", tree]);
154
+ fs.rmSync(work, { recursive: true, force: true });
155
+ if (worktrees.length) git(root, ["worktree", "prune"]);
156
+ }
157
+ }
158
+ function installs(root, more) {
159
+ const found = ["node_modules", ".bundle", "vendor/bundle", ".venv"];
160
+ try {
161
+ const config = fs.readFileSync(path.join(root, ".bundle", "config"), "utf8");
162
+ const gems = /^BUNDLE_PATH:\s*["']?([^"'\n]+?)["']?\s*$/m.exec(config)?.[1];
163
+ if (gems && !path.isAbsolute(gems) && !gems.startsWith("~")) found.push(gems.replace(/^\.\//, "").replace(/\/+$/, ""));
164
+ } catch {
165
+ }
166
+ for (const rel of more) {
167
+ if (path.isAbsolute(rel) || rel.split(/[\\/]/).includes("..")) throw new BaselineError(`--link ${rel}: a folder inside the site's folder (\`vendor/bundle\`)`);
168
+ found.push(rel.replaceAll("\\", "/").replace(/\/+$/, ""));
169
+ }
170
+ return [...new Set(found)];
171
+ }
172
+ function copyWorkingTree(root, copy, inGit, skip, to) {
173
+ const build = new RegExp(`^${to.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-\\d+(?:/|$)`);
174
+ const skipped = (rel) => rel === ".git" || rel.startsWith(".git/") || build.test(rel) || skip.some((s) => rel === s || rel.startsWith(`${s}/`));
175
+ let files;
176
+ if (inGit) {
177
+ const listed = git(root, ["ls-files", "-z", "--cached", "--others", "--exclude-standard"]);
178
+ if (listed.status !== 0) throw new BaselineError(`couldn't list the site's files: ${listed.stderr.toString().trim()}`);
179
+ files = listed.stdout.toString().split("\0").filter(Boolean);
180
+ } else {
181
+ files = [];
182
+ const walk = (rel) => {
183
+ for (const entry of fs.readdirSync(path.join(root, rel), { withFileTypes: true }).sort((a, b) => compareText(a.name, b.name))) {
184
+ const child = rel ? `${rel}/${entry.name}` : entry.name;
185
+ if (skipped(child)) continue;
186
+ if (entry.isDirectory()) walk(child);
187
+ else if (entry.isFile()) files.push(child);
188
+ }
189
+ };
190
+ walk("");
191
+ }
192
+ let untracked = [];
193
+ if (inGit) {
194
+ const others = git(root, ["ls-files", "-z", "--others", "--exclude-standard"]);
195
+ if (others.status === 0) untracked = others.stdout.toString().split("\0").filter((rel) => rel && !skipped(rel));
196
+ }
197
+ for (const rel of files) {
198
+ if (skipped(rel)) continue;
199
+ const from = path.join(root, ...rel.split("/"));
200
+ if (!fs.statSync(from, { throwIfNoEntry: false })?.isFile()) continue;
201
+ const to2 = path.join(copy, ...rel.split("/"));
202
+ fs.mkdirSync(path.dirname(to2), { recursive: true });
203
+ fs.copyFileSync(from, to2);
204
+ }
205
+ return untracked;
206
+ }
207
+ function pinTimes(dir, time) {
208
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
209
+ if (entry.name === ".git" || entry.name === "node_modules") continue;
210
+ const full = path.join(dir, entry.name);
211
+ if (entry.isDirectory()) pinTimes(full, time);
212
+ else if (entry.isFile()) fs.utimesSync(full, time, time);
213
+ }
214
+ }
215
+
216
+ export {
217
+ baselineTime,
218
+ runBaseline
219
+ };
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-CMUWRPSQ.js";
6
6
  import {
7
7
  bail
8
- } from "./chunk-BGCBSQ4A.js";
8
+ } from "./chunk-AIMEXBTK.js";
9
9
 
10
10
  // src/glob.ts
11
11
  var stripDot = (p) => p.replace(/^(\.\/)+/, "");
@@ -2,7 +2,7 @@ import { createRequire as __ssqchCreateRequire } from "node:module";
2
2
  const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  isDir
5
- } from "./chunk-VJWQSYEG.js";
5
+ } from "./chunk-AIMEXBTK.js";
6
6
 
7
7
  // src/command-line.ts
8
8
  import os from "node:os";
@@ -2,7 +2,7 @@ import { createRequire as __ssqchCreateRequire } from "node:module";
2
2
  const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  red
5
- } from "./chunk-BGCBSQ4A.js";
5
+ } from "./chunk-AIMEXBTK.js";
6
6
 
7
7
  // src/serve/builder.ts
8
8
  import { fork } from "node:child_process";
@@ -1,11 +1,9 @@
1
1
  import { createRequire as __ssqchCreateRequire } from "node:module";
2
2
  const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
- BuildError
5
- } from "./chunk-BGCBSQ4A.js";
6
- import {
4
+ BuildError,
7
5
  realPath
8
- } from "./chunk-VJWQSYEG.js";
6
+ } from "./chunk-AIMEXBTK.js";
9
7
 
10
8
  // src/modules.ts
11
9
  import fs from "node:fs";