ssqch 0.7.0 → 0.8.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 (153) hide show
  1. package/README.md +6 -4
  2. package/bin/ssqch.js +14 -48
  3. package/bundled/README.md +1247 -0
  4. package/bundled/completions/bash +840 -0
  5. package/bundled/completions/elvish +286 -0
  6. package/bundled/completions/fish +182 -0
  7. package/bundled/completions/powershell +318 -0
  8. package/bundled/completions/zsh +510 -0
  9. package/bundled/ssqch.d.ts +532 -0
  10. package/bundled/starter/engines/index.edge +11 -0
  11. package/bundled/starter/engines/index.ejs +11 -0
  12. package/bundled/starter/engines/index.hbs +11 -0
  13. package/bundled/starter/engines/index.liquid +11 -0
  14. package/bundled/starter/engines/layout.edge +35 -0
  15. package/bundled/starter/engines/layout.ejs +35 -0
  16. package/bundled/starter/engines/layout.hbs +35 -0
  17. package/bundled/starter/engines/layout.liquid +35 -0
  18. package/bundled/starter/gitignore +3 -0
  19. package/bundled/starter/jsconfig.json +11 -0
  20. package/bundled/starter/src/404.md +8 -0
  21. package/bundled/starter/src/_blueprints/posts.md +5 -0
  22. package/bundled/starter/src/_data/site.json +4 -0
  23. package/bundled/starter/src/_includes/layout.jinja +35 -0
  24. package/bundled/starter/src/index.jinja +11 -0
  25. package/bundled/starter/src/posts/i-know-what-i-saw.md +11 -0
  26. package/bundled/starter/src/posts/posts.json +4 -0
  27. package/bundled/starter/src/posts/raiders-of-the-lost-path.md +27 -0
  28. package/bundled/starter/src/posts/the-cache-of-the-wild.md +26 -0
  29. package/bundled/starter/src/posts/the-stump-has-moved.md +15 -0
  30. package/bundled/starter/src/posts/upon-further-review-a-stump.md +18 -0
  31. package/bundled/starter/ssqch.config.js +29 -0
  32. package/bundled/starter-docs/engines/edge/base.edge +41 -0
  33. package/bundled/starter-docs/engines/edge/containers/details.edge +5 -0
  34. package/bundled/starter-docs/engines/edge/containers/tab.edge +4 -0
  35. package/bundled/starter-docs/engines/edge/containers/tabs.edge +5 -0
  36. package/bundled/starter-docs/engines/edge/doc.edge +59 -0
  37. package/bundled/starter-docs/engines/edge/hooks/heading.edge +2 -0
  38. package/bundled/starter-docs/engines/ejs/base.ejs +41 -0
  39. package/bundled/starter-docs/engines/ejs/containers/details.ejs +5 -0
  40. package/bundled/starter-docs/engines/ejs/containers/tab.ejs +4 -0
  41. package/bundled/starter-docs/engines/ejs/containers/tabs.ejs +5 -0
  42. package/bundled/starter-docs/engines/ejs/doc.ejs +59 -0
  43. package/bundled/starter-docs/engines/ejs/hooks/heading.ejs +2 -0
  44. package/bundled/starter-docs/engines/hbs/base.hbs +41 -0
  45. package/bundled/starter-docs/engines/hbs/containers/details.hbs +5 -0
  46. package/bundled/starter-docs/engines/hbs/containers/tab.hbs +4 -0
  47. package/bundled/starter-docs/engines/hbs/containers/tabs.hbs +5 -0
  48. package/bundled/starter-docs/engines/hbs/doc.hbs +58 -0
  49. package/bundled/starter-docs/engines/hbs/hooks/heading.hbs +2 -0
  50. package/bundled/starter-docs/engines/liquid/base.liquid +41 -0
  51. package/bundled/starter-docs/engines/liquid/containers/details.liquid +5 -0
  52. package/bundled/starter-docs/engines/liquid/containers/tab.liquid +4 -0
  53. package/bundled/starter-docs/engines/liquid/containers/tabs.liquid +5 -0
  54. package/bundled/starter-docs/engines/liquid/doc.liquid +60 -0
  55. package/bundled/starter-docs/engines/liquid/hooks/heading.liquid +2 -0
  56. package/bundled/starter-docs/gitignore +4 -0
  57. package/bundled/starter-docs/src/404.md +12 -0
  58. package/bundled/starter-docs/src/_blueprints/docs.md +5 -0
  59. package/bundled/starter-docs/src/_data/nav.yml +10 -0
  60. package/bundled/starter-docs/src/_data/site.json +5 -0
  61. package/bundled/starter-docs/src/_includes/base.jinja +41 -0
  62. package/bundled/starter-docs/src/_includes/containers/details.jinja +5 -0
  63. package/bundled/starter-docs/src/_includes/containers/tab.jinja +4 -0
  64. package/bundled/starter-docs/src/_includes/containers/tabs.jinja +5 -0
  65. package/bundled/starter-docs/src/_includes/doc.jinja +59 -0
  66. package/bundled/starter-docs/src/_includes/hooks/heading.jinja +2 -0
  67. package/bundled/starter-docs/src/assets/docs.css +257 -0
  68. package/bundled/starter-docs/src/assets/docs.js +67 -0
  69. package/bundled/starter-docs/src/docs/docs.json +1 -0
  70. package/bundled/starter-docs/src/docs/guides/deploying.md +77 -0
  71. package/bundled/starter-docs/src/docs/guides/writing.md +65 -0
  72. package/bundled/starter-docs/src/docs/index.md +29 -0
  73. package/bundled/starter-docs/src/docs/install.md +42 -0
  74. package/bundled/starter-docs/src/index.md +13 -0
  75. package/bundled/starter-docs/ssqch.config.js +40 -0
  76. package/bundled/trailheads/from-component-frameworks.md +116 -0
  77. package/bundled/trailheads/from-docusaurus.md +55 -0
  78. package/bundled/trailheads/from-eleventy.md +140 -0
  79. package/bundled/trailheads/from-hexo.md +92 -0
  80. package/bundled/trailheads/from-mkdocs.md +45 -0
  81. package/bundled/trailheads/from-zola.md +71 -0
  82. package/lib/assets.js +235 -3
  83. package/lib/chunk-37KSIVNY.js +29 -0
  84. package/lib/chunk-3GYLOC6Y.js +1017 -0
  85. package/lib/chunk-3NYSSA2C.js +22 -0
  86. package/lib/chunk-3PHCFZEU.js +209 -0
  87. package/lib/chunk-4Q6WMTER.js +32 -0
  88. package/lib/chunk-6XYSFG6V.js +4423 -0
  89. package/lib/chunk-6XYSFG6V.js.LEGAL.txt +41 -0
  90. package/lib/chunk-AD3HAW3W.js +10 -0
  91. package/lib/chunk-AMBFWPZ4.js +118 -0
  92. package/lib/chunk-BOBPVAX2.js +37088 -0
  93. package/lib/chunk-BOBPVAX2.js.LEGAL.txt +27 -0
  94. package/lib/chunk-BRK4MXXO.js +565 -0
  95. package/lib/chunk-C35KIPAR.js +247 -0
  96. package/lib/chunk-CDEPYU7W.js +25 -0
  97. package/lib/chunk-CMUWRPSQ.js +113 -0
  98. package/lib/chunk-DDV6JEC2.js +46 -0
  99. package/lib/chunk-DHHQKW4F.js +71 -0
  100. package/lib/chunk-EIT4ZDT4.js +1485 -0
  101. package/lib/chunk-EZZUUPI4.js +20 -0
  102. package/lib/chunk-F65YUXZ7.js +334 -0
  103. package/lib/chunk-FVZ5JBRI.js +115 -0
  104. package/lib/chunk-FYGE634X.js +44 -0
  105. package/lib/chunk-GOE4ZSAB.js +75 -0
  106. package/lib/chunk-GSKVRAHF.js +44 -0
  107. package/lib/chunk-HR2RU2LY.js +999 -0
  108. package/lib/chunk-HXCLCXRT.js +20 -0
  109. package/lib/chunk-I3PS26CI.js +48 -0
  110. package/lib/chunk-IAFM5ITE.js +11 -0
  111. package/lib/chunk-IRHRK7XB.js +54 -0
  112. package/lib/chunk-JRT7TQQP.js +57 -0
  113. package/lib/chunk-JSPSMIJ2.js +217 -0
  114. package/lib/chunk-KBGE5MCY.js +175 -0
  115. package/lib/chunk-N5QTGQ5N.js +207 -0
  116. package/lib/chunk-NKXEPHRZ.js +136 -0
  117. package/lib/chunk-NUKCUDC4.js +146 -0
  118. package/lib/chunk-RI2L3VGO.js +376 -0
  119. package/lib/chunk-TDGBQNGW.js +251 -0
  120. package/lib/chunk-TN6EEDX2.js +3935 -0
  121. package/lib/chunk-TWCVHOKO.js +1229 -0
  122. package/lib/chunk-UGEGUUBT.js +29 -0
  123. package/lib/chunk-UU43WIZG.js +29 -0
  124. package/lib/chunk-VJWQSYEG.js +119 -0
  125. package/lib/chunk-VVPZ5PDP.js +160 -0
  126. package/lib/chunk-WMOVCQO6.js +1287 -0
  127. package/lib/chunk-WP3RPVUM.js +211 -0
  128. package/lib/chunk-YSH2NMIE.js +502 -0
  129. package/lib/cli.js +540 -0
  130. package/lib/elements.js +180 -3
  131. package/lib/image.js +27 -3
  132. package/lib/links.js +464 -3
  133. package/lib/minify.js +69 -3
  134. package/lib/redirects.js +152 -3
  135. package/lib/rss.js +139 -3
  136. package/lib/sass.js +221 -3
  137. package/lib/sitemap.js +88 -3
  138. package/lib/ssqch.js +28 -0
  139. package/package.json +83 -80
  140. package/src/serve/live.js +174 -0
  141. package/src/serve/not-found.html +31 -0
  142. package/types/globals.d.ts +3 -2
  143. package/types/image.d.ts +7 -3
  144. package/types/index.d.ts +18 -5
  145. package/types/links.d.ts +1 -1
  146. package/types/minify.d.ts +1 -1
  147. package/types/rss.d.ts +1 -1
  148. package/types/sass.d.ts +1 -1
  149. package/wasm/markdown.wasm +0 -0
  150. package/wasm/minify.wasm +0 -0
  151. package/wasm/sass.wasm +0 -0
  152. package/lib/index.js +0 -3
  153. package/platforms.json +0 -6
package/lib/elements.js CHANGED
@@ -1,3 +1,180 @@
1
- // ssqch/elements is built into the ssqch binary, which runs ssqch.config.js and data files itself.
2
- // This file is here so editors and linters can find the module (its types are in ../types).
3
- throw new Error("ssqch/elements only works in files ssqch runs (ssqch.config.js, data files): build with ssqch, not node");
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ Options
5
+ } from "./chunk-JRT7TQQP.js";
6
+ import {
7
+ BUILTINS,
8
+ debugString,
9
+ rewriteHtml,
10
+ withBase
11
+ } from "./chunk-TN6EEDX2.js";
12
+ import "./chunk-IRHRK7XB.js";
13
+ import {
14
+ count
15
+ } from "./chunk-NKXEPHRZ.js";
16
+ import "./chunk-AD3HAW3W.js";
17
+ import "./chunk-DDV6JEC2.js";
18
+ import "./chunk-EIT4ZDT4.js";
19
+ import "./chunk-FVZ5JBRI.js";
20
+ import "./chunk-TDGBQNGW.js";
21
+ import "./chunk-UU43WIZG.js";
22
+ import "./chunk-C35KIPAR.js";
23
+ import "./chunk-CMUWRPSQ.js";
24
+ import {
25
+ bail,
26
+ context
27
+ } from "./chunk-6XYSFG6V.js";
28
+ import {
29
+ compareText,
30
+ displayPath,
31
+ isDir,
32
+ isFile,
33
+ slashes
34
+ } from "./chunk-VJWQSYEG.js";
35
+ import "./chunk-I3PS26CI.js";
36
+
37
+ // src/modules/elements.ts
38
+ import fs from "node:fs";
39
+ import path from "node:path";
40
+ function elementsPlugin(options = {}) {
41
+ return { name: "ssqch/elements", builtin: "ssqch/elements", options };
42
+ }
43
+ var LOADS = ["eager", "idle", "visible"];
44
+ var parseLoad = (s) => LOADS.find((l) => l === s);
45
+ function isElementName(name) {
46
+ return name.includes("-") && /^[a-z][a-z0-9_.-]*$/.test(name);
47
+ }
48
+ function scan(root, dir, url) {
49
+ if (!isDir(dir)) bail(`the elements folder ${displayPath(root, dir)} doesn't exist; create it, or set \`dir\``);
50
+ const out = /* @__PURE__ */ new Map();
51
+ const sources = /* @__PURE__ */ new Map();
52
+ const walk = (folder) => {
53
+ const entries = fs.readdirSync(folder, { withFileTypes: true }).sort((a, b) => compareText(a.name, b.name));
54
+ for (const entry of entries) {
55
+ const file = path.join(folder, entry.name);
56
+ if (entry.isDirectory()) {
57
+ walk(file);
58
+ continue;
59
+ }
60
+ const ext = path.extname(entry.name);
61
+ if (!entry.isFile() || ext !== ".js" && ext !== ".mjs") continue;
62
+ const stem = path.basename(entry.name, ext);
63
+ if (!isElementName(stem)) continue;
64
+ const rel = slashes(path.relative(dir, file));
65
+ const other = sources.get(stem);
66
+ if (other !== void 0) bail(`${other} and ${rel} both define <${stem}>; keep one`);
67
+ sources.set(stem, rel);
68
+ const css = path.join(folder, `${stem}.css`);
69
+ out.set(stem, { script: url + rel, style: isFile(css) ? url + slashes(path.relative(dir, css)) : void 0 });
70
+ }
71
+ };
72
+ walk(dir);
73
+ return out;
74
+ }
75
+ function findUsed(html, known, fallback) {
76
+ const used = /* @__PURE__ */ new Map();
77
+ let problem;
78
+ const out = rewriteHtml(html, {
79
+ tag(el) {
80
+ const tag = el.name;
81
+ if (!known.has(tag)) return;
82
+ let load = fallback;
83
+ const value = el.get("ssqch:load");
84
+ if (value !== void 0) {
85
+ el.remove("ssqch:load");
86
+ const parsed = parseLoad(value.trim());
87
+ if (parsed === void 0) problem = `<${tag} ssqch:load="${value}">: use eager, idle or visible`;
88
+ else load = parsed;
89
+ }
90
+ const slot = used.get(tag);
91
+ used.set(tag, slot === void 0 || LOADS.indexOf(load) < LOADS.indexOf(slot) ? load : slot);
92
+ }
93
+ });
94
+ if (problem !== void 0) bail(problem);
95
+ return { html: out, used };
96
+ }
97
+ var jsString = (s) => `"${s.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("<", "\\u003c")}"`;
98
+ function tags(used, known, base) {
99
+ let head = "";
100
+ let body = "";
101
+ const lazy = [];
102
+ for (const [tag, load] of [...used].sort((a, b) => compareText(a[0], b[0]))) {
103
+ const element = known.get(tag);
104
+ if (element.style !== void 0) head += `<link rel="stylesheet" href="${element.style}">
105
+ `;
106
+ if (load === "eager") body += `<script type="module" src="${element.script}"></script>
107
+ `;
108
+ else lazy.push(`[${jsString(tag)},${jsString(withBase(base, element.script))},${jsString(load)}]`);
109
+ }
110
+ if (lazy.length) {
111
+ body += `<script type="module">const idle=window.requestIdleCallback||((f)=>setTimeout(f,200));for(const[tag,src,when]of[${lazy.join(",")}]){if(when==="idle"){idle(()=>import(src));continue}const seen=new IntersectionObserver((entries)=>{if(entries.some((e)=>e.isIntersecting)){seen.disconnect();import(src)}},{rootMargin:"200px"});document.querySelectorAll(tag).forEach((el)=>seen.observe(el))}</script>
112
+ `;
113
+ }
114
+ return [head, body];
115
+ }
116
+ var asciiLower = (s) => s.replace(/[A-Z]+/g, (m) => m.toLowerCase());
117
+ function insertBefore(html, close, addition, last) {
118
+ if (addition === "") return html;
119
+ const lower = asciiLower(html);
120
+ const at = last ? lower.lastIndexOf(close) : lower.indexOf(close);
121
+ return at === -1 ? html + addition : html.slice(0, at) + addition + html.slice(at);
122
+ }
123
+ BUILTINS.set("ssqch/elements", (config, given) => {
124
+ const o = new Options(given, ["dir", "url", "load"]);
125
+ const dirOption = o.string("dir");
126
+ let url = o.string("url") ?? "/elements/";
127
+ const loadOption = o.string("load");
128
+ let fallback = "eager";
129
+ if (loadOption !== void 0) {
130
+ const parsed = parseLoad(loadOption);
131
+ if (parsed === void 0) bail(`load must be "eager", "idle" or "visible", not ${debugString(loadOption)}`);
132
+ fallback = parsed;
133
+ }
134
+ if (!url.startsWith("/") || url.includes("..")) bail(`url must be a URL path starting with /, like "/elements/" (got ${debugString(url)})`);
135
+ if (!url.endsWith("/")) url += "/";
136
+ const dir = dirOption ?? path.join(config.input, "elements");
137
+ config.passthrough.push({ from: dir, to: url.replace(/^\/+|\/+$/g, "") });
138
+ config.watch.push(dir);
139
+ let known = /* @__PURE__ */ new Map();
140
+ let pages = 0;
141
+ const usedNames = /* @__PURE__ */ new Set();
142
+ config.beforeBuild.push({
143
+ label: "",
144
+ fn: () => {
145
+ try {
146
+ known = scan(config.root, path.resolve(config.root, dir), url);
147
+ } catch (e) {
148
+ throw context(e, "elements");
149
+ }
150
+ pages = 0;
151
+ usedNames.clear();
152
+ }
153
+ });
154
+ config.htmlTransforms.push(["elements", (html, page) => {
155
+ if (!page.outputPath.endsWith(".html")) return html;
156
+ let any = false;
157
+ for (const tag of known.keys()) if (html.includes(`<${tag}`)) {
158
+ any = true;
159
+ break;
160
+ }
161
+ if (!any) return html;
162
+ const { html: found, used } = findUsed(html, known, fallback);
163
+ if (used.size === 0) return html;
164
+ const [head, body] = tags(used, known, config.base);
165
+ let out = found;
166
+ if (asciiLower(out).includes("</head>")) {
167
+ out = insertBefore(out, "</head>", head, false);
168
+ out = insertBefore(out, "</body>", body, true);
169
+ } else {
170
+ out = insertBefore(out, "</body>", head + body, true);
171
+ }
172
+ pages++;
173
+ for (const tag of used.keys()) usedNames.add(tag);
174
+ return out;
175
+ }]);
176
+ config.summaries.push(["Elements", () => `${known.size} defined, ${usedNames.size} used on ${count(pages)} page${pages === 1 ? "" : "s"}`]);
177
+ });
178
+ export {
179
+ elementsPlugin
180
+ };
package/lib/image.js CHANGED
@@ -1,3 +1,27 @@
1
- // ssqch/image is built into the ssqch binary, which runs ssqch.config.js and data files itself.
2
- // This file is here so editors and linters can find the module (its types are in ../types).
3
- throw new Error("ssqch/image only works in files ssqch runs (ssqch.config.js, data files): build with ssqch, not node");
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ image,
5
+ imagePlugin,
6
+ imageUrl
7
+ } from "./chunk-NUKCUDC4.js";
8
+ import "./chunk-JRT7TQQP.js";
9
+ import "./chunk-TN6EEDX2.js";
10
+ import "./chunk-IRHRK7XB.js";
11
+ import "./chunk-NKXEPHRZ.js";
12
+ import "./chunk-AD3HAW3W.js";
13
+ import "./chunk-DDV6JEC2.js";
14
+ import "./chunk-EIT4ZDT4.js";
15
+ import "./chunk-FVZ5JBRI.js";
16
+ import "./chunk-TDGBQNGW.js";
17
+ import "./chunk-UU43WIZG.js";
18
+ import "./chunk-C35KIPAR.js";
19
+ import "./chunk-CMUWRPSQ.js";
20
+ import "./chunk-6XYSFG6V.js";
21
+ import "./chunk-VJWQSYEG.js";
22
+ import "./chunk-I3PS26CI.js";
23
+ export {
24
+ image,
25
+ imagePlugin,
26
+ imageUrl
27
+ };
package/lib/links.js CHANGED
@@ -1,3 +1,464 @@
1
- // ssqch/links is built into the ssqch binary, which runs ssqch.config.js and data files itself.
2
- // This file is here so editors and linters can find the module (its types are in ../types).
3
- throw new Error("ssqch/links only works in files ssqch runs (ssqch.config.js, data files): build with ssqch, not node");
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ Options
5
+ } from "./chunk-JRT7TQQP.js";
6
+ import {
7
+ BUILTINS,
8
+ rewriteHtml
9
+ } from "./chunk-TN6EEDX2.js";
10
+ import "./chunk-IRHRK7XB.js";
11
+ import {
12
+ count
13
+ } from "./chunk-NKXEPHRZ.js";
14
+ import "./chunk-AD3HAW3W.js";
15
+ import {
16
+ dirsOf
17
+ } from "./chunk-DDV6JEC2.js";
18
+ import "./chunk-EIT4ZDT4.js";
19
+ import {
20
+ closest,
21
+ closestPathFinder
22
+ } from "./chunk-FVZ5JBRI.js";
23
+ import "./chunk-TDGBQNGW.js";
24
+ import {
25
+ TRAIL_GOES_COLD
26
+ } from "./chunk-UU43WIZG.js";
27
+ import "./chunk-C35KIPAR.js";
28
+ import "./chunk-CMUWRPSQ.js";
29
+ import {
30
+ Diagnostics,
31
+ bail,
32
+ error,
33
+ isCapturing,
34
+ warn,
35
+ warning
36
+ } from "./chunk-6XYSFG6V.js";
37
+ import {
38
+ compareText
39
+ } from "./chunk-VJWQSYEG.js";
40
+ import "./chunk-I3PS26CI.js";
41
+
42
+ // src/modules/links.ts
43
+ import fs from "node:fs";
44
+ import path from "node:path";
45
+ function linksPlugin(options = {}) {
46
+ return { name: "ssqch/links", builtin: "ssqch/links", options };
47
+ }
48
+ var asciiLower = (s) => s.replace(/[A-Z]+/g, (m) => m.toLowerCase());
49
+ var SPACES = /\s+/;
50
+ var trim = (s) => s.trim();
51
+ var firstWord = (s) => s.trim().split(SPACES)[0] || void 0;
52
+ function metaIsUrl(given) {
53
+ const name = asciiLower(given);
54
+ if (name === "og:url" || name === "twitter:url" || name === "msapplication-tileimage" || name === "thumbnail") return true;
55
+ return ["og:image", "og:video", "og:audio", "twitter:image", "twitter:player"].some((p) => {
56
+ if (name === p) return true;
57
+ if (!name.startsWith(p)) return false;
58
+ const rest = name.slice(p.length);
59
+ return rest === ":url" || rest === ":secure_url" || rest === ":src";
60
+ });
61
+ }
62
+ function jsonUrls(value, out) {
63
+ if (typeof value === "string") {
64
+ if (value !== "" && !new RegExp("\\p{White_Space}", "u").test(value) && (value.startsWith("/") || value.startsWith("http://") || value.startsWith("https://"))) out.push(value);
65
+ } else if (Array.isArray(value)) {
66
+ for (const v of value) jsonUrls(v, out);
67
+ } else if (value !== null && typeof value === "object") {
68
+ for (const v of Object.values(value)) jsonUrls(v, out);
69
+ }
70
+ }
71
+ function srcsetUrls(srcset, out, keep) {
72
+ for (const candidate of srcset.split(",")) {
73
+ const url = firstWord(candidate);
74
+ if (url !== void 0) out.push(keep(url));
75
+ }
76
+ }
77
+ var XML_ATTR = /[\s<](?:href|src|poster)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
78
+ var XML_SRCSET = /[\s<](?:srcset|imagesrcset)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
79
+ var XML_TEXT = />\s*((?:https?:\/\/|\/)[^<>\s]*)\s*</g;
80
+ var asFound = (found) => found;
81
+ function scanXml(xml, keep = asFound) {
82
+ const unescaped = unescapeXml(xml);
83
+ const out = [];
84
+ for (const c of unescaped.matchAll(XML_ATTR)) out.push(keep(unescapeXml(c[1] ?? c[2] ?? "")));
85
+ for (const c of unescaped.matchAll(XML_SRCSET)) {
86
+ for (const candidate of (c[1] ?? c[2] ?? "").split(",")) {
87
+ const url = firstWord(candidate);
88
+ if (url !== void 0) out.push(keep(unescapeXml(url)));
89
+ }
90
+ }
91
+ for (const c of unescaped.matchAll(XML_TEXT)) out.push(keep(unescapeXml(c[1])));
92
+ return out;
93
+ }
94
+ var NAMED = { lt: "<", gt: ">", quot: '"', apos: "'", amp: "&" };
95
+ function unescapeXml(given) {
96
+ if (!given.includes("&") && !given.includes("<![CDATA[")) return given;
97
+ const s = given.replaceAll("<![CDATA[", "").replaceAll("]]>", "");
98
+ let out = "";
99
+ let rest = s;
100
+ for (let i = rest.indexOf("&"); i !== -1; i = rest.indexOf("&")) {
101
+ out += rest.slice(0, i);
102
+ const after = rest.slice(i + 1);
103
+ const end = after.indexOf(";");
104
+ let decoded;
105
+ if (end !== -1 && end <= 8) {
106
+ const name = after.slice(0, end);
107
+ if (Object.hasOwn(NAMED, name)) decoded = NAMED[name];
108
+ else {
109
+ const hex = /^#[xX]([0-9a-fA-F]+)$/.exec(name);
110
+ const dec = /^#([0-9]+)$/.exec(name);
111
+ const code = hex ? Number.parseInt(hex[1], 16) : dec ? Number.parseInt(dec[1], 10) : void 0;
112
+ if (code !== void 0 && code <= 1114111 && !(code >= 55296 && code <= 57343)) decoded = String.fromCodePoint(code);
113
+ }
114
+ }
115
+ if (decoded !== void 0) {
116
+ out += decoded;
117
+ rest = after.slice(end + 1);
118
+ } else {
119
+ out += "&";
120
+ rest = after;
121
+ }
122
+ }
123
+ return out + rest;
124
+ }
125
+ function scanHtml(html, keep = asFound) {
126
+ const found = { ids: /* @__PURE__ */ new Set(), links: [], siteLinks: [], sitePaths: [] };
127
+ rewriteHtml(html, {
128
+ tag(el) {
129
+ const id = el.get("id");
130
+ if (id !== void 0) found.ids.add(keep(id));
131
+ switch (el.name) {
132
+ case "a": {
133
+ const name = el.get("name");
134
+ if (name !== void 0) found.ids.add(keep(name));
135
+ const href = el.get("href");
136
+ if (href !== void 0) found.links.push(keep(href));
137
+ break;
138
+ }
139
+ case "area": {
140
+ const href = el.get("href");
141
+ if (href !== void 0) found.links.push(keep(href));
142
+ break;
143
+ }
144
+ case "link": {
145
+ const href = el.get("href");
146
+ if (href !== void 0) {
147
+ const rel = asciiLower(el.get("rel") ?? "");
148
+ if (!rel.trim().split(SPACES).some((r) => r === "preconnect" || r === "dns-prefetch")) found.links.push(keep(href));
149
+ }
150
+ const srcset = el.get("imagesrcset");
151
+ if (srcset !== void 0) srcsetUrls(srcset, found.links, keep);
152
+ break;
153
+ }
154
+ case "meta": {
155
+ const content = el.get("content");
156
+ if (content === void 0) break;
157
+ const name = el.get("property") ?? el.get("name") ?? el.get("itemprop") ?? "";
158
+ if (metaIsUrl(name)) found.siteLinks.push(keep(content));
159
+ break;
160
+ }
161
+ case "img":
162
+ case "source": {
163
+ const src = el.get("src");
164
+ if (src !== void 0) found.links.push(keep(src));
165
+ const srcset = el.get("srcset");
166
+ if (srcset !== void 0) srcsetUrls(srcset, found.links, keep);
167
+ break;
168
+ }
169
+ case "script":
170
+ case "iframe":
171
+ case "video":
172
+ case "audio":
173
+ case "track":
174
+ case "embed": {
175
+ const src = el.get("src");
176
+ if (src !== void 0) found.links.push(keep(src));
177
+ break;
178
+ }
179
+ }
180
+ },
181
+ rawText(tag, text) {
182
+ if (tag.name !== "script") return;
183
+ const type = tag.get("type") ?? "";
184
+ if ((tag.namespace === "html" ? asciiLower(type) : type) !== "application/ld+json") return;
185
+ let value;
186
+ try {
187
+ value = JSON.parse(text);
188
+ } catch {
189
+ return;
190
+ }
191
+ jsonUrls(value, found.sitePaths);
192
+ }
193
+ });
194
+ return found;
195
+ }
196
+ function originOf(given) {
197
+ const url = trim(given);
198
+ const at = url.indexOf("://");
199
+ if (at === -1) return void 0;
200
+ const scheme = asciiLower(url.slice(0, at));
201
+ if (scheme !== "http" && scheme !== "https") return void 0;
202
+ const rest = url.slice(at + 3);
203
+ const host = asciiLower(rest.split(/[/?#]/)[0]);
204
+ return host === "" ? void 0 : `${scheme}://${host}`;
205
+ }
206
+ function sitemapOrigin(output) {
207
+ let xml;
208
+ try {
209
+ xml = fs.readFileSync(path.join(output, "sitemap.xml"), "utf8");
210
+ } catch {
211
+ return void 0;
212
+ }
213
+ const open = xml.indexOf("<loc>");
214
+ if (open === -1) return void 0;
215
+ const start = open + 5;
216
+ const close = xml.indexOf("</loc>", start);
217
+ if (close === -1) return void 0;
218
+ return originOf(unescapeXml(trim(xml.slice(start, close))));
219
+ }
220
+ function stripOrigin(given, origin) {
221
+ const link = trim(given);
222
+ const host = origin.slice(origin.indexOf("://") + 3);
223
+ let rest;
224
+ for (const scheme of ["https://", "http://"]) {
225
+ if (asciiLower(link.slice(0, scheme.length)) === scheme) {
226
+ rest = link.slice(scheme.length);
227
+ break;
228
+ }
229
+ }
230
+ if (rest === void 0 || asciiLower(rest.slice(0, host.length)) !== host) return void 0;
231
+ const after = rest.slice(host.length);
232
+ if (after === "") return "/";
233
+ return after.startsWith("/") || after.startsWith("?") || after.startsWith("#") ? after : void 0;
234
+ }
235
+ function inSite(link, base) {
236
+ const trimmed = trim(link);
237
+ if (base === "" || !trimmed.startsWith("/") || trimmed.startsWith("//")) return link;
238
+ if (!trimmed.startsWith(base)) return void 0;
239
+ const rest = trimmed.slice(base.length);
240
+ if (rest === "") return "/";
241
+ return rest.startsWith("/") || rest.startsWith("#") || rest.startsWith("?") ? rest : void 0;
242
+ }
243
+ function urlOf(output, file) {
244
+ const inside = file.length > output.length && file.startsWith(output) && file[output.length] === path.sep;
245
+ const rel = (inside ? file.slice(output.length + 1) : path.relative(output, file)).split(path.sep).join("/");
246
+ const url = `/${rel}`;
247
+ return url.endsWith("index.html") ? url.slice(0, -"index.html".length) : url;
248
+ }
249
+ function hasId(ids, fragment) {
250
+ return ids.has(fragment) || ids.has(percentDecode(fragment));
251
+ }
252
+ function hasScheme(link) {
253
+ const i = link.indexOf(":");
254
+ return i !== -1 && /^[A-Za-z][A-Za-z0-9+.-]*$/.test(link.slice(0, i));
255
+ }
256
+ function resolve(pageUrl, given) {
257
+ const link = trim(given);
258
+ if (link === "" || link.startsWith("//") || hasScheme(link)) return void 0;
259
+ const hash = link.indexOf("#");
260
+ const rest = hash === -1 ? link : link.slice(0, hash);
261
+ const fragment = hash === -1 || hash === link.length - 1 ? void 0 : link.slice(hash + 1);
262
+ const query = rest.indexOf("?");
263
+ const target = query === -1 ? rest : rest.slice(0, query);
264
+ if (target === "") return fragment === void 0 ? void 0 : ["", fragment];
265
+ const joined = target.startsWith("/") ? target : pageUrl.slice(0, pageUrl.lastIndexOf("/") + 1) + target;
266
+ return [normalize(percentDecode(joined)), fragment];
267
+ }
268
+ function normalize(p) {
269
+ const parts = [];
270
+ for (const seg of p.split("/")) {
271
+ if (seg === "" || seg === ".") continue;
272
+ if (seg === "..") parts.pop();
273
+ else parts.push(seg);
274
+ }
275
+ const out = `/${parts.join("/")}`;
276
+ return p.endsWith("/") && out !== "/" ? `${out}/` : out;
277
+ }
278
+ function isFile(p) {
279
+ try {
280
+ return fs.statSync(p, { throwIfNoEntry: false })?.isFile() ?? false;
281
+ } catch {
282
+ return false;
283
+ }
284
+ }
285
+ function find(output, urlPath, written) {
286
+ const there = (p) => written.has(p) || isFile(p);
287
+ const rel = urlPath.replace(/^\/+/, "");
288
+ const base = path.join(output, rel);
289
+ if (urlPath.endsWith("/")) {
290
+ const index2 = path.join(base, "index.html");
291
+ return there(index2) ? index2 : void 0;
292
+ }
293
+ if (there(base)) return base;
294
+ const html = path.join(output, `${rel}.html`);
295
+ if (there(html)) return html;
296
+ const index = path.join(base, "index.html");
297
+ return there(index) ? index : void 0;
298
+ }
299
+ function redirectSources(output) {
300
+ let text;
301
+ try {
302
+ text = fs.readFileSync(path.join(output, "_redirects"), "utf8");
303
+ } catch {
304
+ return [];
305
+ }
306
+ const sources = [];
307
+ for (const line of text.split(/\r?\n/)) {
308
+ const l = trim(line);
309
+ if (l === "" || l.startsWith("#")) continue;
310
+ const from = firstWord(l);
311
+ if (from !== void 0 && from.startsWith("/")) sources.push(from);
312
+ }
313
+ return sources;
314
+ }
315
+ function redirected(sources, p) {
316
+ return sources.some((from) => from.endsWith("*") ? p.startsWith(from.slice(0, -1)) : from === p || from.replace(/\/+$/, "") === p.replace(/\/+$/, ""));
317
+ }
318
+ var HEX2 = /^[0-9a-fA-F]{2}$/;
319
+ function percentDecode(s) {
320
+ if (!s.includes("%")) return s;
321
+ const bytes = Buffer.from(s, "utf8");
322
+ const out = [];
323
+ for (let i = 0; i < bytes.length; i++) {
324
+ if (bytes[i] === 37 && i + 2 < bytes.length) {
325
+ const hex = bytes.toString("latin1", i + 1, i + 3);
326
+ if (HEX2.test(hex)) {
327
+ out.push(Number.parseInt(hex, 16));
328
+ i += 2;
329
+ continue;
330
+ }
331
+ }
332
+ out.push(bytes[i]);
333
+ }
334
+ return Buffer.from(out).toString("utf8");
335
+ }
336
+ async function check(config, output, written, options) {
337
+ const scans = [];
338
+ const kept = /* @__PURE__ */ new Map();
339
+ const keep = (found2) => {
340
+ let copy = kept.get(found2);
341
+ if (copy === void 0) {
342
+ copy = ` ${found2}`.slice(1);
343
+ kept.set(copy, copy);
344
+ }
345
+ return copy;
346
+ };
347
+ const pages = written.filter((file) => {
348
+ const ext = path.extname(file);
349
+ return ext === ".html" || ext === ".xml";
350
+ });
351
+ const reading = /* @__PURE__ */ new Map();
352
+ const AHEAD = 32;
353
+ for (let i = 0; i < pages.length; i++) {
354
+ for (let j = i; j < Math.min(i + AHEAD, pages.length); j++) if (!reading.has(j)) reading.set(j, fs.promises.readFile(pages[j], "utf8"));
355
+ const text = await reading.get(i);
356
+ reading.delete(i);
357
+ scans.push([pages[i], path.extname(pages[i]) === ".xml" ? { ids: /* @__PURE__ */ new Set(), links: [], siteLinks: scanXml(text, keep), sitePaths: [] } : scanHtml(text, keep)]);
358
+ }
359
+ kept.clear();
360
+ const origin = (options.url === void 0 ? void 0 : originOf(options.url)) ?? sitemapOrigin(output);
361
+ const ids = new Map(scans.map(([file, scan]) => [file, scan.ids]));
362
+ const writtenFiles = new Set(written);
363
+ const redirects = redirectSources(output);
364
+ const anchors = options.anchors ?? true;
365
+ let checked = 0;
366
+ const seen = /* @__PURE__ */ new Set();
367
+ const broken = [];
368
+ const found = /* @__PURE__ */ new Map();
369
+ const urls = scans.map(([file]) => urlOf(output, file));
370
+ let nearest;
371
+ const meant = /* @__PURE__ */ new Map();
372
+ const didYouMean = (name, mark) => name === void 0 ? "" : `; did you mean ${mark}${name}?`;
373
+ const reasonFor = (pageUrl, page, inside, ignoreFragment) => {
374
+ const resolved = resolve(pageUrl, inside);
375
+ if (resolved === void 0) return void 0;
376
+ const [targetPath, anchor] = resolved;
377
+ const fragment = ignoreFragment ? void 0 : anchor;
378
+ if (targetPath === "" && fragment === void 0) return void 0;
379
+ if (targetPath === "") {
380
+ return anchors && !hasId(page.ids, fragment) ? `no id "${fragment}" on this page${didYouMean(closest(fragment, page.ids), "#")}` : void 0;
381
+ }
382
+ if (options.ignore.some((p) => targetPath.startsWith(p)) || redirected(redirects, targetPath)) return void 0;
383
+ if (!found.has(targetPath)) found.set(targetPath, find(output, targetPath, writtenFiles));
384
+ const target = found.get(targetPath);
385
+ if (target === void 0) {
386
+ if (!meant.has(targetPath) && meant.size < 500) meant.set(targetPath, didYouMean((nearest ??= closestPathFinder(urls))(targetPath), ""));
387
+ return `not found${meant.get(targetPath) ?? ""}`;
388
+ }
389
+ const targetIds = ids.get(target);
390
+ if (fragment !== void 0 && targetIds !== void 0 && anchors && !hasId(targetIds, fragment)) {
391
+ return `no id "${fragment}" on that page${didYouMean(closest(fragment, targetIds), "#")}`;
392
+ }
393
+ return void 0;
394
+ };
395
+ const fromRoot = /* @__PURE__ */ new Map();
396
+ const one = (pageUrl, page, written2, relativeOk, ignoreFragment) => {
397
+ const onSite = origin === void 0 ? void 0 : stripOrigin(written2, origin);
398
+ let link;
399
+ if (onSite !== void 0) link = onSite;
400
+ else if (relativeOk) link = written2;
401
+ else if (trim(written2).startsWith("/") && !trim(written2).startsWith("//")) link = written2;
402
+ else return;
403
+ checked++;
404
+ const inside = inSite(link, config.base);
405
+ if (inside === void 0) return;
406
+ let reason;
407
+ if (inside.charCodeAt(0) === 47 && inside.charCodeAt(1) !== 47 && !inside.includes("#")) {
408
+ if (fromRoot.has(inside)) reason = fromRoot.get(inside);
409
+ else fromRoot.set(inside, reason = reasonFor(pageUrl, page, inside, ignoreFragment));
410
+ } else {
411
+ reason = reasonFor(pageUrl, page, inside, ignoreFragment);
412
+ }
413
+ if (reason === void 0) return;
414
+ const shown = onSite !== void 0 ? trim(written2) : inside;
415
+ const key = `${pageUrl}\0${shown}\0${reason}`;
416
+ if (!seen.has(key)) {
417
+ seen.add(key);
418
+ broken.push({ page: pageUrl, link: shown, reason });
419
+ }
420
+ };
421
+ for (const [at, [, page]] of scans.entries()) {
422
+ const pageUrl = urls[at];
423
+ for (const l of page.links) one(pageUrl, page, l, true, false);
424
+ for (const l of page.siteLinks) one(pageUrl, page, l, false, false);
425
+ for (const l of page.sitePaths) one(pageUrl, page, l, false, true);
426
+ }
427
+ broken.sort((a, b) => compareText(a.page, b.page) || compareText(a.link, b.link) || compareText(a.reason, b.reason));
428
+ return { checked, broken };
429
+ }
430
+ function describe(broken, shown) {
431
+ let out = `${TRAIL_GOES_COLD} on ${broken.length} broken link${broken.length === 1 ? "" : "s"}:`;
432
+ for (const b of broken.slice(0, shown)) out += `
433
+ ${b.page} -> ${b.link} (${b.reason})`;
434
+ if (broken.length > shown) out += `
435
+ ... and ${broken.length - shown} more (--verbose lists them all)`;
436
+ return out;
437
+ }
438
+ BUILTINS.set("ssqch/links", (config, given) => {
439
+ const o = new Options(given, ["anchors", "ignore", "fail", "url"]);
440
+ const options = { anchors: o.bool("anchors"), ignore: o.list("ignore") ?? [], fail: o.bool("fail"), url: o.string("url") };
441
+ const bad = options.ignore.find((p) => !p.startsWith("/"));
442
+ if (bad !== void 0) bail(`ignore: "${bad}" must be a URL path starting with / (like "/downloads/")`);
443
+ if (options.url !== void 0 && originOf(options.url) === void 0) bail(`url: "${options.url}" must be the site's address, like "https://example.com"`);
444
+ let counts;
445
+ config.afterBuild.push({
446
+ label: "",
447
+ fn: async (event) => {
448
+ const output = dirsOf(config).output;
449
+ const result = await check(config, output, event.written, options);
450
+ counts = [result.checked, result.broken.length];
451
+ if (result.broken.length === 0) return;
452
+ const fail = options.fail ?? (config.env === "production" && !config.serving);
453
+ const message = describe(result.broken, config.verbose ? Infinity : 20);
454
+ const each = (severity) => result.broken.map((b) => ({ ...(severity === "error" ? error : warning)("links", `${b.page} -> ${b.link} (${b.reason})`), url: b.page }));
455
+ if (fail) throw new Diagnostics(message, each("error"));
456
+ if (isCapturing()) each("warning").forEach(warn);
457
+ else if (!config.quiet) warn(warning("links", message));
458
+ }
459
+ });
460
+ config.summaries.push(["Links", () => counts === void 0 ? void 0 : `${count(counts[0])} checked, ${count(counts[1])} broken`]);
461
+ });
462
+ export {
463
+ linksPlugin
464
+ };