ssqch 0.7.1 → 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/minify.js CHANGED
@@ -1,3 +1,69 @@
1
- // ssqch/minify 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/minify 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
+ RustPlugin,
9
+ compilePlugin
10
+ } from "./chunk-TN6EEDX2.js";
11
+ import "./chunk-IRHRK7XB.js";
12
+ import "./chunk-NKXEPHRZ.js";
13
+ import "./chunk-AD3HAW3W.js";
14
+ import "./chunk-DDV6JEC2.js";
15
+ import "./chunk-EIT4ZDT4.js";
16
+ import {
17
+ closest
18
+ } from "./chunk-FVZ5JBRI.js";
19
+ import "./chunk-TDGBQNGW.js";
20
+ import "./chunk-UU43WIZG.js";
21
+ import "./chunk-C35KIPAR.js";
22
+ import "./chunk-CMUWRPSQ.js";
23
+ import {
24
+ BuildError
25
+ } from "./chunk-6XYSFG6V.js";
26
+ import "./chunk-VJWQSYEG.js";
27
+ import "./chunk-I3PS26CI.js";
28
+
29
+ // src/modules/minify.ts
30
+ import { fileURLToPath } from "node:url";
31
+ var OPTIONS = ["collapseWhitespace", "removeComments", "shortDoctype", "shortenAttributes"];
32
+ var WASM_FILE = fileURLToPath(new URL("../../wasm/minify.wasm", new URL("../src/modules/minify.ts", import.meta.url).href));
33
+ function minifier(options) {
34
+ return new RustPlugin(compilePlugin(WASM_FILE, WASM_FILE), options, WASM_FILE);
35
+ }
36
+ var shared;
37
+ function minifyPlugin(options = {}) {
38
+ return { name: "ssqch/minify", builtin: "ssqch/minify", options };
39
+ }
40
+ function minify(html, options = {}) {
41
+ for (const key of Object.keys(options)) {
42
+ if (!OPTIONS.includes(key)) {
43
+ const meant = closest(key, OPTIONS);
44
+ throw new TypeError(`minify(): unknown option "${key}"${meant ? ` (did you mean "${meant}"?)` : ""} (options: ${OPTIONS.join(", ")})`);
45
+ }
46
+ }
47
+ const { collapseWhitespace = true, removeComments = true, shortDoctype = true, shortenAttributes = true } = options;
48
+ const on = { collapseWhitespace: Boolean(collapseWhitespace), removeComments: Boolean(removeComments), shortDoctype: Boolean(shortDoctype), shortenAttributes: Boolean(shortenAttributes) };
49
+ shared ??= minifier({});
50
+ try {
51
+ return shared.filter("minify", [String(html), on]);
52
+ } catch (e) {
53
+ throw e instanceof BuildError ? new Error(`minify(): ${e.message}`) : e;
54
+ }
55
+ }
56
+ BUILTINS.set("ssqch/minify", (config, given) => {
57
+ const o = new Options(given, OPTIONS);
58
+ const on = {};
59
+ for (const key of OPTIONS) {
60
+ const value = o.bool(key);
61
+ if (value !== void 0) on[key] = value;
62
+ }
63
+ const plugin = minifier(on);
64
+ config.transforms.push(["minify-html", (content, page) => page.outputPath.endsWith(".html") ? plugin.transform(content, page) ?? content : content]);
65
+ });
66
+ export {
67
+ minify,
68
+ minifyPlugin
69
+ };
package/lib/redirects.js CHANGED
@@ -1,3 +1,152 @@
1
- // ssqch/redirects 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/redirects 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
+ escapeHtml,
10
+ withBase
11
+ } from "./chunk-TN6EEDX2.js";
12
+ import "./chunk-IRHRK7XB.js";
13
+ import "./chunk-NKXEPHRZ.js";
14
+ import "./chunk-AD3HAW3W.js";
15
+ import "./chunk-DDV6JEC2.js";
16
+ import "./chunk-EIT4ZDT4.js";
17
+ import "./chunk-FVZ5JBRI.js";
18
+ import "./chunk-TDGBQNGW.js";
19
+ import "./chunk-UU43WIZG.js";
20
+ import "./chunk-C35KIPAR.js";
21
+ import "./chunk-CMUWRPSQ.js";
22
+ import {
23
+ bail,
24
+ context
25
+ } from "./chunk-6XYSFG6V.js";
26
+ import {
27
+ compareText,
28
+ displayPath,
29
+ isInside,
30
+ relative,
31
+ slashes
32
+ } from "./chunk-VJWQSYEG.js";
33
+ import "./chunk-I3PS26CI.js";
34
+
35
+ // src/modules/redirects.ts
36
+ function redirectsPlugin(options = {}) {
37
+ return { name: "ssqch/redirects", builtin: "ssqch/redirects", options };
38
+ }
39
+ function checkPath(path) {
40
+ if (!path.startsWith("/") || path.split("/").includes("..") || /[?# ]/.test(path)) bail(`${debugString(path)} must be a URL path starting with /, like "/old-post/"`);
41
+ }
42
+ function redirectPage(to) {
43
+ const js = jsString(to);
44
+ const html = escapeHtml(to);
45
+ return `<!doctype html>
46
+ <html lang="en">
47
+ <meta charset="utf-8">
48
+ <title>Redirecting to ${html}</title>
49
+ <link rel="canonical" href="${html}">
50
+ <meta name="robots" content="noindex">
51
+ <meta http-equiv="refresh" content="0; url=${html}">
52
+ <script>location.replace(${js} + location.hash)</script>
53
+ <p>This page has moved to <a href="${html}">${html}</a>.</p>
54
+ </html>
55
+ `;
56
+ }
57
+ function jsString(to) {
58
+ let out = '"';
59
+ for (const c of to) {
60
+ if (c === '"') out += '\\"';
61
+ else if (c === "\\") out += "\\\\";
62
+ else if (c === "<") out += "\\u003c";
63
+ else if (c.charCodeAt(0) < 32) out += `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`;
64
+ else out += c;
65
+ }
66
+ return `${out}"`;
67
+ }
68
+ var typeOf = (v) => v === null ? "object" : typeof v;
69
+ function hasExtension(from) {
70
+ const last = from.slice(from.lastIndexOf("/") + 1);
71
+ const dot = last.lastIndexOf(".");
72
+ if (dot <= 0) return false;
73
+ const ext = last.slice(dot + 1);
74
+ return ext.length >= 1 && ext.length <= 5 && /^[A-Za-z]+$/.test(ext);
75
+ }
76
+ var trimSlashes = (url) => url.replace(/\/+$/, "");
77
+ function asWritten(alias) {
78
+ if (!(alias instanceof Date) || Number.isNaN(alias.getTime())) return alias;
79
+ const iso = alias.toISOString();
80
+ return iso.endsWith("T00:00:00.000Z") ? iso.slice(0, 10) : iso.replace(/\.000Z$/, "Z");
81
+ }
82
+ BUILTINS.set("ssqch/redirects", (config, given) => {
83
+ const o = new Options(given, ["pages", "netlify", "redirects"]);
84
+ const pages = o.bool("pages") ?? true;
85
+ const netlify = o.bool("netlify") ?? false;
86
+ const redirects = /* @__PURE__ */ new Map();
87
+ const map = o.get("redirects");
88
+ if (map !== void 0) {
89
+ if (typeof map !== "object" || Array.isArray(map)) bail('redirects must be an object of { "/old/": "/new/" }');
90
+ for (const [from, to] of Object.entries(map)) {
91
+ if (typeof to !== "string") bail(`redirects.${from}: the new URL must be a string`);
92
+ redirects.set(from, to);
93
+ }
94
+ }
95
+ if (!pages && !netlify) bail("pages and netlify are both false, so there's nothing to write; turn one on");
96
+ for (const from of redirects.keys()) {
97
+ try {
98
+ checkPath(from);
99
+ } catch (e) {
100
+ throw context(e, "redirects");
101
+ }
102
+ }
103
+ config.generators.push(["ssqch/redirects", (config2, summaries) => {
104
+ const byUrl = /* @__PURE__ */ new Map();
105
+ for (const p of summaries) if (!byUrl.has(trimSlashes(p.url))) byUrl.set(trimSlashes(p.url), p);
106
+ const all = /* @__PURE__ */ new Map();
107
+ for (const [from, to] of redirects) all.set(from, [to, "the redirects option"]);
108
+ for (const page of summaries) {
109
+ const source = displayPath(config2.root, page.inputPath);
110
+ const given2 = asWritten(page.data.aliases);
111
+ if (given2 === void 0 || given2 === null) continue;
112
+ let aliases;
113
+ if (typeof given2 === "string") aliases = [given2];
114
+ else if (Array.isArray(given2)) aliases = given2.map(asWritten);
115
+ else bail(`${source}: aliases must be a URL path or a list of them, not ${typeOf(given2)}`);
116
+ for (const each of aliases) {
117
+ if (typeof each !== "string") bail(`${source}: aliases must be URL paths, not ${typeOf(each)}`);
118
+ let alias = each;
119
+ if (!alias.startsWith("/")) alias = `/${alias}`;
120
+ try {
121
+ checkPath(alias);
122
+ } catch (e) {
123
+ throw context(e, `${source}: aliases`);
124
+ }
125
+ const other = all.get(alias);
126
+ all.set(alias, [page.url, source]);
127
+ if (other) bail(`${other[1]} and ${source} both redirect ${alias}`);
128
+ }
129
+ }
130
+ const files = [];
131
+ let lines = "";
132
+ for (const [from, [to, source]] of [...all].sort((a, b) => compareText(a[0], b[0]))) {
133
+ const page = byUrl.get(trimSlashes(from));
134
+ if (page) {
135
+ const input = isInside(config2.root, page.inputPath) ? relative(config2.root, page.inputPath) : slashes(page.inputPath);
136
+ bail(`${source}: ${from} is the URL of ${input}, so it can't redirect to ${to}`);
137
+ }
138
+ if (pages) {
139
+ const path = from.endsWith("/") || hasExtension(from) ? from : `${from}/`;
140
+ const target = withBase(config2.base, to);
141
+ files.push({ path, contents: redirectPage(target), hook: { name: "redirect", value: { from, to: target } } });
142
+ }
143
+ lines += `${from} ${to} 301
144
+ `;
145
+ }
146
+ if (netlify && lines !== "") files.push({ path: "/_redirects", contents: lines, append: true });
147
+ return files;
148
+ }]);
149
+ });
150
+ export {
151
+ redirectsPlugin
152
+ };
package/lib/rss.js CHANGED
@@ -1,3 +1,139 @@
1
- // ssqch/rss 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/rss 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
+ feedImages
5
+ } from "./chunk-NUKCUDC4.js";
6
+ import {
7
+ Options
8
+ } from "./chunk-JRT7TQQP.js";
9
+ import {
10
+ BUILTINS,
11
+ rewriteHtml
12
+ } from "./chunk-TN6EEDX2.js";
13
+ import "./chunk-IRHRK7XB.js";
14
+ import "./chunk-NKXEPHRZ.js";
15
+ import "./chunk-AD3HAW3W.js";
16
+ import "./chunk-DDV6JEC2.js";
17
+ import "./chunk-EIT4ZDT4.js";
18
+ import "./chunk-FVZ5JBRI.js";
19
+ import "./chunk-TDGBQNGW.js";
20
+ import "./chunk-UU43WIZG.js";
21
+ import "./chunk-C35KIPAR.js";
22
+ import "./chunk-CMUWRPSQ.js";
23
+ import {
24
+ bail,
25
+ toDate
26
+ } from "./chunk-6XYSFG6V.js";
27
+ import "./chunk-VJWQSYEG.js";
28
+ import "./chunk-I3PS26CI.js";
29
+
30
+ // src/modules/rss.ts
31
+ function rssPlugin(_options) {
32
+ return { name: "ssqch/rss", builtin: "ssqch/rss" };
33
+ }
34
+ var output = (v) => v === void 0 || v === null ? "" : v instanceof Date ? v.toISOString() : String(v);
35
+ function shown(v) {
36
+ if (v === void 0) return "undefined";
37
+ if (typeof v === "function") return "[Function]";
38
+ if (v instanceof Date) return Number.isNaN(v.getTime()) ? "Invalid Date" : `Date(${v.toISOString().replace(/\.\d+Z$/, "+00:00")})`;
39
+ if (typeof v === "number" && !Number.isFinite(v)) return String(v);
40
+ try {
41
+ return JSON.stringify(v) ?? "null";
42
+ } catch {
43
+ return "null";
44
+ }
45
+ }
46
+ var two = (n) => String(n).padStart(2, "0");
47
+ var DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
48
+ var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
49
+ function getNewestCollectionItemDate(items) {
50
+ let newest;
51
+ for (const item of Array.isArray(items) ? items : []) {
52
+ const date = toDate(item === null || item === void 0 ? void 0 : item.date);
53
+ if (date !== void 0 && (newest === void 0 || date.getTime() > newest.getTime())) newest = date;
54
+ }
55
+ return newest;
56
+ }
57
+ function dateToRfc3339(date) {
58
+ const d = toDate(date);
59
+ if (d === void 0) bail(`dateToRfc3339: not a date: ${shown(date)}`);
60
+ return `${year(d)}-${two(d.getUTCMonth() + 1)}-${two(d.getUTCDate())}T${two(d.getUTCHours())}:${two(d.getUTCMinutes())}:${two(d.getUTCSeconds())}Z`;
61
+ }
62
+ function dateToRfc822(date) {
63
+ const d = toDate(date);
64
+ if (d === void 0) bail(`dateToRfc822: not a date: ${shown(date)}`);
65
+ return `${DAYS[d.getUTCDay()]}, ${two(d.getUTCDate())} ${MONTHS[d.getUTCMonth()]} ${year(d)} ${two(d.getUTCHours())}:${two(d.getUTCMinutes())}:${two(d.getUTCSeconds())} +0000`;
66
+ }
67
+ function year(d) {
68
+ const y = d.getUTCFullYear();
69
+ if (y < 0) return `-${String(-y).padStart(4, "0")}`;
70
+ return y > 9999 ? `+${y}` : String(y).padStart(4, "0");
71
+ }
72
+ function absoluteUrl(url, base) {
73
+ const text = String(url);
74
+ try {
75
+ return new URL(text, String(base)).toString();
76
+ } catch {
77
+ return text;
78
+ }
79
+ }
80
+ function htmlToAbsoluteUrls(html, base) {
81
+ const baseUrl = String(base);
82
+ return rewriteHtml(String(html ?? ""), {
83
+ tag(el) {
84
+ for (const attr of ["href", "src", "poster", "srcset"]) {
85
+ const v = el.get(attr);
86
+ if (v === void 0) continue;
87
+ if (attr !== "srcset") {
88
+ el.set(attr, absoluteUrl(v, baseUrl));
89
+ continue;
90
+ }
91
+ const candidates = v.split(",").map((c) => {
92
+ const candidate = c.trim();
93
+ const space = candidate.indexOf(" ");
94
+ return space === -1 ? absoluteUrl(candidate, baseUrl) : `${absoluteUrl(candidate.slice(0, space), baseUrl)} ${candidate.slice(space + 1)}`;
95
+ });
96
+ el.set(attr, candidates.join(", "));
97
+ }
98
+ }
99
+ });
100
+ }
101
+ function feedHtml(html, base, options) {
102
+ const feedImages2 = feedImages;
103
+ if (typeof feedImages2 !== "function") bail("feedHtml() isn't in the Node build of ssqch yet (the move to Node, stage 5)");
104
+ const source = html === void 0 || html === null ? "" : String(html);
105
+ const done = feedImages2(source, String(base), options);
106
+ return typeof done === "string" ? htmlToAbsoluteUrls(done, base) : done.then((h) => htmlToAbsoluteUrls(h, base));
107
+ }
108
+ BUILTINS.set("ssqch/rss", (config, options) => {
109
+ new Options(options, []);
110
+ const filters = config.filters;
111
+ filters.set("getNewestCollectionItemDate", (items) => getNewestCollectionItemDate(items));
112
+ filters.set("dateToRfc3339", (date) => dateToRfc3339(date));
113
+ filters.set("dateToRfc822", (date) => dateToRfc822(date));
114
+ filters.set("absoluteUrl", (url, base) => absoluteUrl(output(url), output(base)));
115
+ filters.set("htmlToAbsoluteUrls", (html, base) => htmlToAbsoluteUrls(output(html), output(base)));
116
+ const unprefixed = (e) => {
117
+ if (e instanceof Error && e.message.startsWith("feedHtml(): ")) e.message = e.message.slice("feedHtml(): ".length);
118
+ return e;
119
+ };
120
+ filters.set("feedHtml", (html, base, options2) => {
121
+ try {
122
+ const done = feedHtml(html, base, options2);
123
+ return typeof done === "string" ? done : done.catch((e) => {
124
+ throw unprefixed(e);
125
+ });
126
+ } catch (e) {
127
+ throw unprefixed(e);
128
+ }
129
+ });
130
+ });
131
+ export {
132
+ absoluteUrl,
133
+ dateToRfc3339,
134
+ dateToRfc822,
135
+ feedHtml,
136
+ getNewestCollectionItemDate,
137
+ htmlToAbsoluteUrls,
138
+ rssPlugin
139
+ };
package/lib/sass.js CHANGED
@@ -1,3 +1,221 @@
1
- // ssqch/sass 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/sass 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
+ startReading
5
+ } from "./chunk-3NYSSA2C.js";
6
+ import {
7
+ Options
8
+ } from "./chunk-JRT7TQQP.js";
9
+ import {
10
+ BUILTINS,
11
+ cssWithBase,
12
+ debugString,
13
+ wasi
14
+ } from "./chunk-TN6EEDX2.js";
15
+ import "./chunk-IRHRK7XB.js";
16
+ import "./chunk-NKXEPHRZ.js";
17
+ import "./chunk-AD3HAW3W.js";
18
+ import "./chunk-DDV6JEC2.js";
19
+ import {
20
+ WebAssembly
21
+ } from "./chunk-EIT4ZDT4.js";
22
+ import "./chunk-FVZ5JBRI.js";
23
+ import "./chunk-TDGBQNGW.js";
24
+ import "./chunk-UU43WIZG.js";
25
+ import "./chunk-C35KIPAR.js";
26
+ import "./chunk-CMUWRPSQ.js";
27
+ import {
28
+ BuildError,
29
+ bail,
30
+ messageOf
31
+ } from "./chunk-6XYSFG6V.js";
32
+ import {
33
+ comparePaths,
34
+ displayPath,
35
+ isInside,
36
+ realPath,
37
+ slashes
38
+ } from "./chunk-VJWQSYEG.js";
39
+ import "./chunk-I3PS26CI.js";
40
+
41
+ // src/modules/sass.ts
42
+ import fs from "node:fs";
43
+ import path from "node:path";
44
+ import { fileURLToPath } from "node:url";
45
+ function sassPlugin(options = {}) {
46
+ return { name: "ssqch/sass", builtin: "ssqch/sass", options };
47
+ }
48
+ var isSass = (file) => file.endsWith(".scss") || file.endsWith(".sass");
49
+ function entries(root, from, to) {
50
+ const src = path.resolve(root, from);
51
+ const stat = fs.statSync(src, { throwIfNoEntry: false });
52
+ if (stat?.isFile()) {
53
+ if (!isSass(src)) bail(`files: ${from} isn't a .scss or .sass file`);
54
+ return [[src, to.endsWith("/") ? `${to}${path.basename(src).replace(/\.s[ac]ss$/, "")}.css` : to]];
55
+ }
56
+ if (!stat?.isDirectory()) bail(`files: ${from} doesn't exist`);
57
+ const out = [];
58
+ const walk = (dir) => {
59
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
60
+ const file = path.join(dir, entry.name);
61
+ if (entry.isDirectory()) walk(file);
62
+ else if (entry.isFile() && isSass(entry.name) && !entry.name.startsWith("_")) {
63
+ out.push([file, `${to.replace(/\/+$/, "")}/${slashes(path.relative(src, file)).replace(/\.s[ac]ss$/, "")}.css`]);
64
+ }
65
+ }
66
+ };
67
+ walk(src);
68
+ return out.sort((a, b) => comparePaths(a[0], b[0]) || (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));
69
+ }
70
+ BUILTINS.set("ssqch/sass", (config, given) => {
71
+ const o = new Options(given, ["files", "style", "loadPaths"]);
72
+ const files = [];
73
+ const map = o.get("files");
74
+ if (map !== void 0) {
75
+ if (typeof map !== "object" || Array.isArray(map)) bail('files must be an object of { source: "/output" }');
76
+ for (const [from, to] of Object.entries(map)) {
77
+ if (typeof to !== "string") bail(`files.${from}: the output must be a URL path string`);
78
+ files.push([from, to]);
79
+ }
80
+ }
81
+ const style = o.string("style");
82
+ if (style !== void 0 && style !== "compressed" && style !== "expanded") bail(`style must be "compressed" or "expanded", not ${debugString(style)}`);
83
+ const loadPaths = o.list("loadPaths") ?? [];
84
+ if (!files.length) bail('files is required: { "src/scss": "/css" } or { "src/app.scss": "/app.css" }');
85
+ for (const [from, to] of files) {
86
+ if (!to.startsWith("/") || to.includes("..")) bail(`files: ${debugString(to)} must be a URL path starting with / (like "/css/app.css" or "/css")`);
87
+ if (from === "") bail("files: a source path can't be empty");
88
+ }
89
+ for (const [from] of files) {
90
+ config.watch.push(from);
91
+ const slash = Math.max(from.lastIndexOf("/"), from.lastIndexOf(path.sep));
92
+ const dir = slash < 0 ? "" : slash === 0 ? from.slice(0, 1) : from.slice(0, slash);
93
+ if (isSass(from) && dir !== "") config.watch.push(dir);
94
+ }
95
+ for (const dir of loadPaths) config.watch.push(dir);
96
+ let count;
97
+ config.fileBuilders.push(["ssqch/sass", (config2) => {
98
+ const chosen = style ?? (config2.env === "production" && !config2.serving ? "compressed" : "expanded");
99
+ const used = startReading(config2, "ssqch/sass");
100
+ const compiler = new Compiler(config2.root, used);
101
+ const options = JSON.stringify({ style: chosen, loadPaths: loadPaths.map((dir) => compiler.name(path.resolve(config2.root, dir))) });
102
+ const out = [];
103
+ for (const [from, to] of files) {
104
+ for (const [src, url] of entries(config2.root, from, to)) {
105
+ const shown = displayPath(config2.root, src);
106
+ const css = compiler.compile(src, options, shown);
107
+ out.push({ path: url, contents: cssWithBase(config2.base, css) });
108
+ }
109
+ }
110
+ count = [out.length, chosen];
111
+ return out;
112
+ }]);
113
+ config.summaries.push(["Sass", () => count === void 0 ? void 0 : `${count[0]} file${count[0] === 1 ? "" : "s"} (${count[1]})`]);
114
+ });
115
+ var WASM_FILE = fileURLToPath(new URL("../../wasm/sass.wasm", new URL("../src/modules/sass.ts", import.meta.url).href));
116
+ var compiled;
117
+ var current;
118
+ var active;
119
+ var Compiler = class {
120
+ root;
121
+ used;
122
+ constructor(root, used) {
123
+ this.root = root;
124
+ this.used = used;
125
+ }
126
+ /** A path as grass sees it: from the root for the site's own files, else whole; with `/`. */
127
+ name(file) {
128
+ return isInside(this.root, file) && file !== this.root ? slashes(path.relative(this.root, file)) : slashes(file);
129
+ }
130
+ /** A path grass gave back, as a real one. */
131
+ file(name) {
132
+ return path.resolve(this.root, name);
133
+ }
134
+ compile(src, options, shown) {
135
+ const x = instance();
136
+ const parts = [this.name(src), options];
137
+ const lens = parts.map((p) => Buffer.byteLength(p, "utf8"));
138
+ const ptr = x.sass_alloc(lens[0] + lens[1]);
139
+ const bytes = Buffer.from(x.memory.buffer);
140
+ bytes.write(parts[0], ptr, lens[0], "utf8");
141
+ bytes.write(parts[1], ptr + lens[0], lens[1], "utf8");
142
+ active = this;
143
+ let status;
144
+ try {
145
+ status = x.sass_compile(ptr, lens[0], lens[1]);
146
+ } catch (e) {
147
+ current = void 0;
148
+ let message = messageOf(e);
149
+ if (e instanceof WebAssembly.RuntimeError) {
150
+ try {
151
+ x.sass_panic();
152
+ message = resultOf(x) || message;
153
+ } catch {
154
+ }
155
+ }
156
+ throw new BuildError(`compiling ${shown}: ssqch's Sass crashed (${message.replace(/\s*\n\s*/g, " ")})`);
157
+ } finally {
158
+ active = void 0;
159
+ }
160
+ const text = resultOf(x);
161
+ if (status !== 0) throw new BuildError(`compiling ${shown}: ${shown}: ${text}`);
162
+ return text;
163
+ }
164
+ };
165
+ function resultOf(x) {
166
+ const ptr = x.sass_result_ptr();
167
+ return Buffer.from(x.memory.buffer).toString("utf8", ptr, ptr + x.sass_result_len());
168
+ }
169
+ function instance() {
170
+ if (current) return current;
171
+ if (!compiled) {
172
+ let bytes;
173
+ try {
174
+ bytes = fs.readFileSync(WASM_FILE);
175
+ } catch (e) {
176
+ throw new BuildError(`ssqch's Sass isn't there (${WASM_FILE}: ${messageOf(e)}); build it with node packages/ssqch/scripts/build-wasm.ts sass`);
177
+ }
178
+ compiled = new WebAssembly.Module(bytes);
179
+ }
180
+ let x;
181
+ const memory = () => x.memory;
182
+ const text = (ptr, len) => Buffer.from(x.memory.buffer).toString("utf8", ptr, ptr + len);
183
+ const reply = (out, status, answer) => {
184
+ const data = typeof answer === "string" ? Buffer.from(answer, "utf8") : answer;
185
+ const ptr = x.sass_alloc(data.length);
186
+ const bytes = Buffer.from(x.memory.buffer);
187
+ bytes.set(data, ptr);
188
+ bytes.writeUInt32LE(ptr, out);
189
+ bytes.writeUInt32LE(data.length, out + 4);
190
+ return status;
191
+ };
192
+ const stat = (ptr, len) => fs.statSync(active.file(text(ptr, len)), { throwIfNoEntry: false });
193
+ const host = {
194
+ is_file: (ptr, len) => stat(ptr, len)?.isFile() ? 1 : 0,
195
+ is_dir: (ptr, len) => stat(ptr, len)?.isDirectory() ? 1 : 0,
196
+ read: (ptr, len, out) => {
197
+ const file = active.file(text(ptr, len));
198
+ try {
199
+ const data = fs.readFileSync(file);
200
+ active.used.add(realPath(file));
201
+ return reply(out, 0, data);
202
+ } catch (e) {
203
+ return reply(out, 1, messageOf(e));
204
+ }
205
+ },
206
+ // The same file under two names is one module (grass uses it to load each once).
207
+ canonicalize: (ptr, len, out) => {
208
+ try {
209
+ return reply(out, 0, active.name(fs.realpathSync.native(active.file(text(ptr, len)))));
210
+ } catch (e) {
211
+ return reply(out, 1, messageOf(e));
212
+ }
213
+ }
214
+ };
215
+ x = new WebAssembly.Instance(compiled, { wasi_snapshot_preview1: wasi(memory), ssqch: host }).exports;
216
+ x._initialize();
217
+ return current = x;
218
+ }
219
+ export {
220
+ sassPlugin
221
+ };