ssqch 0.7.1 → 0.9.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.
- package/README.md +8 -4
- package/bin/ssqch.js +14 -48
- package/bundled/README.md +1314 -0
- package/bundled/completions/bash +840 -0
- package/bundled/completions/elvish +286 -0
- package/bundled/completions/fish +182 -0
- package/bundled/completions/powershell +318 -0
- package/bundled/completions/zsh +510 -0
- package/bundled/ssqch.d.ts +540 -0
- package/bundled/starter/engines/index.edge +11 -0
- package/bundled/starter/engines/index.ejs +11 -0
- package/bundled/starter/engines/index.hbs +11 -0
- package/bundled/starter/engines/index.liquid +11 -0
- package/bundled/starter/engines/layout.edge +35 -0
- package/bundled/starter/engines/layout.ejs +35 -0
- package/bundled/starter/engines/layout.hbs +35 -0
- package/bundled/starter/engines/layout.liquid +35 -0
- package/bundled/starter/gitignore +3 -0
- package/bundled/starter/jsconfig.json +11 -0
- package/bundled/starter/src/404.md +8 -0
- package/bundled/starter/src/_blueprints/posts.md +5 -0
- package/bundled/starter/src/_data/site.json +4 -0
- package/bundled/starter/src/_includes/layout.jinja +35 -0
- package/bundled/starter/src/index.jinja +11 -0
- package/bundled/starter/src/posts/i-know-what-i-saw.md +11 -0
- package/bundled/starter/src/posts/posts.json +4 -0
- package/bundled/starter/src/posts/raiders-of-the-lost-path.md +27 -0
- package/bundled/starter/src/posts/the-cache-of-the-wild.md +26 -0
- package/bundled/starter/src/posts/the-stump-has-moved.md +15 -0
- package/bundled/starter/src/posts/upon-further-review-a-stump.md +18 -0
- package/bundled/starter/ssqch.config.js +29 -0
- package/bundled/starter-docs/engines/edge/base.edge +41 -0
- package/bundled/starter-docs/engines/edge/containers/details.edge +5 -0
- package/bundled/starter-docs/engines/edge/containers/tab.edge +4 -0
- package/bundled/starter-docs/engines/edge/containers/tabs.edge +5 -0
- package/bundled/starter-docs/engines/edge/doc.edge +59 -0
- package/bundled/starter-docs/engines/edge/hooks/heading.edge +2 -0
- package/bundled/starter-docs/engines/ejs/base.ejs +41 -0
- package/bundled/starter-docs/engines/ejs/containers/details.ejs +5 -0
- package/bundled/starter-docs/engines/ejs/containers/tab.ejs +4 -0
- package/bundled/starter-docs/engines/ejs/containers/tabs.ejs +5 -0
- package/bundled/starter-docs/engines/ejs/doc.ejs +59 -0
- package/bundled/starter-docs/engines/ejs/hooks/heading.ejs +2 -0
- package/bundled/starter-docs/engines/hbs/base.hbs +41 -0
- package/bundled/starter-docs/engines/hbs/containers/details.hbs +5 -0
- package/bundled/starter-docs/engines/hbs/containers/tab.hbs +4 -0
- package/bundled/starter-docs/engines/hbs/containers/tabs.hbs +5 -0
- package/bundled/starter-docs/engines/hbs/doc.hbs +58 -0
- package/bundled/starter-docs/engines/hbs/hooks/heading.hbs +2 -0
- package/bundled/starter-docs/engines/liquid/base.liquid +41 -0
- package/bundled/starter-docs/engines/liquid/containers/details.liquid +5 -0
- package/bundled/starter-docs/engines/liquid/containers/tab.liquid +4 -0
- package/bundled/starter-docs/engines/liquid/containers/tabs.liquid +5 -0
- package/bundled/starter-docs/engines/liquid/doc.liquid +60 -0
- package/bundled/starter-docs/engines/liquid/hooks/heading.liquid +2 -0
- package/bundled/starter-docs/gitignore +4 -0
- package/bundled/starter-docs/src/404.md +12 -0
- package/bundled/starter-docs/src/_blueprints/docs.md +5 -0
- package/bundled/starter-docs/src/_data/nav.yml +10 -0
- package/bundled/starter-docs/src/_data/site.json +5 -0
- package/bundled/starter-docs/src/_includes/base.jinja +41 -0
- package/bundled/starter-docs/src/_includes/containers/details.jinja +5 -0
- package/bundled/starter-docs/src/_includes/containers/tab.jinja +4 -0
- package/bundled/starter-docs/src/_includes/containers/tabs.jinja +5 -0
- package/bundled/starter-docs/src/_includes/doc.jinja +59 -0
- package/bundled/starter-docs/src/_includes/hooks/heading.jinja +2 -0
- package/bundled/starter-docs/src/assets/docs.css +257 -0
- package/bundled/starter-docs/src/assets/docs.js +67 -0
- package/bundled/starter-docs/src/docs/docs.json +1 -0
- package/bundled/starter-docs/src/docs/guides/deploying.md +77 -0
- package/bundled/starter-docs/src/docs/guides/writing.md +65 -0
- package/bundled/starter-docs/src/docs/index.md +29 -0
- package/bundled/starter-docs/src/docs/install.md +42 -0
- package/bundled/starter-docs/src/index.md +13 -0
- package/bundled/starter-docs/ssqch.config.js +40 -0
- package/bundled/trailheads/from-component-frameworks.md +116 -0
- package/bundled/trailheads/from-docusaurus.md +55 -0
- package/bundled/trailheads/from-eleventy.md +140 -0
- package/bundled/trailheads/from-hexo.md +92 -0
- package/bundled/trailheads/from-jekyll.md +79 -0
- package/bundled/trailheads/from-mkdocs.md +45 -0
- package/bundled/trailheads/from-zola.md +71 -0
- package/lib/assets.js +235 -3
- package/lib/chunk-3A647I3N.js +384 -0
- package/lib/chunk-3GYLOC6Y.js +1017 -0
- package/lib/chunk-3K3ANWZ2.js +118 -0
- package/lib/chunk-3NYSSA2C.js +22 -0
- package/lib/chunk-47P4YREZ.js +1287 -0
- package/lib/chunk-4Q6WMTER.js +32 -0
- package/lib/chunk-76NTVE34.js +338 -0
- package/lib/chunk-7PWCYHTJ.js +1350 -0
- package/lib/chunk-7RDRZHJD.js +217 -0
- package/lib/chunk-7SD7K567.js +57 -0
- package/lib/chunk-7XLK2GEG.js +54 -0
- package/lib/chunk-AD3HAW3W.js +10 -0
- package/lib/chunk-BEGC7YP6.js +502 -0
- package/lib/chunk-CMUWRPSQ.js +113 -0
- package/lib/chunk-CZ4XQC56.js +999 -0
- package/lib/chunk-D2XE2GTY.js +71 -0
- package/lib/chunk-DDV6JEC2.js +46 -0
- package/lib/chunk-DELWRJAO.js +37409 -0
- package/lib/chunk-DELWRJAO.js.LEGAL.txt +27 -0
- package/lib/chunk-F65YUXZ7.js +334 -0
- package/lib/chunk-FVZ5JBRI.js +115 -0
- package/lib/chunk-GRWMGC7D.js +4435 -0
- package/lib/chunk-GRWMGC7D.js.LEGAL.txt +41 -0
- package/lib/chunk-GUKSZ2XM.js +207 -0
- package/lib/chunk-HPXAZ2HU.js +251 -0
- package/lib/chunk-HXCLCXRT.js +20 -0
- package/lib/chunk-I3PS26CI.js +48 -0
- package/lib/chunk-IAFM5ITE.js +11 -0
- package/lib/chunk-II5DEH3Q.js +209 -0
- package/lib/chunk-IJWHOFRP.js +44 -0
- package/lib/chunk-LPHNACE4.js +29 -0
- package/lib/chunk-MI6EJWA2.js +175 -0
- package/lib/chunk-NCWFYT74.js +1541 -0
- package/lib/chunk-NKXEPHRZ.js +136 -0
- package/lib/chunk-NNUKIGOO.js +160 -0
- package/lib/chunk-R7K3D5W5.js +3957 -0
- package/lib/chunk-RNJFPFXE.js +29 -0
- package/lib/chunk-SF4I6Z7S.js +25 -0
- package/lib/chunk-SURPOAW7.js +44 -0
- package/lib/chunk-SXMJ52IK.js +572 -0
- package/lib/chunk-TICWN55Z.js +20 -0
- package/lib/chunk-TVU3OPPK.js +146 -0
- package/lib/chunk-UU43WIZG.js +29 -0
- package/lib/chunk-VJWQSYEG.js +119 -0
- package/lib/chunk-XMXBHXZR.js +75 -0
- package/lib/chunk-YTHQBMDJ.js +211 -0
- package/lib/cli.js +547 -0
- package/lib/elements.js +180 -3
- package/lib/image.js +27 -3
- package/lib/links.js +464 -3
- package/lib/minify.js +69 -3
- package/lib/redirects.js +152 -3
- package/lib/rss.js +139 -3
- package/lib/sass.js +256 -3
- package/lib/sitemap.js +113 -3
- package/lib/ssqch.js +28 -0
- package/package.json +83 -80
- package/src/serve/live.js +174 -0
- package/src/serve/not-found.html +31 -0
- package/types/globals.d.ts +3 -2
- package/types/image.d.ts +7 -3
- package/types/index.d.ts +28 -9
- package/types/links.d.ts +1 -1
- package/types/minify.d.ts +1 -1
- package/types/rss.d.ts +1 -1
- package/types/sass.d.ts +1 -1
- package/types/sitemap.d.ts +2 -0
- package/wasm/markdown.wasm +0 -0
- package/wasm/minify.wasm +0 -0
- package/wasm/sass.wasm +0 -0
- package/lib/index.js +0 -3
- package/platforms.json +0 -6
package/lib/assets.js
CHANGED
|
@@ -1,3 +1,235 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { createRequire as __ssqchCreateRequire } from "node:module";
|
|
2
|
+
const require = __ssqchCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
Options
|
|
5
|
+
} from "./chunk-7SD7K567.js";
|
|
6
|
+
import {
|
|
7
|
+
BUILTINS,
|
|
8
|
+
blake3Hex,
|
|
9
|
+
rewriteHtml
|
|
10
|
+
} from "./chunk-R7K3D5W5.js";
|
|
11
|
+
import "./chunk-7XLK2GEG.js";
|
|
12
|
+
import "./chunk-NKXEPHRZ.js";
|
|
13
|
+
import "./chunk-AD3HAW3W.js";
|
|
14
|
+
import "./chunk-DDV6JEC2.js";
|
|
15
|
+
import "./chunk-NCWFYT74.js";
|
|
16
|
+
import "./chunk-FVZ5JBRI.js";
|
|
17
|
+
import "./chunk-HPXAZ2HU.js";
|
|
18
|
+
import "./chunk-UU43WIZG.js";
|
|
19
|
+
import "./chunk-76NTVE34.js";
|
|
20
|
+
import "./chunk-CMUWRPSQ.js";
|
|
21
|
+
import {
|
|
22
|
+
bail,
|
|
23
|
+
warn,
|
|
24
|
+
warning
|
|
25
|
+
} from "./chunk-GRWMGC7D.js";
|
|
26
|
+
import {
|
|
27
|
+
displayPath
|
|
28
|
+
} from "./chunk-VJWQSYEG.js";
|
|
29
|
+
import "./chunk-I3PS26CI.js";
|
|
30
|
+
|
|
31
|
+
// src/modules/assets.ts
|
|
32
|
+
import crypto from "node:crypto";
|
|
33
|
+
import fs from "node:fs";
|
|
34
|
+
import path from "node:path";
|
|
35
|
+
function assetsPlugin(options = {}) {
|
|
36
|
+
return { name: "ssqch/assets", builtin: "ssqch/assets", options };
|
|
37
|
+
}
|
|
38
|
+
function splitName(name) {
|
|
39
|
+
const dot = name.lastIndexOf(".");
|
|
40
|
+
return dot > 0 ? [name.slice(0, dot), name.slice(dot)] : [name, ""];
|
|
41
|
+
}
|
|
42
|
+
function fingerprintedCopies(dir, stem, ext) {
|
|
43
|
+
let names;
|
|
44
|
+
try {
|
|
45
|
+
names = fs.readdirSync(dir);
|
|
46
|
+
} catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
const out = [];
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
if (!name.startsWith(`${stem}.`) || !name.endsWith(ext)) continue;
|
|
52
|
+
const hash = name.slice(stem.length + 1, name.length - ext.length);
|
|
53
|
+
if (hash.length === 8 && /^[0-9a-f]{8}$/.test(hash) && name.length === stem.length + 1 + 8 + ext.length && fs.statSync(path.join(dir, name), { throwIfNoEntry: false })?.isFile()) out.push(path.join(dir, name));
|
|
54
|
+
}
|
|
55
|
+
return out.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
56
|
+
}
|
|
57
|
+
function fingerprint(output, file) {
|
|
58
|
+
const plain = path.join(output, file.replace(/^\/+/, ""));
|
|
59
|
+
const dir = path.dirname(plain);
|
|
60
|
+
const name = path.basename(plain);
|
|
61
|
+
const [stem, ext] = splitName(name);
|
|
62
|
+
const copies = fingerprintedCopies(dir, stem, ext);
|
|
63
|
+
let hashed;
|
|
64
|
+
if (fs.statSync(plain, { throwIfNoEntry: false })?.isFile()) {
|
|
65
|
+
let bytes;
|
|
66
|
+
try {
|
|
67
|
+
bytes = fs.readFileSync(plain);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
bail(`reading ${plain}: ${e.message}`);
|
|
70
|
+
}
|
|
71
|
+
hashed = `${stem}.${blake3Hex(bytes).slice(0, 8)}${ext}`;
|
|
72
|
+
try {
|
|
73
|
+
fs.renameSync(plain, path.join(dir, hashed));
|
|
74
|
+
} catch (e) {
|
|
75
|
+
bail(`renaming ${plain} to ${hashed}: ${e.message}`);
|
|
76
|
+
}
|
|
77
|
+
for (const old of copies.filter((c) => path.basename(c) !== hashed)) {
|
|
78
|
+
try {
|
|
79
|
+
fs.rmSync(old);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
bail(`removing ${old}: ${e.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else if (copies.length === 1) {
|
|
85
|
+
hashed = path.basename(copies[0]);
|
|
86
|
+
} else if (copies.length === 0) {
|
|
87
|
+
bail(`${plain} doesn't exist; build the CSS and JS before ssqch`);
|
|
88
|
+
} else {
|
|
89
|
+
bail(`${plain} doesn't exist, and there are ${copies.length} fingerprinted copies of it; rebuild it`);
|
|
90
|
+
}
|
|
91
|
+
return file.slice(0, file.length - name.length) + hashed;
|
|
92
|
+
}
|
|
93
|
+
function builtCopy(output, file) {
|
|
94
|
+
const plain = path.join(output, file.replace(/^\/+/, ""));
|
|
95
|
+
const name = path.basename(plain);
|
|
96
|
+
const [stem, ext] = splitName(name);
|
|
97
|
+
const copies = fingerprintedCopies(path.dirname(plain), stem, ext);
|
|
98
|
+
return copies.length === 1 ? file.slice(0, file.length - name.length) + path.basename(copies[0]) : void 0;
|
|
99
|
+
}
|
|
100
|
+
function integrity(bytes) {
|
|
101
|
+
return `sha384-${crypto.createHash("sha384").update(bytes).digest("base64")}`;
|
|
102
|
+
}
|
|
103
|
+
function passthroughSource(config, url) {
|
|
104
|
+
const root = config.root;
|
|
105
|
+
const input = path.resolve(root, config.input);
|
|
106
|
+
const output = path.resolve(root, config.output);
|
|
107
|
+
const want = path.join(output, url.replace(/^\/+/, ""));
|
|
108
|
+
const inside = (dir, p) => p.startsWith(dir + path.sep);
|
|
109
|
+
for (const { from, to } of config.passthrough) {
|
|
110
|
+
if (/[*?[{]/.test(from)) continue;
|
|
111
|
+
const src = path.resolve(root, from);
|
|
112
|
+
const dest = to !== void 0 ? path.join(output, to) : path.join(output, inside(input, src) ? path.relative(input, src) : inside(root, src) ? path.relative(root, src) : src);
|
|
113
|
+
const found = want === dest ? src : inside(dest, want) ? path.join(src, path.relative(dest, want)) : void 0;
|
|
114
|
+
if (found !== void 0 && (fs.statSync(found, { throwIfNoEntry: false })?.isFile() ?? false)) return found;
|
|
115
|
+
}
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
var plainPath = (value) => value.split(/[?#]/)[0];
|
|
119
|
+
function rewriteAssets(html, urls, sri) {
|
|
120
|
+
const rewrite = (value) => {
|
|
121
|
+
const at = value.search(/[?#]/);
|
|
122
|
+
const [p, rest] = at === -1 ? [value, ""] : [value.slice(0, at), value.slice(at)];
|
|
123
|
+
const url = urls.get(p);
|
|
124
|
+
return url !== void 0 && url !== p ? url + rest : void 0;
|
|
125
|
+
};
|
|
126
|
+
return rewriteHtml(html, {
|
|
127
|
+
tag: (el) => {
|
|
128
|
+
for (const attr of ["href", "src"]) {
|
|
129
|
+
const value = el.get(attr);
|
|
130
|
+
if (value === void 0) continue;
|
|
131
|
+
const loads = el.name === "link" && attr === "href" || el.name === "script" && attr === "src";
|
|
132
|
+
if (loads && el.get("integrity") === void 0) {
|
|
133
|
+
const hash = sri.get(plainPath(value));
|
|
134
|
+
if (hash !== void 0) el.set("integrity", hash);
|
|
135
|
+
}
|
|
136
|
+
const changed = rewrite(value);
|
|
137
|
+
if (changed !== void 0) el.set(attr, changed);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
script: (el, js) => {
|
|
141
|
+
const module = el.get("src") === void 0 && el.get("type")?.trim().toLowerCase() === "module";
|
|
142
|
+
return module ? rewriteImports(js, urls) : js;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
var IMPORT = /(\bfrom\s*|\bimport\s*(?:\(\s*)?)(?:"([^"\n]*)"|'([^'\n]*)')/g;
|
|
147
|
+
function rewriteImports(js, urls) {
|
|
148
|
+
if (!js.includes("import") && !js.includes("export")) return js;
|
|
149
|
+
return js.replace(IMPORT, (whole, lead, double, single) => {
|
|
150
|
+
const [quote, spec] = double !== void 0 ? ['"', double] : ["'", single];
|
|
151
|
+
const at = spec.search(/[?#]/);
|
|
152
|
+
const [p, rest] = at === -1 ? [spec, ""] : [spec.slice(0, at), spec.slice(at)];
|
|
153
|
+
const url = urls.get(p);
|
|
154
|
+
return url !== void 0 && url !== p ? `${lead}${quote}${url}${rest}${quote}` : whole;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
BUILTINS.set("ssqch/assets", (config, given) => {
|
|
158
|
+
const o = new Options(given, ["files", "fingerprint", "integrity"]);
|
|
159
|
+
const files = o.list("files") ?? [];
|
|
160
|
+
if (!files.length) bail('files is required: the URL paths of the files to fingerprint, like ["/assets/index.css"]');
|
|
161
|
+
const fingerprinting = o.bool("fingerprint");
|
|
162
|
+
const withIntegrity = o.bool("integrity") ?? false;
|
|
163
|
+
for (const file of files) {
|
|
164
|
+
if (!file.startsWith("/") || file.endsWith("/") || file.includes("..")) bail(`files: "${file}" must be a URL path to a file, starting with / (like "/assets/index.css")`);
|
|
165
|
+
}
|
|
166
|
+
let urls = /* @__PURE__ */ new Map();
|
|
167
|
+
let sri = /* @__PURE__ */ new Map();
|
|
168
|
+
let names = [];
|
|
169
|
+
let changing = [];
|
|
170
|
+
config.beforeBuild.push({ label: "", fn: () => {
|
|
171
|
+
const output = path.resolve(config.root, config.output);
|
|
172
|
+
const shownOutput = displayPath(config.root, output);
|
|
173
|
+
const enabled = fingerprinting ?? (config.env === "production" && !config.serving);
|
|
174
|
+
const map = /* @__PURE__ */ new Map();
|
|
175
|
+
const hashes = /* @__PURE__ */ new Map();
|
|
176
|
+
const done = [];
|
|
177
|
+
for (const file of files) {
|
|
178
|
+
if (enabled) {
|
|
179
|
+
const src = passthroughSource(config, file);
|
|
180
|
+
if (src !== void 0) {
|
|
181
|
+
const plain = path.join(output, file.replace(/^\/+/, ""));
|
|
182
|
+
fs.mkdirSync(path.dirname(plain), { recursive: true });
|
|
183
|
+
try {
|
|
184
|
+
fs.copyFileSync(src, plain);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
bail(`copying ${src} to ${plain}: ${e.message}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const hashed = fingerprint(output, file);
|
|
190
|
+
if (withIntegrity) {
|
|
191
|
+
const at = path.join(output, hashed.replace(/^\/+/, ""));
|
|
192
|
+
let bytes;
|
|
193
|
+
try {
|
|
194
|
+
bytes = fs.readFileSync(at);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
bail(`reading ${at}: ${e.message}`);
|
|
197
|
+
}
|
|
198
|
+
hashes.set(file, integrity(bytes));
|
|
199
|
+
}
|
|
200
|
+
done.push(hashed.slice(hashed.lastIndexOf("/") + 1));
|
|
201
|
+
map.set(file, hashed);
|
|
202
|
+
} else if ((fs.statSync(path.join(output, file.replace(/^\/+/, "")), { throwIfNoEntry: false })?.isFile() ?? false) || passthroughSource(config, file) !== void 0) {
|
|
203
|
+
map.set(file, file);
|
|
204
|
+
} else {
|
|
205
|
+
const copy = builtCopy(output, file);
|
|
206
|
+
if (copy !== void 0) {
|
|
207
|
+
warn(warning("assets", `${file} isn't in the output (${shownOutput}), so pages link to ${copy} from the last production build; run the tool that writes ${file} to see changes`));
|
|
208
|
+
map.set(file, copy);
|
|
209
|
+
} else {
|
|
210
|
+
warn(warning("assets", `${file} isn't in the output yet (${shownOutput}); its tool may still be building it`));
|
|
211
|
+
map.set(file, file);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
urls = map;
|
|
216
|
+
sri = hashes;
|
|
217
|
+
names = done;
|
|
218
|
+
changing = [.../* @__PURE__ */ new Set([...[...map].filter(([plain, url]) => plain !== url).map(([plain]) => plain), ...hashes.keys()])];
|
|
219
|
+
} });
|
|
220
|
+
config.htmlTransforms.push(["assets", (content, info) => {
|
|
221
|
+
if (path.extname(info.outputPath) !== ".html") return content;
|
|
222
|
+
if (!changing.some((plain) => content.includes(plain))) return content;
|
|
223
|
+
return rewriteAssets(content, urls, sri);
|
|
224
|
+
}]);
|
|
225
|
+
config.filters.set("assetUrl", (...given2) => {
|
|
226
|
+
const p = given2.length === 0 ? "" : String(given2[0]);
|
|
227
|
+
const url = urls.get(p);
|
|
228
|
+
if (url === void 0) bail(`assetUrl("${p}"): not one of the assets plugin's files (${[...urls.keys()].sort((a, b) => a < b ? -1 : a > b ? 1 : 0).join(", ")})`);
|
|
229
|
+
return url;
|
|
230
|
+
});
|
|
231
|
+
config.summaries.push(["Assets", () => names.length ? `${names.length} fingerprinted (${names.join(", ")})` : void 0]);
|
|
232
|
+
});
|
|
233
|
+
export {
|
|
234
|
+
assetsPlugin
|
|
235
|
+
};
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { createRequire as __ssqchCreateRequire } from "node:module";
|
|
2
|
+
const require = __ssqchCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
withBase
|
|
5
|
+
} from "./chunk-R7K3D5W5.js";
|
|
6
|
+
import {
|
|
7
|
+
slugOptions,
|
|
8
|
+
slugWith
|
|
9
|
+
} from "./chunk-NCWFYT74.js";
|
|
10
|
+
import {
|
|
11
|
+
BuildError,
|
|
12
|
+
isPlainObject
|
|
13
|
+
} from "./chunk-GRWMGC7D.js";
|
|
14
|
+
import {
|
|
15
|
+
compareText
|
|
16
|
+
} from "./chunk-VJWQSYEG.js";
|
|
17
|
+
|
|
18
|
+
// src/content.ts
|
|
19
|
+
var HEADING = /<h([1-6])(\s[^>]*)?>(.*?)<\/h[1-6]\s*>/gis;
|
|
20
|
+
var ID_ATTR = /(?:^|\s)id\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i;
|
|
21
|
+
var TAG = /<(\/?)([A-Za-z][A-Za-z0-9-]*)([^>]*)>|<!--.*?-->/gs;
|
|
22
|
+
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;
|
|
24
|
+
var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
|
|
25
|
+
function headings(html) {
|
|
26
|
+
if (!html.includes("<h") && !html.includes("<H")) return [];
|
|
27
|
+
const out = [];
|
|
28
|
+
for (const found of html.replace(CODE, "").matchAll(HEADING)) {
|
|
29
|
+
const id = ID_ATTR.exec(found[2] ?? "");
|
|
30
|
+
const value = id ? id[1] ?? id[2] ?? id[3] : void 0;
|
|
31
|
+
out.push({ level: Number(found[1]), id: value === void 0 ? void 0 : decodeEntities(value), text: htmlText(found[3]) });
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function htmlText(html) {
|
|
36
|
+
let text = "";
|
|
37
|
+
let hidden = 0;
|
|
38
|
+
let last = 0;
|
|
39
|
+
for (const found of html.matchAll(TAG)) {
|
|
40
|
+
if (hidden === 0) text += html.slice(last, found.index);
|
|
41
|
+
last = found.index + found[0].length;
|
|
42
|
+
if (found[2] === void 0) continue;
|
|
43
|
+
const name = found[2].toLowerCase();
|
|
44
|
+
const attrs = found[3] ?? "";
|
|
45
|
+
if (VOID.has(name) || attrs.endsWith("/")) {
|
|
46
|
+
if (name === "br" && hidden === 0) text += " ";
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (found[1] === "/") hidden = Math.max(0, hidden - 1);
|
|
50
|
+
else if (hidden > 0 || HIDDEN.test(attrs)) hidden++;
|
|
51
|
+
}
|
|
52
|
+
if (hidden === 0) text += html.slice(last);
|
|
53
|
+
return splitWhitespace(decodeEntities(text)).join(" ");
|
|
54
|
+
}
|
|
55
|
+
function splitWhitespace(text) {
|
|
56
|
+
return text.split(/[\t-\r \u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]+/).filter((word) => word !== "");
|
|
57
|
+
}
|
|
58
|
+
var ENTITY = /&(#[0-9]{1,7}|#[xX][0-9A-Fa-f]{1,6}|[A-Za-z]+);/g;
|
|
59
|
+
var NAMED = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\xA0" };
|
|
60
|
+
function decodeEntities(s) {
|
|
61
|
+
if (!s.includes("&")) return s;
|
|
62
|
+
return s.replace(ENTITY, (whole, name) => {
|
|
63
|
+
if (Object.hasOwn(NAMED, name)) return NAMED[name];
|
|
64
|
+
if (name[0] !== "#") return whole;
|
|
65
|
+
const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
|
|
66
|
+
return code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : whole;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function escapeText(s) {
|
|
70
|
+
return s.replace(/[&<>"]/g, (c) => c === "&" ? "&" : c === "<" ? "<" : c === ">" ? ">" : """);
|
|
71
|
+
}
|
|
72
|
+
function escapeHtml(s) {
|
|
73
|
+
return s.replace(/[&<>"']/g, (c) => c === "&" ? "&" : c === "<" ? "<" : c === ">" ? ">" : c === '"' ? """ : "'");
|
|
74
|
+
}
|
|
75
|
+
function excerpt(html) {
|
|
76
|
+
const more = /<!--\s*more\s*-->/.exec(html);
|
|
77
|
+
if (more) return html.slice(0, more.index).trim();
|
|
78
|
+
return /<p(?:\s[^>]*)?>.*?<\/p>/is.exec(html)?.[0];
|
|
79
|
+
}
|
|
80
|
+
function toc(list, from, to, ordered, markup = {}) {
|
|
81
|
+
const tag = ordered ? "ol" : "ul";
|
|
82
|
+
const attr = (name, value) => value ? ` ${name}="${escapeHtml(value)}"` : "";
|
|
83
|
+
const open = (outer) => `<${tag}${outer ? attr("id", markup.id) + attr("class", markup.class) : attr("class", markup.sublistClass)}>`;
|
|
84
|
+
const link = attr("class", markup.linkClass);
|
|
85
|
+
const items = [];
|
|
86
|
+
for (const v of list) {
|
|
87
|
+
const h = v;
|
|
88
|
+
if (typeof h?.level !== "number") continue;
|
|
89
|
+
const level = Math.trunc(h.level);
|
|
90
|
+
const id = typeof h.id === "string" && h.id !== "" ? h.id : void 0;
|
|
91
|
+
if (id !== void 0 && level >= from && level <= to) items.push({ level, id, text: String(h.text) });
|
|
92
|
+
}
|
|
93
|
+
let out = "";
|
|
94
|
+
const stack = [];
|
|
95
|
+
for (const h of items) {
|
|
96
|
+
if (!stack.length) {
|
|
97
|
+
out += open(true);
|
|
98
|
+
stack.push(h.level);
|
|
99
|
+
} else {
|
|
100
|
+
while (stack.length > 1 && h.level < stack[stack.length - 1]) {
|
|
101
|
+
out += `</li></${tag}>`;
|
|
102
|
+
stack.pop();
|
|
103
|
+
}
|
|
104
|
+
if (h.level > stack[stack.length - 1]) {
|
|
105
|
+
out += open(false);
|
|
106
|
+
stack.push(h.level);
|
|
107
|
+
} else {
|
|
108
|
+
out += "</li>";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
out += `<li${attr("class", markup.itemClass?.replaceAll("{level}", String(h.level)))}><a href="#${escapeHtml(h.id ?? "")}"${link}>${escapeText(h.text)}</a>`;
|
|
112
|
+
}
|
|
113
|
+
for (const _ of stack) out += `</li></${tag}>`;
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/nav.ts
|
|
118
|
+
var CHILD_KEYS = ["children", "items", "pages"];
|
|
119
|
+
function children(entry) {
|
|
120
|
+
if (!isPlainObject(entry)) return void 0;
|
|
121
|
+
for (const key of CHILD_KEYS) {
|
|
122
|
+
const list = entry[key];
|
|
123
|
+
if (Array.isArray(list) && list.length > 0) return [key, list];
|
|
124
|
+
}
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
var urlOf = (entry) => isPlainObject(entry) && typeof entry.url === "string" ? entry.url : void 0;
|
|
128
|
+
function sameUrl(a, b) {
|
|
129
|
+
return a !== "" && b !== "" && normal(a) === normal(b);
|
|
130
|
+
}
|
|
131
|
+
function normal(url) {
|
|
132
|
+
let u = url.split(/[#?]/)[0];
|
|
133
|
+
if (u.endsWith("index.html")) u = u.slice(0, -"index.html".length);
|
|
134
|
+
return u.replace(/\/+$/, "");
|
|
135
|
+
}
|
|
136
|
+
function buildIndex(entries) {
|
|
137
|
+
const index = { entries, unmarked: entries.map((e) => mark(e, "\0")[0]), paths: /* @__PURE__ */ new Map(), flat: [], position: /* @__PURE__ */ new Map() };
|
|
138
|
+
const walk = (level, prefix) => {
|
|
139
|
+
level.forEach((e, i) => {
|
|
140
|
+
prefix.push(i);
|
|
141
|
+
const url = urlOf(e);
|
|
142
|
+
if (url !== void 0 && url !== "") {
|
|
143
|
+
const key = normal(url);
|
|
144
|
+
const at = index.paths.get(key);
|
|
145
|
+
if (at) at.push([...prefix]);
|
|
146
|
+
else index.paths.set(key, [[...prefix]]);
|
|
147
|
+
if (!index.position.has(key)) index.position.set(key, index.flat.length);
|
|
148
|
+
index.flat.push(withoutChildren(e));
|
|
149
|
+
}
|
|
150
|
+
const below = children(e);
|
|
151
|
+
if (below) walk(below[1], prefix);
|
|
152
|
+
prefix.pop();
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
walk(entries, []);
|
|
156
|
+
return index;
|
|
157
|
+
}
|
|
158
|
+
var RECENT = [];
|
|
159
|
+
var SEEN_ONCE = [];
|
|
160
|
+
function indexOf(entries) {
|
|
161
|
+
const found = RECENT.find((i) => i.entries === entries);
|
|
162
|
+
if (found) return found;
|
|
163
|
+
const at = SEEN_ONCE.indexOf(entries);
|
|
164
|
+
if (at < 0) {
|
|
165
|
+
if (SEEN_ONCE.length >= 16) SEEN_ONCE.shift();
|
|
166
|
+
SEEN_ONCE.push(entries);
|
|
167
|
+
return void 0;
|
|
168
|
+
}
|
|
169
|
+
SEEN_ONCE.splice(at, 1);
|
|
170
|
+
const index = buildIndex(entries);
|
|
171
|
+
if (RECENT.length >= 16) RECENT.shift();
|
|
172
|
+
RECENT.push(index);
|
|
173
|
+
return index;
|
|
174
|
+
}
|
|
175
|
+
function markPaths(level, paths) {
|
|
176
|
+
const out = level.slice();
|
|
177
|
+
const firsts = [...new Set(paths.map((p) => p[0]))].sort((a, b) => a - b);
|
|
178
|
+
for (const i of firsts) {
|
|
179
|
+
const entry = level[i];
|
|
180
|
+
if (!isPlainObject(entry)) continue;
|
|
181
|
+
const here = paths.filter((p) => p[0] === i).map((p) => p.slice(1));
|
|
182
|
+
const current = here.some((p) => p.length === 0);
|
|
183
|
+
const below = here.filter((p) => p.length > 0);
|
|
184
|
+
const map = { ...entry };
|
|
185
|
+
if (below.length > 0) {
|
|
186
|
+
const kids = children(entry);
|
|
187
|
+
if (kids) map[kids[0]] = markPaths(kids[1], below);
|
|
188
|
+
}
|
|
189
|
+
map.current = current;
|
|
190
|
+
map.ancestor = below.length > 0;
|
|
191
|
+
map.open = true;
|
|
192
|
+
out[i] = map;
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
function tree(entries, url) {
|
|
197
|
+
return entries.map((e) => mark(e, url)[0]);
|
|
198
|
+
}
|
|
199
|
+
function treeOf(nav, url) {
|
|
200
|
+
if (!Array.isArray(nav)) return [];
|
|
201
|
+
const index = indexOf(nav);
|
|
202
|
+
if (!index) return tree(nav, url);
|
|
203
|
+
const paths = url === "" ? void 0 : index.paths.get(normal(url));
|
|
204
|
+
return paths ? markPaths(index.unmarked, paths) : index.unmarked.slice();
|
|
205
|
+
}
|
|
206
|
+
function pagerOf(nav, url) {
|
|
207
|
+
if (!Array.isArray(nav)) return pager([], url);
|
|
208
|
+
const index = indexOf(nav);
|
|
209
|
+
if (!index) return pager(nav, url);
|
|
210
|
+
const i = url === "" ? void 0 : index.position.get(normal(url));
|
|
211
|
+
const at = (j) => j === void 0 ? null : index.flat[j] ?? null;
|
|
212
|
+
return { previous: at(i === void 0 || i === 0 ? void 0 : i - 1), next: at(i === void 0 ? void 0 : i + 1) };
|
|
213
|
+
}
|
|
214
|
+
function breadcrumbsOf(nav, url) {
|
|
215
|
+
if (!Array.isArray(nav)) return [];
|
|
216
|
+
const index = indexOf(nav);
|
|
217
|
+
if (!index) return breadcrumbs(nav, url);
|
|
218
|
+
const path = url === "" ? void 0 : index.paths.get(normal(url))?.[0];
|
|
219
|
+
if (!path) return [];
|
|
220
|
+
let level = nav;
|
|
221
|
+
const out = [];
|
|
222
|
+
for (const i of path) {
|
|
223
|
+
const entry = level[i];
|
|
224
|
+
out.push(withoutChildren(entry));
|
|
225
|
+
level = children(entry)?.[1] ?? [];
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
function mark(entry, url) {
|
|
230
|
+
if (!isPlainObject(entry)) return [entry, false];
|
|
231
|
+
const out = { ...entry };
|
|
232
|
+
const own = urlOf(entry);
|
|
233
|
+
const current = own !== void 0 && sameUrl(own, url);
|
|
234
|
+
let ancestor = false;
|
|
235
|
+
const below = children(entry);
|
|
236
|
+
if (below) {
|
|
237
|
+
out[below[0]] = below[1].map((c) => {
|
|
238
|
+
const [v, found] = mark(c, url);
|
|
239
|
+
ancestor ||= found;
|
|
240
|
+
return v;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
out.current = current;
|
|
244
|
+
out.ancestor = ancestor;
|
|
245
|
+
out.open = current || ancestor;
|
|
246
|
+
return [out, current || ancestor];
|
|
247
|
+
}
|
|
248
|
+
function flatten(entries, out) {
|
|
249
|
+
for (const e of entries) {
|
|
250
|
+
const url = urlOf(e);
|
|
251
|
+
if (url !== void 0 && url !== "") out.push(e);
|
|
252
|
+
const below = children(e);
|
|
253
|
+
if (below) flatten(below[1], out);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function pager(entries, url) {
|
|
257
|
+
const flat = [];
|
|
258
|
+
flatten(entries, flat);
|
|
259
|
+
const i = flat.findIndex((e) => sameUrl(urlOf(e) ?? "", url));
|
|
260
|
+
const at = (j) => j === void 0 || j < 0 || j >= flat.length ? null : withoutChildren(flat[j]);
|
|
261
|
+
return { previous: at(i < 0 || i === 0 ? void 0 : i - 1), next: at(i < 0 ? void 0 : i + 1) };
|
|
262
|
+
}
|
|
263
|
+
function withoutChildren(e) {
|
|
264
|
+
if (!isPlainObject(e)) return e;
|
|
265
|
+
return Object.fromEntries(Object.entries(e).filter(([k]) => !CHILD_KEYS.includes(k)));
|
|
266
|
+
}
|
|
267
|
+
function breadcrumbs(entries, url) {
|
|
268
|
+
const path = [];
|
|
269
|
+
const walk = (level) => {
|
|
270
|
+
for (const e of level) {
|
|
271
|
+
path.push(withoutChildren(e));
|
|
272
|
+
const own = urlOf(e);
|
|
273
|
+
if (own !== void 0 && sameUrl(own, url)) return true;
|
|
274
|
+
const below = children(e);
|
|
275
|
+
if (below && walk(below[1])) return true;
|
|
276
|
+
path.pop();
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
};
|
|
280
|
+
return walk(entries) ? path : [];
|
|
281
|
+
}
|
|
282
|
+
function totalCompare(a, b) {
|
|
283
|
+
if (Number.isNaN(a) || Number.isNaN(b)) return Number(Number.isNaN(a)) - Number(Number.isNaN(b));
|
|
284
|
+
if (a < b) return -1;
|
|
285
|
+
if (a > b) return 1;
|
|
286
|
+
if (a === 0 && b === 0) return Number(Object.is(a, 0)) - Number(Object.is(b, 0));
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
var get = (v, key) => isPlainObject(v) ? v[key] : void 0;
|
|
290
|
+
function fromPages(items) {
|
|
291
|
+
let nodes = [];
|
|
292
|
+
for (const item of items) {
|
|
293
|
+
const data = get(item, "data");
|
|
294
|
+
const nav = get(data, "nav");
|
|
295
|
+
if (nav === void 0 || nav === null || nav === false) continue;
|
|
296
|
+
const navTitle = get(nav, "title");
|
|
297
|
+
const title = typeof navTitle === "string" ? navTitle : String(get(data, "title"));
|
|
298
|
+
const navKey = get(nav, "key");
|
|
299
|
+
const key = typeof navKey === "string" ? navKey : title;
|
|
300
|
+
const parent = get(nav, "parent");
|
|
301
|
+
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 } });
|
|
303
|
+
}
|
|
304
|
+
const build = (parent, depth) => {
|
|
305
|
+
if (depth > 32) return [];
|
|
306
|
+
const level = nodes.filter((n) => n.parent === parent);
|
|
307
|
+
level.sort((a, b) => totalCompare(a.order, b.order) || compareText(a.entry.title, b.entry.title));
|
|
308
|
+
return level.map((n) => ({ ...n.entry, children: build(n.key, depth + 1) }));
|
|
309
|
+
};
|
|
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);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/filters.ts
|
|
316
|
+
var BUILTIN_FILTERS = [
|
|
317
|
+
["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."],
|
|
319
|
+
["navTree", "`navTree(nav, page.url)` marks a navigation tree's entries `current`, `ancestor` or `open`."],
|
|
320
|
+
["navPager", "`navPager(nav, page.url)` is `{ previous, next }` in reading order."],
|
|
321
|
+
["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."],
|
|
323
|
+
["highlight", "`highlight(code, lang)` is highlighted HTML for inside a `<code>`, with `hl-*` classes."],
|
|
324
|
+
["readingTime", "`readingTime(content)` is the minutes it takes to read some HTML, at 200 words a minute."],
|
|
325
|
+
["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.']
|
|
327
|
+
];
|
|
328
|
+
function builtinFilters(markdown, config) {
|
|
329
|
+
const filters = /* @__PURE__ */ new Map();
|
|
330
|
+
filters.set("markdown", (text, option) => {
|
|
331
|
+
const inline = option === "inline" || isPlainObject(option) && Boolean(option.inline);
|
|
332
|
+
return markdown.html(text === void 0 || text === null ? "" : String(text), inline);
|
|
333
|
+
});
|
|
334
|
+
filters.set("highlight", (...args) => {
|
|
335
|
+
const code = args.length > 0 ? String(args[0]) : "";
|
|
336
|
+
const lang = args.length > 1 ? String(args[1]) : "";
|
|
337
|
+
return markdown.highlight(code, lang) ?? escapeText(code);
|
|
338
|
+
});
|
|
339
|
+
const urlArg = (args) => args.length > 1 ? String(args[1]) : "";
|
|
340
|
+
filters.set("navTree", (...args) => treeOf(args[0], urlArg(args)));
|
|
341
|
+
filters.set("navPager", (...args) => pagerOf(args[0], urlArg(args)));
|
|
342
|
+
filters.set("navBreadcrumbs", (...args) => breadcrumbsOf(args[0], urlArg(args)));
|
|
343
|
+
filters.set("pagesTree", (...args) => fromPages(Array.isArray(args[0]) ? args[0] : []));
|
|
344
|
+
filters.set("slugify", (text, option) => {
|
|
345
|
+
const [separator, apostrophes] = slugOptions(option);
|
|
346
|
+
return slugWith(String(text), separator, apostrophes);
|
|
347
|
+
});
|
|
348
|
+
filters.set("readingTime", (text, wordsPerMinute) => {
|
|
349
|
+
const wpm = typeof wordsPerMinute === "number" && wordsPerMinute > 0 ? wordsPerMinute : 200;
|
|
350
|
+
const words = splitWhitespace(htmlText(String(text))).length;
|
|
351
|
+
return Math.max(Math.ceil(words / wpm), 1);
|
|
352
|
+
});
|
|
353
|
+
const TOC_MARKUP = ["id", "class", "sublistClass", "itemClass", "linkClass"];
|
|
354
|
+
filters.set("toc", (list, option, last) => {
|
|
355
|
+
const headings2 = Array.isArray(list) ? list : [];
|
|
356
|
+
let [from, to, ordered] = [2, 3, false];
|
|
357
|
+
const markup = {};
|
|
358
|
+
if (isPlainObject(option)) {
|
|
359
|
+
for (const [key, value] of Object.entries(option)) {
|
|
360
|
+
if (TOC_MARKUP.includes(key)) {
|
|
361
|
+
if (value !== void 0 && value !== null && typeof value !== "string") throw new BuildError(`toc: \`${key}\` must be text (a class name, or names with spaces between)`);
|
|
362
|
+
if (value) markup[key] = value;
|
|
363
|
+
} else if (!["from", "to", "ordered"].includes(key)) throw new BuildError(`toc: unknown option \`${key}\` (options: from, to, ordered, ${TOC_MARKUP.join(", ")})`);
|
|
364
|
+
}
|
|
365
|
+
if (typeof option.from === "number") from = option.from;
|
|
366
|
+
if (typeof option.to === "number") to = option.to;
|
|
367
|
+
ordered = Boolean(option.ordered);
|
|
368
|
+
} else if (typeof option === "number") {
|
|
369
|
+
from = option;
|
|
370
|
+
to = typeof last === "number" ? last : Math.max(to, from);
|
|
371
|
+
}
|
|
372
|
+
const level = (n) => Math.trunc(Math.min(Math.max(n, 1), 6));
|
|
373
|
+
return toc(headings2, level(from), level(to), ordered, markup);
|
|
374
|
+
});
|
|
375
|
+
filters.set("withBase", (url) => withBase(config.base, url === void 0 ? "" : String(url)));
|
|
376
|
+
return filters;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export {
|
|
380
|
+
headings,
|
|
381
|
+
excerpt,
|
|
382
|
+
BUILTIN_FILTERS,
|
|
383
|
+
builtinFilters
|
|
384
|
+
};
|