ssqch 0.11.0 → 0.13.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 (138) hide show
  1. package/bundled/completions/bash +67 -9
  2. package/bundled/completions/elvish +24 -4
  3. package/bundled/completions/fish +37 -25
  4. package/bundled/completions/powershell +26 -4
  5. package/bundled/completions/zsh +45 -10
  6. package/bundled/docs/agents.md +2 -2
  7. package/bundled/docs/build-summary.md +1 -1
  8. package/bundled/docs/comparing-builds.md +7 -4
  9. package/bundled/docs/configuring.md +7 -12
  10. package/bundled/docs/deploying.md +1 -1
  11. package/bundled/docs/field-guide.md +4 -4
  12. package/bundled/docs/github-pages.md +2 -1
  13. package/bundled/docs/index.md +1 -1
  14. package/bundled/docs/install.md +1 -1
  15. package/bundled/docs/known-gaps.md +1 -1
  16. package/bundled/docs/markdown.md +11 -13
  17. package/bundled/docs/nav.yml +6 -1
  18. package/bundled/docs/netlify.md +4 -2
  19. package/bundled/docs/patrol.md +48 -0
  20. package/bundled/docs/plugins.md +6 -4
  21. package/bundled/docs/robots.md +72 -0
  22. package/bundled/docs/seo.md +2 -38
  23. package/bundled/docs/serving-markdown.md +142 -0
  24. package/bundled/docs/template-languages.md +2 -1
  25. package/bundled/docs/templates.md +2 -1
  26. package/bundled/docs/trailheads/from-component-frameworks.md +9 -10
  27. package/bundled/docs/trailheads/from-hugo.md +5 -3
  28. package/bundled/docs/trailheads/from-jekyll.md +54 -13
  29. package/bundled/docs/trailheads/from-mkdocs.md +15 -12
  30. package/bundled/docs/trailheads/from-vitepress.md +142 -0
  31. package/bundled/docs/trailheads.md +5 -5
  32. package/bundled/docs/where-values-come-from.md +5 -5
  33. package/bundled/docs/writing-plugins.md +69 -0
  34. package/bundled/ssqch.d.ts +150 -34
  35. package/bundled/starter/engines/index.edge +1 -0
  36. package/bundled/starter/engines/index.ejs +1 -0
  37. package/bundled/starter/engines/index.hbs +1 -0
  38. package/bundled/starter/engines/index.liquid +1 -0
  39. package/bundled/starter/engines/layout.edge +7 -0
  40. package/bundled/starter/engines/layout.ejs +4 -0
  41. package/bundled/starter/engines/layout.hbs +4 -0
  42. package/bundled/starter/engines/layout.liquid +4 -0
  43. package/bundled/starter/src/_data/site.json +1 -0
  44. package/bundled/starter/src/_includes/layout.jinja +4 -0
  45. package/bundled/starter/src/index.jinja +1 -0
  46. package/bundled/starter/ssqch.config.js +14 -1
  47. package/bundled/starter-docs/engines/edge/base.edge +7 -0
  48. package/bundled/starter-docs/engines/edge/doc.edge +4 -0
  49. package/bundled/starter-docs/engines/ejs/base.ejs +4 -0
  50. package/bundled/starter-docs/engines/ejs/doc.ejs +4 -0
  51. package/bundled/starter-docs/engines/hbs/base.hbs +4 -0
  52. package/bundled/starter-docs/engines/hbs/doc.hbs +3 -0
  53. package/bundled/starter-docs/engines/liquid/base.liquid +4 -0
  54. package/bundled/starter-docs/engines/liquid/doc.liquid +4 -0
  55. package/bundled/starter-docs/src/_data/site.json +1 -0
  56. package/bundled/starter-docs/src/_includes/base.jinja +4 -0
  57. package/bundled/starter-docs/src/_includes/doc.jinja +4 -0
  58. package/bundled/starter-docs/src/assets/docs.css +4 -0
  59. package/bundled/starter-docs/src/assets/docs.js +17 -0
  60. package/bundled/starter-docs/ssqch.config.js +14 -1
  61. package/lib/assets.js +13 -11
  62. package/lib/chunk-25WERNDD.js +112 -0
  63. package/lib/{chunk-H5K2ZE7B.js → chunk-2BJFGKOE.js} +13 -5
  64. package/lib/chunk-2FKYWYAB.js +268 -0
  65. package/lib/{chunk-LJOURBYT.js → chunk-3ZTRIO6O.js} +21 -19
  66. package/lib/{chunk-IOBC665M.js → chunk-4AZFCSGJ.js} +5 -3
  67. package/lib/{chunk-HWW5NCVJ.js → chunk-4Q6WMTER.js} +1 -1
  68. package/lib/{chunk-V2FSMOFX.js → chunk-55WXDGO4.js} +3 -3
  69. package/lib/{chunk-ZR3JYLFB.js → chunk-6FY77I4M.js} +331 -58
  70. package/lib/{chunk-JC54PHIT.js → chunk-6OUCRDYI.js} +514 -141
  71. package/lib/{chunk-ERAIEV3O.js → chunk-6U5VIQVY.js} +9 -7
  72. package/lib/{chunk-Z5OP43HU.js → chunk-7U5GWTEH.js} +455 -94
  73. package/lib/{chunk-CMJ7X5WW.js → chunk-AIJNG6MJ.js} +3 -2
  74. package/lib/{chunk-3K237XAX.js → chunk-C2Q7JKFI.js} +12 -10
  75. package/lib/{chunk-GS5B3CBW.js → chunk-DDV6JEC2.js} +1 -1
  76. package/lib/{chunk-A75EVUJX.js → chunk-DFJFHULZ.js} +47 -20
  77. package/lib/{chunk-KZZS4W2V.js → chunk-ENWDM2RW.js} +45 -42
  78. package/lib/{chunk-I3HYKEEW.js → chunk-ER72RPD6.js} +3 -3
  79. package/lib/chunk-F3JPNFCZ.js +23 -0
  80. package/lib/{chunk-B5E27PLU.js → chunk-FENJHLNM.js} +6 -3
  81. package/lib/{chunk-UU43WIZG.js → chunk-FJML7INB.js} +4 -2
  82. package/lib/{chunk-KCF2Z6N7.js → chunk-FQZDUDFK.js} +5 -3
  83. package/lib/{chunk-GJNIQAIH.js → chunk-GSNRAGKQ.js} +13 -6
  84. package/lib/{chunk-443ZQLVX.js → chunk-GU7BBYWB.js} +5 -4
  85. package/lib/{chunk-X2GAVYV2.js → chunk-HDKU6LRI.js} +110 -748
  86. package/lib/chunk-J3C2LEW7.js +121 -0
  87. package/lib/{chunk-XS4EJSEK.js → chunk-K5WZ2VYK.js} +7 -5
  88. package/lib/{chunk-3HZZY3Y7.js → chunk-OOKBXQAY.js} +7 -6
  89. package/lib/chunk-P2WS4RM4.js +707 -0
  90. package/lib/{chunk-RBNPBTDP.js → chunk-SNQOHNXE.js} +1 -1
  91. package/lib/{chunk-HFSWUTXX.js → chunk-SPIFZBIW.js} +1 -1
  92. package/lib/{chunk-QLUTNR37.js → chunk-T5IUI7W7.js} +12 -11
  93. package/lib/{chunk-ZINLHOX4.js → chunk-TGSVSG2G.js} +3 -2
  94. package/lib/{chunk-2L3HR67O.js → chunk-U2KEMVXO.js} +24 -16
  95. package/lib/{chunk-RYIWYWRQ.js → chunk-UHRBPZ4A.js} +7 -5
  96. package/lib/{chunk-2QTJTEBV.js → chunk-ULCT3PAV.js} +1 -1
  97. package/lib/{chunk-FCM3NYFR.js → chunk-UZNUS7RP.js} +12 -9
  98. package/lib/{chunk-GLJQ4C76.js → chunk-V3G2QGL3.js} +13 -106
  99. package/lib/{chunk-Z44IAMNG.js → chunk-VILOEVK7.js} +60 -28
  100. package/lib/chunk-VJWQSYEG.js +119 -0
  101. package/lib/{chunk-5ELAUHRL.js → chunk-WGAIE3DD.js} +23 -19
  102. package/lib/{chunk-OQGXZYZS.js → chunk-WUCRAV36.js} +13 -7
  103. package/lib/{chunk-RZYAIX2R.js → chunk-XYAWJTHM.js} +11 -10
  104. package/lib/{chunk-OSBEH67S.js → chunk-YA23NDMW.js} +5 -3
  105. package/lib/{chunk-AIMEXBTK.js → chunk-YNJNMQWU.js} +37 -142
  106. package/lib/{chunk-QJ5ZFTML.js → chunk-ZMG25MXF.js} +20 -18
  107. package/lib/cli.js +72 -35
  108. package/lib/elements.js +13 -11
  109. package/lib/from-hugo.js +36 -0
  110. package/lib/from-jekyll.js +41 -0
  111. package/lib/from-mkdocs.js +49 -0
  112. package/lib/from-vitepress.js +49 -0
  113. package/lib/image.js +12 -11
  114. package/lib/links.js +13 -11
  115. package/lib/llms.js +613 -0
  116. package/lib/minify.js +14 -12
  117. package/lib/redirects.js +13 -11
  118. package/lib/robots.js +87 -0
  119. package/lib/rss.js +24 -13
  120. package/lib/sass.js +12 -11
  121. package/lib/sitemap.js +23 -18
  122. package/lib/ssqch.js +6 -5
  123. package/lib/vue.js +400 -0
  124. package/package.json +29 -1
  125. package/types/from-hugo.d.ts +5 -0
  126. package/types/from-jekyll.d.ts +11 -0
  127. package/types/from-mkdocs.d.ts +11 -0
  128. package/types/from-vitepress.d.ts +5 -0
  129. package/types/index.d.ts +51 -31
  130. package/types/llms.d.ts +27 -0
  131. package/types/robots.d.ts +13 -0
  132. package/types/sass.d.ts +1 -1
  133. package/types/sitemap.d.ts +2 -2
  134. package/types/vue.d.ts +17 -0
  135. package/wasm/markdown.wasm +0 -0
  136. package/lib/chunk-RVXGUMFI.js +0 -21
  137. /package/lib/{chunk-ZR3JYLFB.js.LEGAL.txt → chunk-6FY77I4M.js.LEGAL.txt} +0 -0
  138. /package/lib/{chunk-AIMEXBTK.js.LEGAL.txt → chunk-YNJNMQWU.js.LEGAL.txt} +0 -0
package/lib/vue.js ADDED
@@ -0,0 +1,400 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ Options
5
+ } from "./chunk-SNQOHNXE.js";
6
+ import {
7
+ BUILTINS,
8
+ debugString
9
+ } from "./chunk-VILOEVK7.js";
10
+ import "./chunk-ULCT3PAV.js";
11
+ import "./chunk-6U5VIQVY.js";
12
+ import "./chunk-AD3HAW3W.js";
13
+ import "./chunk-YCOTX2VM.js";
14
+ import "./chunk-DDV6JEC2.js";
15
+ import "./chunk-6OUCRDYI.js";
16
+ import "./chunk-SPIFZBIW.js";
17
+ import "./chunk-FVZ5JBRI.js";
18
+ import "./chunk-FJML7INB.js";
19
+ import "./chunk-4AZFCSGJ.js";
20
+ import "./chunk-CMUWRPSQ.js";
21
+ import {
22
+ BuildError,
23
+ bail
24
+ } from "./chunk-YNJNMQWU.js";
25
+ import "./chunk-VJWQSYEG.js";
26
+ import "./chunk-I3PS26CI.js";
27
+
28
+ // src/modules/vue.ts
29
+ import fs from "node:fs";
30
+ import path from "node:path";
31
+ import { pathToFileURL } from "node:url";
32
+ var shown = (v) => typeof v === "string" ? debugString(v) : JSON.stringify(v) ?? String(v);
33
+ function vuePlugin(options = {}) {
34
+ return { name: "ssqch/vue", builtin: "ssqch/vue", options };
35
+ }
36
+ function setupImports(markdown) {
37
+ const out = {};
38
+ const loaders = {};
39
+ let fence;
40
+ const lines = markdown.split("\n");
41
+ for (let i = 0; i < lines.length; i++) {
42
+ const m = /^\s*(`{3,}|~{3,})/.exec(lines[i]);
43
+ if (fence !== void 0) {
44
+ if (m && m[1][0] === fence[0] && lines[i].trim() === m[1]) fence = void 0;
45
+ continue;
46
+ }
47
+ if (m) {
48
+ fence = m[1];
49
+ continue;
50
+ }
51
+ if (!/^<script\b[^>]*\bsetup\b/.test(lines[i])) continue;
52
+ const start = i;
53
+ while (i < lines.length && !lines[i].includes("</script>")) i++;
54
+ const code = lines.slice(start, i + 1).join("\n");
55
+ for (const imp of code.matchAll(/import\s+([A-Z]\w*)\s+from\s+['"]([^'"]+\.vue)['"]/g)) out[imp[1]] = imp[2];
56
+ for (const imp of code.matchAll(/import\s*\{\s*data(?:\s+as\s+(\w+))?\s*\}\s*from\s+['"]([^'"]+\.data(?:\.[cm]?[jt]s)?)['"]/g)) loaders[imp[1] ?? "data"] = imp[2];
57
+ }
58
+ return { components: out, loaders };
59
+ }
60
+ function routeParams(relativePath, url) {
61
+ const names = [...relativePath.matchAll(/\[(\w+)\]/g)].map((m2) => m2[1]);
62
+ if (!names.length) return {};
63
+ const pattern = new RegExp(`^/${relativePath.replace(/\.md$/, "").replace(/[.+^$()|{}\\]/g, "\\$&").replace(/\[\w+\]/g, "([^/]+?)")}(?:\\.html|/)?$`);
64
+ const m = pattern.exec(url);
65
+ return m ? Object.fromEntries(names.map((n, i) => [n, decodeURIComponent(m[i + 1])])) : {};
66
+ }
67
+ function packageEntry(root, name, subpath = ".") {
68
+ for (let dir = root; ; dir = path.dirname(dir)) {
69
+ const pkgDir = path.join(dir, "node_modules", ...name.split("/"));
70
+ const file = path.join(pkgDir, "package.json");
71
+ if (fs.existsSync(file)) {
72
+ const pkg = JSON.parse(fs.readFileSync(file, "utf8"));
73
+ const pick = (e) => {
74
+ if (typeof e === "string") return e;
75
+ if (e === null || typeof e !== "object" || Array.isArray(e)) return void 0;
76
+ const o = e;
77
+ for (const key of ["import", "node", "default"]) if (key in o) {
78
+ const p = pick(o[key]);
79
+ if (p) return p;
80
+ }
81
+ return void 0;
82
+ };
83
+ const exp = pkg.exports;
84
+ const entry = exp !== void 0 ? pick(typeof exp === "object" && exp !== null && !Array.isArray(exp) && Object.keys(exp).some((k) => k.startsWith(".")) ? exp[subpath] : subpath === "." ? exp : void 0) : subpath === "." ? pkg.module ?? pkg.main ?? "index.js" : void 0;
85
+ return entry === void 0 ? void 0 : path.join(pkgDir, entry);
86
+ }
87
+ if (path.dirname(dir) === dir) return void 0;
88
+ }
89
+ }
90
+ function sitePackage(root, name) {
91
+ const found = packageEntry(root, name);
92
+ if (found !== void 0) return found;
93
+ const vitepress = path.join(root, "node_modules", "vitepress");
94
+ if (!fs.existsSync(vitepress)) return void 0;
95
+ return packageEntry(fs.realpathSync(vitepress), name);
96
+ }
97
+ async function fromSite(root, name) {
98
+ const entry = sitePackage(root, name);
99
+ if (entry === void 0) {
100
+ const pm = fs.existsSync(path.join(root, "pnpm-lock.yaml")) ? "pnpm add -D" : fs.existsSync(path.join(root, "yarn.lock")) ? "yarn add -D" : "npm install -D";
101
+ bail(`vuePlugin() needs ${name} in the site's packages, as a VitePress site has it: \`${pm} vite @vitejs/plugin-vue vue\``);
102
+ }
103
+ return import(pathToFileURL(entry).href);
104
+ }
105
+ var HYDRATE = ["load", "idle", "visible"];
106
+ var MARK = (n) => `\uE050${n}\uE051`;
107
+ var MARKS = /\uE050(\d+)\uE051/g;
108
+ BUILTINS.set("ssqch/vue", (config, given) => {
109
+ if (given !== null && typeof given === "object" && Object.hasOwn(given, "vitepress")) bail('`vitepress` is fromVitepress() from "ssqch/from-vitepress" now: add it to plugins, and vuePlugin() gives the components VitePress\'s `useData()`, `@theme/` and data loaders (`ssqch docs fromVitepress`)');
110
+ const o = new Options(given, ["components", "root", "hydrate", "css", "vite"]);
111
+ const globals = o.get("components") ?? {};
112
+ if (typeof globals !== "object" || globals === null || Array.isArray(globals)) bail(`components must be an object of { Name: "path/to/Name.vue" }, the ones the site registers for every page (VitePress's \`app.component()\`) (got ${shown(globals)})`);
113
+ for (const [name, file] of Object.entries(globals)) if (!/^[A-Z]\w*$/.test(name) || typeof file !== "string") bail(`components: ${debugString(name)} must be a PascalCase name with a .vue file's path, like { Badge: ".vitepress/theme/Badge.vue" }`);
114
+ const hydrateGiven = o.get("hydrate");
115
+ if (hydrateGiven !== void 0 && hydrateGiven !== false && !HYDRATE.includes(hydrateGiven)) bail(`hydrate must be false, "load", "idle" or "visible" (got ${shown(hydrateGiven)})`);
116
+ const hydrate = hydrateGiven === void 0 || hydrateGiven === false ? false : hydrateGiven;
117
+ const cssGiven = o.get("css");
118
+ if (cssGiven !== void 0 && typeof cssGiven !== "boolean" && !(typeof cssGiven === "string" && cssGiven.startsWith("/") && cssGiven.endsWith(".css"))) bail(`css must be a path like "/assets/vue.css", or false (got ${shown(cssGiven)})`);
119
+ const cssPath = cssGiven === false ? void 0 : typeof cssGiven === "string" ? cssGiven : "/assets/vue.css";
120
+ const extra = o.get("vite") ?? {};
121
+ if (typeof extra !== "object" || extra === null) bail(`vite must be Vite's options to add, like { resolve: { alias: { "@theme": "./.vitepress/theme" } } } (got ${shown(extra)})`);
122
+ const rootGiven = o.string("root");
123
+ const vitepressFolder = [".vitepress", "docs/.vitepress"].map((f) => path.join(config.root, f)).find((f) => fs.existsSync(f));
124
+ const cache = path.join(config.root, ".cache", "ssqch", "vue");
125
+ const globalFile = (file) => file.startsWith(".") ? path.resolve(config.root, file) : file;
126
+ let byPage = /* @__PURE__ */ new Map();
127
+ let pageLoaders = /* @__PURE__ */ new Map();
128
+ const loaded = /* @__PURE__ */ new Map();
129
+ let ids = /* @__PURE__ */ new Map();
130
+ let render;
131
+ let builtFrom = "";
132
+ let pending = [];
133
+ let islands = false;
134
+ const scan = () => {
135
+ const pages = /* @__PURE__ */ new Map();
136
+ const walk = (dir) => {
137
+ for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
138
+ if (e.name.startsWith(".") || e.name === "node_modules" || e.name === "_site") continue;
139
+ const full = path.join(dir, e.name);
140
+ if (e.isDirectory()) {
141
+ if (path.resolve(full) !== path.resolve(config.root, config.output)) walk(full);
142
+ continue;
143
+ }
144
+ if (!/\.md$/i.test(e.name)) continue;
145
+ const found = setupImports(fs.readFileSync(full, "utf8"));
146
+ const files = {};
147
+ for (const [name, spec] of Object.entries(found.components)) files[name] = spec.startsWith(".") ? path.resolve(path.dirname(full), spec) : spec;
148
+ if (Object.keys(files).length) pages.set(path.resolve(full), files);
149
+ const data = {};
150
+ for (const [local, spec] of Object.entries(found.loaders)) {
151
+ const at = path.resolve(path.dirname(full), spec);
152
+ const file = [at, `${at}.ts`, `${at}.js`, `${at}.mts`, `${at}.mjs`].find((f) => /\.data\.[cm]?[jt]s$/.test(f) && fs.existsSync(f));
153
+ if (file) data[local] = file;
154
+ }
155
+ if (Object.keys(data).length) pageLoaders.set(path.resolve(full), data);
156
+ }
157
+ };
158
+ walk(path.resolve(config.root, config.input));
159
+ return pages;
160
+ };
161
+ config.beforeBuild.push({ label: "", fn: async (event) => {
162
+ process.env.NODE_ENV ??= config.env === "production" ? "production" : "development";
163
+ pending = [];
164
+ islands = false;
165
+ const changed = Array.isArray(event.changed) ? event.changed : void 0;
166
+ pageLoaders = /* @__PURE__ */ new Map();
167
+ byPage = scan();
168
+ const all = /* @__PURE__ */ new Set([...Object.values(globals).map(globalFile), ...[...byPage.values()].flatMap((m) => Object.values(m))]);
169
+ const files = [...all].sort();
170
+ ids = new Map(files.map((f, i) => [f, i]));
171
+ const key = JSON.stringify([files, hydrate, rootGiven, cssPath]);
172
+ const codeChanged = changed === void 0 || changed.some((f) => /\.(?:vue|[cm]?[jt]sx?|css|scss)$/.test(f));
173
+ if (render && key === builtFrom && !codeChanged) return;
174
+ if (!files.length) {
175
+ render = void 0;
176
+ builtFrom = key;
177
+ return;
178
+ }
179
+ const [vite, vuePluginModule] = await Promise.all([fromSite(config.root, "vite"), fromSite(config.root, "@vitejs/plugin-vue")]);
180
+ const vue = vuePluginModule.default ?? vuePluginModule;
181
+ fs.rmSync(cache, { recursive: true, force: true });
182
+ fs.mkdirSync(cache, { recursive: true });
183
+ const vitepress = config.vitepress;
184
+ const shim = path.join(cache, "vitepress.js");
185
+ const quiet = { logLevel: config.quiet ? "silent" : "warn" };
186
+ const root = path.resolve(config.root, rootGiven ?? config.input);
187
+ const dirname = {
188
+ name: "ssqch:dirname",
189
+ transform(code, id) {
190
+ if (!/\.[cm]?[jt]sx?$/.test(id.split("?")[0]) || id.includes("node_modules") || !/\b__(?:dirname|filename)\b/.test(code)) return null;
191
+ const file = id.split("?")[0];
192
+ return code.replace(/\b__dirname\b/g, JSON.stringify(path.dirname(file))).replace(/\b__filename\b/g, JSON.stringify(file));
193
+ }
194
+ };
195
+ const given2 = extra;
196
+ const alias = [...vitepress ? [{ find: /^vitepress$/, replacement: shim }, ...vitepressFolder ? [{ find: /^@theme\//, replacement: `${path.join(vitepressFolder, "theme")}/` }] : []] : [], ...Array.isArray(given2.resolve?.alias) ? given2.resolve.alias : Object.entries(given2.resolve?.alias ?? {}).map(([find, replacement]) => ({ find, replacement }))];
197
+ const base = { publicDir: false, ...extra, root, configFile: false, resolve: { ...given2.resolve ?? {}, alias }, ssr: { noExternal: vitepress ? ["vitepress"] : [] }, plugins: [dirname, vue(), ...extra.plugins ?? []], define: { __VUE_OPTIONS_API__: true, __VUE_PROD_DEVTOOLS__: false, __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false, ...extra.define ?? {} } };
198
+ loaded.clear();
199
+ let runner;
200
+ const runLoader = async (file) => {
201
+ if (loaded.has(file)) return;
202
+ runner ??= await vite.createServer({ ...base, logLevel: "silent", server: { middlewareMode: true, hmr: false, watch: null }, appType: "custom", optimizeDeps: { noDiscovery: true, include: [] } });
203
+ let mod2;
204
+ try {
205
+ mod2 = await runner.ssrLoadModule(file);
206
+ } catch (e) {
207
+ throw new BuildError(`vuePlugin(): the data loader ${path.relative(config.root, file)} didn't load: ${e instanceof Error ? e.message : String(e)}`);
208
+ }
209
+ const loader = mod2.default;
210
+ if (!loader || typeof loader.load !== "function") throw new BuildError(`vuePlugin(): ${path.relative(config.root, file)} is imported as a data loader, but its default export has no \`load()\` (VitePress's \`export default { load() { ... } }\`)`);
211
+ loaded.set(file, await loader.load());
212
+ };
213
+ const loaders = {
214
+ name: "ssqch:vitepress-loaders",
215
+ enforce: "pre",
216
+ async resolveId(source, importer) {
217
+ if (!importer || !/\.data(?:\.[cm]?[jt]s)?$/.test(source) || importer.startsWith("\0")) return null;
218
+ const base2 = source.startsWith(".") ? path.resolve(path.dirname(importer.split("?")[0]), source) : void 0;
219
+ if (base2 === void 0) return null;
220
+ const file = [base2, `${base2}.ts`, `${base2}.js`, `${base2}.mts`, `${base2}.mjs`].find((f) => /\.data\.[cm]?[jt]s$/.test(f) && fs.existsSync(f));
221
+ return file === void 0 ? null : `\0ssqch-loader:${file}`;
222
+ },
223
+ async load(id) {
224
+ if (!id.startsWith("\0ssqch-loader:")) return null;
225
+ const file = id.slice("\0ssqch-loader:".length);
226
+ await runLoader(file);
227
+ return `export const data = ${JSON.stringify(loaded.get(file))};`;
228
+ }
229
+ };
230
+ if (vitepress) {
231
+ let siteConfig = {};
232
+ const file = vitepressFolder && ["config.ts", "config.mts", "config.js", "config.mjs"].map((f) => path.join(vitepressFolder, f)).find((f) => fs.existsSync(f));
233
+ if (file) {
234
+ const reader = await vite.createServer({ root: config.root, configFile: false, plugins: [dirname], logLevel: "silent", server: { middlewareMode: true, hmr: false, watch: null }, appType: "custom", optimizeDeps: { noDiscovery: true, include: [] } });
235
+ try {
236
+ siteConfig = (await reader.ssrLoadModule(file)).default ?? {};
237
+ } catch {
238
+ } finally {
239
+ await reader.close();
240
+ }
241
+ }
242
+ const site = { title: siteConfig.title ?? "", description: siteConfig.description ?? "", base: config.base || "/", lang: siteConfig.lang ?? "en-US", themeConfig: siteConfig.themeConfig ?? {} };
243
+ fs.writeFileSync(shim, [
244
+ `import { ref, computed } from "vue";`,
245
+ `export const current = { page: ref({ relativePath: "", frontmatter: {}, params: {}, title: "" }), frontmatter: ref({}), params: ref({}) };`,
246
+ `const site = ref(${JSON.stringify(site)});`,
247
+ `export const useData = () => ({ site, theme: computed(() => site.value.themeConfig), page: current.page, frontmatter: current.frontmatter, params: current.params, title: computed(() => current.page.value.title), description: computed(() => current.frontmatter.value.description ?? site.value.description), lang: computed(() => site.value.lang), isDark: ref(false), localeIndex: ref("root"), hash: ref("") });`,
248
+ `export const useRoute = () => ({ path: "/" + current.page.value.relativePath.replace(/(^|\\/)index\\.md$/, "$1").replace(/\\.md$/, ${JSON.stringify(config.urls === "html" ? ".html" : "/")}), data: current.page.value, component: null });`,
249
+ `export const useRouter = () => ({ route: useRoute(), go: () => {} });`,
250
+ `export const withBase = (p) => (p.startsWith("/") ? ${JSON.stringify(config.base.replace(/\/$/, ""))} + p : p);`,
251
+ `export const inBrowser = false;`,
252
+ `export const defineLoader = (loader) => loader;`,
253
+ `export const defineConfig = (c) => c;`,
254
+ `export const defineConfigWithTheme = (c) => c;`,
255
+ `export const onContentUpdated = () => {};`,
256
+ `export const Content = { render: () => null };`,
257
+ `export const ClientOnly = { setup: () => () => null };`,
258
+ ""
259
+ ].join("\n"));
260
+ }
261
+ const imports = files.map((f, i) => `import C${i} from ${JSON.stringify(f)};`).join("\n");
262
+ const server = path.join(cache, "server.js");
263
+ fs.writeFileSync(server, [
264
+ `import { createSSRApp, h, createStaticVNode } from "vue";`,
265
+ `import { renderToString } from "vue/server-renderer";`,
266
+ ...vitepress ? [`import { current } from ${JSON.stringify(shim)};`] : [],
267
+ imports,
268
+ `const components = [${files.map((_, i) => `C${i}`).join(", ")}];`,
269
+ `export async function render(id, props, content, page) {`,
270
+ ...vitepress ? [` current.page.value = page; current.frontmatter.value = page.frontmatter; current.params.value = page.params;`] : [],
271
+ // What's between the tags is the default slot, as the page's HTML.
272
+ ` const app = createSSRApp({ render: () => h(components[id], props, content ? { default: () => createStaticVNode(content, 1) } : undefined) });`,
273
+ // VitePress's <ClientOnly> renders nothing on the server.
274
+ ` app.component("ClientOnly", { setup: () => () => null });`,
275
+ ` return renderToString(app);`,
276
+ `}`,
277
+ ""
278
+ ].join("\n"));
279
+ try {
280
+ await vite.build({ ...base, plugins: [...vitepress ? [loaders] : [], ...base.plugins], ...quiet, base: config.base || "/", build: { ssr: server, outDir: path.join(cache, "ssr"), emptyOutDir: true, minify: false, cssCodeSplit: false, ssrEmitAssets: true, rollupOptions: { output: { entryFileNames: "server.mjs" } } } });
281
+ } catch (e) {
282
+ throw e instanceof BuildError ? e : new BuildError(`vuePlugin(): Vite couldn't build the components for the server: ${e instanceof Error ? e.message : String(e)}`);
283
+ }
284
+ for (const file of new Set([...pageLoaders.values()].flatMap((m) => Object.values(m)))) await runLoader(file);
285
+ await runner?.close();
286
+ const mod = await import(`${pathToFileURL(path.join(cache, "ssr", "server.mjs")).href}?${Date.now()}`);
287
+ render = mod.render;
288
+ if (hydrate) {
289
+ const client = path.join(cache, "client.js");
290
+ fs.writeFileSync(client, [
291
+ `import { createSSRApp, h } from "vue";`,
292
+ `const load = [${files.map((f) => `() => import(${JSON.stringify(f)})`).join(", ")}];`,
293
+ `const start = (el) => load[Number(el.dataset.component)]().then((m) => { createSSRApp({ render: () => h(m.default, JSON.parse(el.dataset.props || "{}")) }).mount(el); });`,
294
+ `for (const el of document.querySelectorAll("ssqch-vue")) {`,
295
+ ` const when = el.dataset.hydrate;`,
296
+ ` if (when === "visible" && "IntersectionObserver" in window) { const seen = new IntersectionObserver((entries) => { if (entries.some((e) => e.isIntersecting)) { seen.disconnect(); start(el); } }); seen.observe(el); }`,
297
+ ` else if (when === "idle" && "requestIdleCallback" in window) requestIdleCallback(() => start(el));`,
298
+ ` else start(el);`,
299
+ `}`,
300
+ ""
301
+ ].join("\n"));
302
+ try {
303
+ await vite.build({ ...base, plugins: [...vitepress ? [loaders] : [], ...base.plugins], ...quiet, base: `${config.base.replace(/\/$/, "")}/assets/vue/`, build: { outDir: path.join(cache, "client"), emptyOutDir: true, manifest: false, cssCodeSplit: false, rollupOptions: { input: client, output: { entryFileNames: "islands.js", chunkFileNames: "[name]-[hash].js", assetFileNames: "[name]-[hash][extname]" } } } });
304
+ } catch (e) {
305
+ throw new BuildError(`vuePlugin(): Vite couldn't build the components for the browser: ${e instanceof Error ? e.message : String(e)}`);
306
+ }
307
+ }
308
+ builtFrom = key;
309
+ } });
310
+ config.componentRenderers.push((name, value, inputPath, data) => {
311
+ if (!render) return void 0;
312
+ const pageFile = byPage.get(path.resolve(inputPath))?.[name];
313
+ const globalName = globals[name];
314
+ const file = pageFile ?? (globalName === void 0 ? void 0 : globalFile(globalName));
315
+ const id = file === void 0 ? void 0 : ids.get(file);
316
+ if (id === void 0) return void 0;
317
+ const props = Object.fromEntries(Object.entries(value.props).filter(([k]) => !k.includes("-") && k !== "class" && k !== "style"));
318
+ const attrs = Object.fromEntries(Object.entries(value.props).filter(([k]) => k === "class" || k === "style"));
319
+ const front = Object.fromEntries(Object.entries(data).filter(([k]) => !["collections", "page", "content", "pagination", "eleventyComputed", "computed"].includes(k) && typeof data[k] !== "function"));
320
+ const relativePath = path.relative(path.resolve(config.root, config.input), inputPath).split(path.sep).join("/");
321
+ const url = typeof data.page?.url === "string" ? data.page.url : "";
322
+ const params = data.params ?? routeParams(relativePath, url);
323
+ const ownPath = relativePath.includes("[") && url !== "" ? url.replace(/^\//, "").replace(/(^|\/)$/, "$1index.html").replace(/\.html$/, ".md").replace(/^(?!.*\.md$)(.*)$/, "$1.md") : relativePath;
324
+ const page = { relativePath: ownPath, frontmatter: front, params, title: typeof data.title === "string" ? data.title : "" };
325
+ const scope = { page, params, $params: params, frontmatter: front, $frontmatter: front };
326
+ for (const [local, file2] of Object.entries(pageLoaders.get(path.resolve(inputPath)) ?? {})) scope[local] = loaded.get(file2);
327
+ for (const [prop, expr] of Object.entries(value.bindings)) {
328
+ try {
329
+ props[prop] = new Function(...Object.keys(scope), `"use strict"; return (${expr});`)(...Object.values(scope));
330
+ } catch {
331
+ }
332
+ }
333
+ const pageJson = JSON.parse(JSON.stringify(page, (_, v) => v instanceof Date ? v.toISOString() : v));
334
+ const html = fill(value.content).then((content) => render(id, { ...props, ...attrs }, content, pageJson)).then(
335
+ (h) => {
336
+ if (!hydrate) return h;
337
+ islands = true;
338
+ return `<ssqch-vue data-component="${id}" data-hydrate="${hydrate}" data-props="${JSON.stringify(props).replace(/&/g, "&amp;").replace(/"/g, "&quot;")}">${h}</ssqch-vue>`;
339
+ },
340
+ (e) => {
341
+ throw new BuildError(`vuePlugin(): <${name}> in ${path.relative(config.root, inputPath)} didn't render: ${e instanceof Error ? e.message : String(e)}`);
342
+ }
343
+ );
344
+ html.catch(() => {
345
+ });
346
+ pending.push(html);
347
+ return MARK(pending.length - 1);
348
+ });
349
+ config.htmlTransforms.push(["vue", async (content, page) => {
350
+ if (!content.includes("\uE050")) return content;
351
+ let out;
352
+ try {
353
+ out = await fill(content);
354
+ } catch (e) {
355
+ throw e instanceof BuildError ? e : new BuildError(`vuePlugin(): ${page.inputPath}: ${e instanceof Error ? e.message : String(e)}`);
356
+ }
357
+ if (hydrate && out.includes("<ssqch-vue ")) {
358
+ const tag = `<script type="module" src="${config.base.replace(/\/$/, "")}/assets/vue/islands.js"></script>`;
359
+ out = out.includes("</body>") ? out.replace("</body>", `${tag}</body>`) : out + tag;
360
+ }
361
+ return out;
362
+ }]);
363
+ async function fill(text) {
364
+ for (let round = 0; text.includes("\uE050"); round++) {
365
+ if (round > 50) throw new BuildError("vuePlugin(): components nest more than 50 deep");
366
+ const done = /* @__PURE__ */ new Map();
367
+ for (const m of text.matchAll(MARKS)) {
368
+ const n = Number(m[1]);
369
+ if (pending[n] === void 0) throw new BuildError(`vuePlugin(): a component's HTML went missing (marker ${n}): this is a bug in ssqch`);
370
+ done.set(n, await pending[n]);
371
+ }
372
+ text = text.replace(MARKS, (_, n) => done.get(Number(n)));
373
+ }
374
+ return text;
375
+ }
376
+ config.generators.push(["ssqch/vue", () => {
377
+ const files = [];
378
+ if (!render) return files;
379
+ const ssrDir = path.join(cache, "ssr");
380
+ const listed = (dir) => fs.existsSync(dir) ? fs.readdirSync(dir, { recursive: true }).map(String).filter((f) => fs.statSync(path.join(dir, f)).isFile()).sort() : [];
381
+ const ssr = listed(ssrDir);
382
+ const css = ssr.filter((f) => f.endsWith(".css"));
383
+ if (cssPath && css.length) {
384
+ files.push({ path: cssPath, contents: css.map((f) => fs.readFileSync(path.join(ssrDir, f), "utf8")).join("\n") });
385
+ for (const f of ssr) if (!/\.(?:[cm]?js|css|map)$/.test(f)) files.push({ path: `/${f.split(path.sep).join("/")}`, contents: fs.readFileSync(path.join(ssrDir, f)) });
386
+ }
387
+ const clientDir = path.join(cache, "client");
388
+ if (hydrate && islands) {
389
+ for (const f of listed(clientDir)) {
390
+ if (f.endsWith(".map")) continue;
391
+ const full = path.join(clientDir, f);
392
+ files.push({ path: `/assets/vue/${f.split(path.sep).join("/")}`, contents: /\.(?:[cm]?js|css|svg|json)$/.test(f) ? fs.readFileSync(full, "utf8") : fs.readFileSync(full) });
393
+ }
394
+ }
395
+ return files;
396
+ }]);
397
+ });
398
+ export {
399
+ vuePlugin
400
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssqch",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "SiteSquatch (ssqch): a fast static site generator, configured with JavaScript",
5
5
  "keywords": [
6
6
  "static site generator",
@@ -54,6 +54,34 @@
54
54
  "types": "./types/sitemap.d.ts",
55
55
  "default": "./lib/sitemap.js"
56
56
  },
57
+ "./from-vitepress": {
58
+ "types": "./types/from-vitepress.d.ts",
59
+ "default": "./lib/from-vitepress.js"
60
+ },
61
+ "./from-mkdocs": {
62
+ "types": "./types/from-mkdocs.d.ts",
63
+ "default": "./lib/from-mkdocs.js"
64
+ },
65
+ "./from-jekyll": {
66
+ "types": "./types/from-jekyll.d.ts",
67
+ "default": "./lib/from-jekyll.js"
68
+ },
69
+ "./from-hugo": {
70
+ "types": "./types/from-hugo.d.ts",
71
+ "default": "./lib/from-hugo.js"
72
+ },
73
+ "./vue": {
74
+ "types": "./types/vue.d.ts",
75
+ "default": "./lib/vue.js"
76
+ },
77
+ "./llms": {
78
+ "types": "./types/llms.d.ts",
79
+ "default": "./lib/llms.js"
80
+ },
81
+ "./robots": {
82
+ "types": "./types/robots.d.ts",
83
+ "default": "./lib/robots.js"
84
+ },
57
85
  "./elements": {
58
86
  "types": "./types/elements.d.ts",
59
87
  "default": "./lib/elements.js"
@@ -0,0 +1,5 @@
1
+ // ssqch/from-hugo: from ssqch.d.ts, the types `ssqch types` writes.
2
+ /// <reference path="./globals.d.ts" />
3
+ import type { BuiltinPlugin } from "ssqch";
4
+ /** Hugo's shortcodes for a site moving from Hugo, as a default under the site's own `markdown` options (`shortcodes: "hugo"`): a shortcode on a line of its own (`{{< note type="tip" >}}` to `{{< /note >}}`, or `{{% %}}`) is a container rendered by `_includes/containers/<name>.*`, with its arguments as `container.props`, and one inside a line of text renders the same template in its place, with `container.inline` true. Takes no options. */
5
+ export function fromHugo(): BuiltinPlugin;
@@ -0,0 +1,11 @@
1
+ // ssqch/from-jekyll: from ssqch.d.ts, the types `ssqch types` writes.
2
+ /// <reference path="./globals.d.ts" />
3
+ import type { BuiltinPlugin } from "ssqch";
4
+ export interface FromJekyllOptions {
5
+ /** Templates see Jekyll's `page` and `site`, so a Jekyll site's layouts and includes run as written: `page` has the page's front matter too (`page.title`; ssqch's own keys, like `url` and `date`, win), `page.path` and `page.categories`; `site` has the site's own keys, `posts` (newest first), each collection by its tag (`site.articles`), `pages`, `html_pages`, `categories`, `tags`, `data` (the global data) and `time`; and items read in Jekyll's shape (`post.title`, `post.content`, `post.excerpt`). Default `true`. */
6
+ templates?: boolean;
7
+ /** kramdown's Markdown, each a default under the site's own `markdown` options: Markdown inside HTML with `markdown="1"` (`htmlMarkdown: "kramdown"`), kramdown's heading ids (`headingIds: "kramdown"`), smart quotes (`smartPunctuation: true`) and no links from bare URLs (`autolinks: false`). Default `true`. */
8
+ kramdown?: boolean;
9
+ }
10
+ /** What a Jekyll site's templates and Markdown expect, for a site moving from Jekyll: Jekyll's `page` and `site` in templates, and kramdown's Markdown. */
11
+ export function fromJekyll(options?: FromJekyllOptions): BuiltinPlugin;
@@ -0,0 +1,11 @@
1
+ // ssqch/from-mkdocs: from ssqch.d.ts, the types `ssqch types` writes.
2
+ /// <reference path="./globals.d.ts" />
3
+ import type { BuiltinPlugin } from "ssqch";
4
+ export interface FromMkdocsOptions {
5
+ /** The mkdocs.yml, from the project root, that `templates` reads. Default `"mkdocs.yml"`. */
6
+ config?: string;
7
+ /** What MkDocs gives a theme's templates, so an MkDocs theme's Jinja (Material for MkDocs') runs as written: `config`, `nav`, `page` (with `content` and `toc` in layouts), `base_url`, the `url` filter, `main.html` (or a page's `template`) as a Markdown page's layout, the theme's `404.html` as the 404 page, and `.jinja` not escaping what it prints, as MkDocs' Jinja doesn't. Default `false`: turn it on once the theme's templates are in the site (`theme: "theme"`). */
8
+ templates?: boolean;
9
+ }
10
+ /** MkDocs' Markdown for a site moving from MkDocs, each a default under the site's own `markdown` options: Python-Markdown's reading (`dialect: "python-markdown"`: raw HTML blocks to their closing tag, lists at four spaces), its toc's heading ids, `!!! note` admonitions and `=== "Tab"` tabs as Material writes them, and `.md` links from the page; and with `templates`, MkDocs' context for a theme's templates. */
11
+ export function fromMkdocs(options?: FromMkdocsOptions): BuiltinPlugin;
@@ -0,0 +1,5 @@
1
+ // ssqch/from-vitepress: from ssqch.d.ts, the types `ssqch types` writes.
2
+ /// <reference path="./globals.d.ts" />
3
+ import type { BuiltinPlugin } from "ssqch";
4
+ /** VitePress's Markdown, for a site moving from VitePress, and VitePress's ways for `vuePlugin()`'s components (`useData()` and the rest from "vitepress", `@theme/`, and `./x.data` imports running its data loaders): Vue's `<script>` and `<style>` blocks and `<ClientOnly>` left out, VitePress's markup for headings (`header-anchor`), links (`.html` with `urls: "html"`, external ones in a new tab), code blocks and tables, its `tip`, `info`, `warning`, `danger`, `details`, `raw` and `code-group` containers, `[[toc]]`, and, under the site's own `markdown` options, its heading ids and email autolinks. A site's own hook or container template of the same name replaces VitePress's. Takes no options. */
5
+ export function fromVitepress(): BuiltinPlugin;