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.
Files changed (155) hide show
  1. package/README.md +8 -4
  2. package/bin/ssqch.js +14 -48
  3. package/bundled/README.md +1314 -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 +540 -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-jekyll.md +79 -0
  81. package/bundled/trailheads/from-mkdocs.md +45 -0
  82. package/bundled/trailheads/from-zola.md +71 -0
  83. package/lib/assets.js +235 -3
  84. package/lib/chunk-3A647I3N.js +384 -0
  85. package/lib/chunk-3GYLOC6Y.js +1017 -0
  86. package/lib/chunk-3K3ANWZ2.js +118 -0
  87. package/lib/chunk-3NYSSA2C.js +22 -0
  88. package/lib/chunk-47P4YREZ.js +1287 -0
  89. package/lib/chunk-4Q6WMTER.js +32 -0
  90. package/lib/chunk-76NTVE34.js +338 -0
  91. package/lib/chunk-7PWCYHTJ.js +1350 -0
  92. package/lib/chunk-7RDRZHJD.js +217 -0
  93. package/lib/chunk-7SD7K567.js +57 -0
  94. package/lib/chunk-7XLK2GEG.js +54 -0
  95. package/lib/chunk-AD3HAW3W.js +10 -0
  96. package/lib/chunk-BEGC7YP6.js +502 -0
  97. package/lib/chunk-CMUWRPSQ.js +113 -0
  98. package/lib/chunk-CZ4XQC56.js +999 -0
  99. package/lib/chunk-D2XE2GTY.js +71 -0
  100. package/lib/chunk-DDV6JEC2.js +46 -0
  101. package/lib/chunk-DELWRJAO.js +37409 -0
  102. package/lib/chunk-DELWRJAO.js.LEGAL.txt +27 -0
  103. package/lib/chunk-F65YUXZ7.js +334 -0
  104. package/lib/chunk-FVZ5JBRI.js +115 -0
  105. package/lib/chunk-GRWMGC7D.js +4435 -0
  106. package/lib/chunk-GRWMGC7D.js.LEGAL.txt +41 -0
  107. package/lib/chunk-GUKSZ2XM.js +207 -0
  108. package/lib/chunk-HPXAZ2HU.js +251 -0
  109. package/lib/chunk-HXCLCXRT.js +20 -0
  110. package/lib/chunk-I3PS26CI.js +48 -0
  111. package/lib/chunk-IAFM5ITE.js +11 -0
  112. package/lib/chunk-II5DEH3Q.js +209 -0
  113. package/lib/chunk-IJWHOFRP.js +44 -0
  114. package/lib/chunk-LPHNACE4.js +29 -0
  115. package/lib/chunk-MI6EJWA2.js +175 -0
  116. package/lib/chunk-NCWFYT74.js +1541 -0
  117. package/lib/chunk-NKXEPHRZ.js +136 -0
  118. package/lib/chunk-NNUKIGOO.js +160 -0
  119. package/lib/chunk-R7K3D5W5.js +3957 -0
  120. package/lib/chunk-RNJFPFXE.js +29 -0
  121. package/lib/chunk-SF4I6Z7S.js +25 -0
  122. package/lib/chunk-SURPOAW7.js +44 -0
  123. package/lib/chunk-SXMJ52IK.js +572 -0
  124. package/lib/chunk-TICWN55Z.js +20 -0
  125. package/lib/chunk-TVU3OPPK.js +146 -0
  126. package/lib/chunk-UU43WIZG.js +29 -0
  127. package/lib/chunk-VJWQSYEG.js +119 -0
  128. package/lib/chunk-XMXBHXZR.js +75 -0
  129. package/lib/chunk-YTHQBMDJ.js +211 -0
  130. package/lib/cli.js +547 -0
  131. package/lib/elements.js +180 -3
  132. package/lib/image.js +27 -3
  133. package/lib/links.js +464 -3
  134. package/lib/minify.js +69 -3
  135. package/lib/redirects.js +152 -3
  136. package/lib/rss.js +139 -3
  137. package/lib/sass.js +256 -3
  138. package/lib/sitemap.js +113 -3
  139. package/lib/ssqch.js +28 -0
  140. package/package.json +83 -80
  141. package/src/serve/live.js +174 -0
  142. package/src/serve/not-found.html +31 -0
  143. package/types/globals.d.ts +3 -2
  144. package/types/image.d.ts +7 -3
  145. package/types/index.d.ts +28 -9
  146. package/types/links.d.ts +1 -1
  147. package/types/minify.d.ts +1 -1
  148. package/types/rss.d.ts +1 -1
  149. package/types/sass.d.ts +1 -1
  150. package/types/sitemap.d.ts +2 -0
  151. package/wasm/markdown.wasm +0 -0
  152. package/wasm/minify.wasm +0 -0
  153. package/wasm/sass.wasm +0 -0
  154. package/lib/index.js +0 -3
  155. package/platforms.json +0 -6
package/lib/sitemap.js CHANGED
@@ -1,3 +1,113 @@
1
- // ssqch/sitemap 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/sitemap 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-7SD7K567.js";
6
+ import {
7
+ BUILTINS,
8
+ debugString,
9
+ escapeHtml,
10
+ isoDay
11
+ } from "./chunk-R7K3D5W5.js";
12
+ import "./chunk-7XLK2GEG.js";
13
+ import "./chunk-NKXEPHRZ.js";
14
+ import "./chunk-AD3HAW3W.js";
15
+ import "./chunk-DDV6JEC2.js";
16
+ import "./chunk-NCWFYT74.js";
17
+ import "./chunk-FVZ5JBRI.js";
18
+ import {
19
+ globSet
20
+ } from "./chunk-HPXAZ2HU.js";
21
+ import "./chunk-UU43WIZG.js";
22
+ import "./chunk-76NTVE34.js";
23
+ import "./chunk-CMUWRPSQ.js";
24
+ import {
25
+ bail,
26
+ toDate
27
+ } from "./chunk-GRWMGC7D.js";
28
+ import {
29
+ compareText
30
+ } from "./chunk-VJWQSYEG.js";
31
+ import "./chunk-I3PS26CI.js";
32
+
33
+ // src/modules/sitemap.ts
34
+ import path from "node:path";
35
+ function sitemapPlugin(options = {}) {
36
+ return { name: "ssqch/sitemap", builtin: "ssqch/sitemap", options };
37
+ }
38
+ function isLaterPage(data) {
39
+ const p = data.pagination;
40
+ const number = typeof p?.pageNumber === "number" ? p.pageNumber : 0;
41
+ const size = typeof p?.size === "number" ? p.size : 1;
42
+ return number > 0 && size > 1;
43
+ }
44
+ BUILTINS.set("ssqch/sitemap", (config, given) => {
45
+ const o = new Options(given, ["url", "exclude", "lastmod", "output", "paginated", "alternates"]);
46
+ const alternates = o.get("alternates");
47
+ if (alternates !== void 0 && typeof alternates !== "function") bail(`alternates must be a function that gets each page and returns its translations, like (page) => [{ hreflang: "fr", href: "/fr/" }] (got ${typeof alternates})`);
48
+ const url = o.string("url");
49
+ if (url === void 0) bail(`url is required: the site's address, like "https://example.com"`);
50
+ const exclude = o.list("exclude") ?? [];
51
+ const lastmod = o.bool("lastmod") ?? true;
52
+ const output = o.string("output") ?? "/sitemap.xml";
53
+ const paginated = o.bool("paginated") ?? false;
54
+ if (!(url.startsWith("https://") || url.startsWith("http://"))) bail(`url must be the site's address, like "https://example.com" (got ${debugString(url)})`);
55
+ if (!output.startsWith("/") || output.endsWith("/")) bail(`output must be a URL path to a file, like "/sitemap.xml" (got ${debugString(output)})`);
56
+ const matchers = exclude.map((glob) => {
57
+ if (!glob.startsWith("/")) bail(`exclude: ${debugString(glob)} must be a URL path or glob starting with /, like "/tags/**"`);
58
+ return globSet("exclude", [glob]);
59
+ });
60
+ const excluded = (url2) => matchers.some((m) => m(url2));
61
+ config.generators.push(["ssqch/sitemap", (config2, pages) => {
62
+ const trimmed = url.replace(/\/+$/, "");
63
+ const withBase = trimmed.endsWith(config2.base) ? trimmed : trimmed + config2.base;
64
+ const entries = [];
65
+ const absolute = (href) => href.startsWith("/") ? withBase + href : href;
66
+ const linksOf = (p) => {
67
+ if (!alternates) return [];
68
+ let out;
69
+ try {
70
+ out = alternates(p);
71
+ } catch (e) {
72
+ bail(`alternates(), for ${p.url}: ${e instanceof Error ? e.message : String(e)}`);
73
+ }
74
+ if (out === void 0 || out === null) return [];
75
+ if (out instanceof Promise) bail("alternates() answered with a promise; it has to answer at once (work the translations out in data or a collection first)");
76
+ if (!Array.isArray(out)) bail(`alternates(), for ${p.url}: expected a list of { hreflang, href } (got ${typeof out})`);
77
+ return out.map((a) => {
78
+ const { hreflang, href } = a ?? {};
79
+ if (typeof hreflang !== "string" || hreflang === "" || typeof href !== "string" || !(href.startsWith("/") || /^https?:\/\//.test(href))) bail(`alternates(), for ${p.url}: each one is { hreflang: "fr", href: "/fr/page/" } (an href from the site's root, or a whole address), got ${JSON.stringify(a) ?? String(a)}`);
80
+ return [hreflang, absolute(href)];
81
+ });
82
+ };
83
+ for (const p of pages) {
84
+ if (path.extname(p.outputPath) !== ".html") continue;
85
+ if (p.data.sitemap === false) continue;
86
+ if (!paginated && isLaterPage(p.data)) continue;
87
+ if (p.url === "/404.html" || p.url === "/404/") continue;
88
+ if (excluded(p.url)) continue;
89
+ entries.push([p.url, isoDay(toDate(p.data.page?.lastModified) ?? p.date), linksOf(p)]);
90
+ }
91
+ entries.sort((a, b) => compareText(a[0], b[0]) || compareText(a[1], b[1]));
92
+ const loc = escapeHtml(withBase);
93
+ const xhtml = entries.some((e) => e[2].length) ? ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' : "";
94
+ let xml = `<?xml version="1.0" encoding="utf-8"?>
95
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${xhtml}>
96
+ `;
97
+ for (const [pageUrl, date, links] of entries) {
98
+ xml += ` <url>
99
+ <loc>${loc}${escapeHtml(pageUrl)}</loc>
100
+ `;
101
+ for (const [hreflang, href] of links) xml += ` <xhtml:link rel="alternate" hreflang="${escapeHtml(hreflang)}" href="${escapeHtml(href)}"/>
102
+ `;
103
+ if (lastmod) xml += ` <lastmod>${date}</lastmod>
104
+ `;
105
+ xml += " </url>\n";
106
+ }
107
+ xml += "</urlset>\n";
108
+ return [{ path: output, contents: xml }];
109
+ }]);
110
+ });
111
+ export {
112
+ sitemapPlugin
113
+ };
package/lib/ssqch.js ADDED
@@ -0,0 +1,28 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import {
4
+ api_default,
5
+ defineConfig,
6
+ files,
7
+ markdown,
8
+ readData,
9
+ slugger,
10
+ slugify
11
+ } from "./chunk-NCWFYT74.js";
12
+ import "./chunk-FVZ5JBRI.js";
13
+ import "./chunk-HPXAZ2HU.js";
14
+ import "./chunk-UU43WIZG.js";
15
+ import "./chunk-76NTVE34.js";
16
+ import "./chunk-CMUWRPSQ.js";
17
+ import "./chunk-GRWMGC7D.js";
18
+ import "./chunk-VJWQSYEG.js";
19
+ import "./chunk-I3PS26CI.js";
20
+ export {
21
+ api_default as default,
22
+ defineConfig,
23
+ files,
24
+ markdown,
25
+ readData,
26
+ slugger,
27
+ slugify
28
+ };
package/package.json CHANGED
@@ -1,82 +1,85 @@
1
1
  {
2
- "name": "ssqch",
3
- "description": "SiteSquatch, a fast static site generator configured with JavaScript",
4
- "version": "0.7.1",
5
- "license": "MIT",
6
- "homepage": "https://github.com/reverentgeek/sitesquatch#readme",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/reverentgeek/sitesquatch.git"
10
- },
11
- "bugs": "https://github.com/reverentgeek/sitesquatch/issues",
12
- "keywords": [
13
- "static site generator",
14
- "ssg",
15
- "blog",
16
- "markdown",
17
- "jinja",
18
- "liquid"
19
- ],
20
- "bin": {
21
- "ssqch": "bin/ssqch.js"
22
- },
23
- "types": "./types/index.d.ts",
24
- "exports": {
25
- ".": {
26
- "types": "./types/index.d.ts",
27
- "default": "./lib/index.js"
28
- },
29
- "./image": {
30
- "types": "./types/image.d.ts",
31
- "default": "./lib/image.js"
32
- },
33
- "./rss": {
34
- "types": "./types/rss.d.ts",
35
- "default": "./lib/rss.js"
36
- },
37
- "./minify": {
38
- "types": "./types/minify.d.ts",
39
- "default": "./lib/minify.js"
40
- },
41
- "./assets": {
42
- "types": "./types/assets.d.ts",
43
- "default": "./lib/assets.js"
44
- },
45
- "./links": {
46
- "types": "./types/links.d.ts",
47
- "default": "./lib/links.js"
48
- },
49
- "./sitemap": {
50
- "types": "./types/sitemap.d.ts",
51
- "default": "./lib/sitemap.js"
52
- },
53
- "./elements": {
54
- "types": "./types/elements.d.ts",
55
- "default": "./lib/elements.js"
56
- },
57
- "./redirects": {
58
- "types": "./types/redirects.d.ts",
59
- "default": "./lib/redirects.js"
60
- },
61
- "./sass": {
62
- "types": "./types/sass.d.ts",
63
- "default": "./lib/sass.js"
64
- },
65
- "./package.json": "./package.json"
66
- },
67
- "files": [
68
- "bin",
69
- "lib",
70
- "types",
71
- "platforms.json"
72
- ],
73
- "engines": {
74
- "node": ">=18"
75
- },
76
- "optionalDependencies": {
77
- "@ssqch/darwin-arm64": "0.7.1",
78
- "@ssqch/darwin-x64": "0.7.1",
79
- "@ssqch/linux-x64": "0.7.1",
80
- "@ssqch/win32-x64": "0.7.1"
81
- }
2
+ "name": "ssqch",
3
+ "version": "0.9.0",
4
+ "description": "SiteSquatch (ssqch): a fast static site generator, configured with JavaScript",
5
+ "keywords": [
6
+ "static site generator",
7
+ "ssg",
8
+ "blog",
9
+ "markdown",
10
+ "jinja",
11
+ "nunjucks",
12
+ "liquid",
13
+ "edge"
14
+ ],
15
+ "homepage": "https://github.com/reverentgeek/sitesquatch#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/reverentgeek/sitesquatch.git",
19
+ "directory": "packages/ssqch"
20
+ },
21
+ "bugs": "https://github.com/reverentgeek/sitesquatch/issues",
22
+ "license": "MIT",
23
+ "type": "module",
24
+ "bin": {
25
+ "ssqch": "bin/ssqch.js"
26
+ },
27
+ "types": "./types/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./types/index.d.ts",
31
+ "default": "./lib/ssqch.js"
32
+ },
33
+ "./image": {
34
+ "types": "./types/image.d.ts",
35
+ "default": "./lib/image.js"
36
+ },
37
+ "./rss": {
38
+ "types": "./types/rss.d.ts",
39
+ "default": "./lib/rss.js"
40
+ },
41
+ "./minify": {
42
+ "types": "./types/minify.d.ts",
43
+ "default": "./lib/minify.js"
44
+ },
45
+ "./assets": {
46
+ "types": "./types/assets.d.ts",
47
+ "default": "./lib/assets.js"
48
+ },
49
+ "./links": {
50
+ "types": "./types/links.d.ts",
51
+ "default": "./lib/links.js"
52
+ },
53
+ "./sitemap": {
54
+ "types": "./types/sitemap.d.ts",
55
+ "default": "./lib/sitemap.js"
56
+ },
57
+ "./elements": {
58
+ "types": "./types/elements.d.ts",
59
+ "default": "./lib/elements.js"
60
+ },
61
+ "./redirects": {
62
+ "types": "./types/redirects.d.ts",
63
+ "default": "./lib/redirects.js"
64
+ },
65
+ "./sass": {
66
+ "types": "./types/sass.d.ts",
67
+ "default": "./lib/sass.js"
68
+ },
69
+ "./package.json": "./package.json"
70
+ },
71
+ "files": [
72
+ "bin",
73
+ "lib",
74
+ "src",
75
+ "types",
76
+ "wasm",
77
+ "bundled"
78
+ ],
79
+ "engines": {
80
+ "node": ">=22.18"
81
+ },
82
+ "dependencies": {
83
+ "sharp": "0.35.5"
84
+ }
82
85
  }
@@ -0,0 +1,174 @@
1
+ (() => {
2
+ // What `ssqch serve` adds to each page it sends: it asks the server what changed,
3
+ // and reloads, swaps a stylesheet or shows a build error. It's never written to the output.
4
+ let seen;
5
+ let panel;
6
+ let icon;
7
+ let hidden;
8
+ // Where the keyboard was before the overlay took it, to give it back.
9
+ let before;
10
+ const title = document.title;
11
+ const hide = () => {
12
+ hidden = panel.shadowRoot.querySelector("pre").textContent;
13
+ show(hidden);
14
+ };
15
+ const escape = event => {
16
+ if (event.key === "Escape" && panel) hide();
17
+ };
18
+ const show = error => {
19
+ if (!error || error === hidden) {
20
+ if (panel) {
21
+ const had = panel.shadowRoot.activeElement || document.activeElement === panel;
22
+ panel.remove();
23
+ icon.remove();
24
+ panel = icon = null;
25
+ document.title = title;
26
+ document.removeEventListener("keydown", escape);
27
+ if (had && before?.isConnected) before.focus();
28
+ before = null;
29
+ }
30
+ if (!error) hidden = null;
31
+ return;
32
+ }
33
+ if (!panel) {
34
+ panel = document.createElement("div");
35
+ panel.attachShadow({ mode: "open" }).innerHTML = `<style>
36
+ section { position: fixed; inset: 0; z-index: 2147483647; overflow: auto; box-sizing: border-box; padding: 2rem 1rem; background: rgba(27, 32, 29, 0.97); color: #e5e9e1; font: 16px/1.5 system-ui, sans-serif; }
37
+ div { max-width: 60rem; margin: 0 auto; }
38
+ h1 { margin: 0 0 0.25rem; font-size: 1.4rem; color: #f0a17d; }
39
+ p { margin: 0 0 1rem; color: #a2aca3; }
40
+ pre { margin: 0 0 1rem; padding: 1rem; border-left: 5px solid #e8af43; background: #252b27; color: #e5e9e1; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
41
+ section:focus { outline: none; }
42
+ button { margin-right: 0.5rem; padding: 0.35rem 0.9rem; border: 0; border-radius: 4px; background: #a23e20; color: #fafaf7; font: inherit; cursor: pointer; }
43
+ button:focus-visible { outline: 3px solid #e8af43; outline-offset: 2px; }
44
+ small { margin-left: 0.25rem; color: #a2aca3; }
45
+ </style><section role="alert" aria-labelledby="ssqch-title" tabindex="-1"><div><h1 id="ssqch-title">Build failed</h1><p>This page is from the last build that worked. Fix the error and this goes away.</p><pre></pre><button type="button" data-copy>Copy diagnostic</button><button type="button" data-hide>Hide</button><small>Escape hides it. Squatch Watch (ssqch serve)</small></div></section>`;
46
+ const root = panel.shadowRoot;
47
+ const copy = root.querySelector("[data-copy]");
48
+ copy.addEventListener("click", async () => {
49
+ const text = root.querySelector("pre").textContent;
50
+ try {
51
+ await navigator.clipboard.writeText(text);
52
+ copy.textContent = "Copied";
53
+ } catch {
54
+ // No clipboard (a page served over plain HTTP to another device): select it to copy by hand.
55
+ const range = document.createRange();
56
+ range.selectNodeContents(root.querySelector("pre"));
57
+ getSelection().removeAllRanges();
58
+ getSelection().addRange(range);
59
+ copy.textContent = "Selected: copy it with your keyboard";
60
+ }
61
+ setTimeout(() => {
62
+ copy.textContent = "Copy diagnostic";
63
+ }, 2000);
64
+ });
65
+ root.querySelector("[data-hide]").addEventListener("click", hide);
66
+ document.addEventListener("keydown", escape);
67
+ document.body.append(panel);
68
+ // The keyboard goes to the overlay (Tab reaches its buttons), and comes back when it goes.
69
+ before = document.activeElement;
70
+ root.querySelector("section").focus({ preventScroll: true });
71
+ icon = document.createElement("link");
72
+ icon.rel = "icon";
73
+ icon.href = "/__ssqch/favicon-error.svg";
74
+ document.head.append(icon);
75
+ document.title = `[build failed] ${title}`;
76
+ }
77
+ panel.shadowRoot.querySelector("pre").textContent = error;
78
+ };
79
+ // Stylesheets and scripts the page links that aren't in the output: a note in the corner (the
80
+ // page is there, just unstyled or without its script), and the server says so in the terminal.
81
+ let note;
82
+ let missing = new Map();
83
+ const assets = () => [...document.querySelectorAll('link[rel~="stylesheet"][href], script[src]')]
84
+ .map(el => new URL(el.getAttribute("href") ?? el.getAttribute("src"), location.href))
85
+ .filter(url => url.origin === location.origin && !url.pathname.startsWith("/__ssqch/"))
86
+ .map(url => url.pathname);
87
+ const notice = () => {
88
+ if (!missing.size) {
89
+ note?.remove();
90
+ note = null;
91
+ return;
92
+ }
93
+ if (!note) {
94
+ note = document.createElement("div");
95
+ note.attachShadow({ mode: "open" }).innerHTML = `<style>
96
+ aside { position: fixed; right: 1rem; bottom: 1rem; z-index: 2147483646; max-width: 32rem; box-sizing: border-box; padding: 0.75rem 1rem; border-left: 5px solid #e8af43; background: #1b201d; color: #e5e9e1; font: 14px/1.5 system-ui, sans-serif; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); }
97
+ strong { display: block; color: #f0a17d; }
98
+ p { margin: 0.35rem 0 0; overflow-wrap: anywhere; }
99
+ button { margin-top: 0.5rem; padding: 0.2rem 0.7rem; border: 0; border-radius: 4px; background: #a23e20; color: #fafaf7; font: inherit; cursor: pointer; }
100
+ </style><aside role="status"><strong>Missing from the output</strong><div></div><button type="button">Hide</button></aside>`;
101
+ note.shadowRoot.querySelector("button").addEventListener("click", () => note.remove());
102
+ document.body.append(note);
103
+ }
104
+ const list = note.shadowRoot.querySelector("div");
105
+ list.replaceChildren(...[...missing.values()].map(message => Object.assign(document.createElement("p"), { textContent: message })));
106
+ };
107
+ const check = async paths => {
108
+ for (const path of paths) {
109
+ try {
110
+ const found = (await fetch(path, { method: "HEAD", cache: "no-store" })).ok;
111
+ if (found) {
112
+ missing.delete(path);
113
+ continue;
114
+ }
115
+ const { message } = await (await fetch(`/__ssqch/missing?path=${encodeURIComponent(path)}`)).json();
116
+ if (message) missing.set(path, message);
117
+ else missing.delete(path);
118
+ } catch {}
119
+ }
120
+ notice();
121
+ };
122
+ check(assets());
123
+ // A changed stylesheet is fetched again in place: the page keeps its scroll position and its forms.
124
+ // The new one loads next to the old, which goes once it's there, so the page is never unstyled
125
+ // in between. One that doesn't load, or comes back empty where the old one had rules (a tool
126
+ // still writing it), leaves the old one in place and is tried again.
127
+ const loading = new Map();
128
+ const rules = link => {
129
+ try {
130
+ return link.sheet?.cssRules.length ?? 0;
131
+ } catch {
132
+ return 1;
133
+ }
134
+ };
135
+ const swap = (path, id, tries = 0) => {
136
+ const replacements = new Set(loading.values());
137
+ for (const link of document.querySelectorAll('link[rel~="stylesheet"]')) {
138
+ const url = new URL(link.href, location.href);
139
+ if (replacements.has(link) || url.origin !== location.origin || url.pathname !== path) continue;
140
+ url.searchParams.set("ssqch", tries ? `${id}.${tries}` : id);
141
+ // A newer change replaces one still loading.
142
+ loading.get(link)?.remove();
143
+ const next = link.cloneNode();
144
+ next.href = url.href;
145
+ const done = ok => {
146
+ if (loading.get(link) !== next) return;
147
+ loading.delete(link);
148
+ (ok ? link : next).remove();
149
+ if (!ok && tries < 5) setTimeout(() => swap(path, id, tries + 1), 300);
150
+ };
151
+ next.addEventListener("load", () => done(rules(next) > 0 || rules(link) === 0), { once: true });
152
+ next.addEventListener("error", () => done(false), { once: true });
153
+ loading.set(link, next);
154
+ link.after(next);
155
+ }
156
+ };
157
+ setInterval(async () => {
158
+ try {
159
+ const now = await (await fetch(`/__ssqch/build?v=${seen ?? ""}&p=${encodeURIComponent(location.pathname)}`)).json();
160
+ show(now.error);
161
+ if (seen !== undefined && now.id !== seen && !now.error) {
162
+ if (now.reload) {
163
+ console.log("[ssqch] Fresh tracks. Reloading.");
164
+ location.reload();
165
+ return;
166
+ }
167
+ for (const path of now.css) swap(path, now.id);
168
+ // A file that was missing may be there now.
169
+ if (missing.size) check([...missing.keys()]);
170
+ }
171
+ seen = now.id;
172
+ } catch {}
173
+ }, 700);
174
+ })();
@@ -0,0 +1,31 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Page not found</title>
7
+ <style>
8
+ /* Ranger Station '76: soft white (or green charcoal), neutral text, pine headings, burnt orange links. */
9
+ :root { color-scheme: light dark; --ink: #29332c; --heading: #233b2b; --soft: #5e6a61; --paper: #fafaf7; --link: #a23e20; --gold: #e8af43; }
10
+ @media (prefers-color-scheme: dark) { :root { --ink: #e5e9e1; --heading: #d6e4c8; --soft: #a2aca3; --paper: #1b201d; --link: #f0a17d; } }
11
+ body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: var(--paper); color: var(--ink); font: 1rem/1.6 system-ui, sans-serif; }
12
+ main { max-width: 32rem; padding: 2rem 1rem; text-align: center; }
13
+ svg { width: 9rem; height: auto; }
14
+ h1 { font-size: 1.5rem; margin: 1rem 0 0.5rem; color: var(--heading); }
15
+ code { font-size: 0.95em; overflow-wrap: anywhere; }
16
+ a { color: var(--link); text-decoration: underline; text-underline-offset: 0.18em; }
17
+ h1::after { content: ""; display: block; width: 4rem; height: 4px; margin: 0.6rem auto 0; background: var(--gold); }
18
+ small { display: block; margin-top: 2rem; color: var(--soft); }
19
+ </style>
20
+ </head>
21
+ <body>
22
+ <main>
23
+ {{patch}}
24
+ <h1>Page not found</h1>
25
+ <p>The trail goes cold at <code>{{url}}</code>. We have several eyewitness accounts of this page, but no page.</p>
26
+ {{suggestion}}
27
+ <p><a href="{{home}}">Back to the trailhead</a></p>
28
+ <small>From <code>ssqch serve</code>, because this site has no <code>404.html</code>. Add a page with <code>permalink: /404.html</code> to make your own.</small>
29
+ </main>
30
+ </body>
31
+ </html>
@@ -2,8 +2,9 @@
2
2
  // Written by `ssqch types`. Editors use them for autocomplete and checking;
3
3
  // the build doesn't read them. Regenerate after upgrading ssqch.
4
4
 
5
- // The parts of Node's `process` that ssqch provides to configs and data files. Declared
6
- // the way @types/node declares it, so a project that installs those types gets theirs too.
5
+ // A config and its data files run on Node, so `process` is Node's own. These are the parts
6
+ // they most often use, declared the way @types/node declares them, so a project that installs
7
+ // those types gets theirs too.
7
8
  declare namespace NodeJS {
8
9
  interface ProcessEnv {
9
10
  /** The build's environment (`--env`): `"production"` for `ssqch build`, `"development"` for `ssqch serve`. */
package/types/image.d.ts CHANGED
@@ -17,11 +17,15 @@ export interface ImagePluginOptions {
17
17
  outputDir?: string;
18
18
  /** URL path they're served from. Default `/img/`. */
19
19
  urlPath?: string;
20
+ /** WebP quality, sharp's: a whole number from 1 to 100. Default 75. */
20
21
  webpQuality?: number;
22
+ /** AVIF quality, sharp's: a whole number from 1 to 100. Default 41. */
21
23
  avifQuality?: number;
22
- /** 1 (slowest, smallest) to 10 (fastest). Default 8. */
23
- avifSpeed?: number;
24
+ /** sharp's AVIF effort: a whole number from 0 (fastest) to 9 (slowest, smallest files). Default 2. */
25
+ avifEffort?: number;
26
+ /** JPEG quality, sharp's (mozjpeg): a whole number from 1 to 100. Default 89. */
24
27
  jpegQuality?: number;
28
+ /** A width larger than the original is clamped to it only when the width before it is this many times smaller. Default 1.25. */
25
29
  minimumThreshold?: number;
26
30
  /** Delete generated images the build didn't use. Only for full builds. */
27
31
  prune?: boolean;
@@ -48,7 +52,7 @@ export interface ImageEntry {
48
52
  size: number;
49
53
  }
50
54
 
51
- /** Turns every local `<img>` in HTML output into a `<picture>`. */
55
+ /** Turns every local `<img>` in HTML output into a `<picture>`, with AVIF, WebP and fallback sources encoded by sharp. `[ssqch] Encoded ...` lines come as each image's files are done, while pages go on rendering. */
52
56
  export function imagePlugin(options?: ImagePluginOptions): BuiltinPlugin;
53
57
 
54
58
  /** Generate one image's files with the plugin's settings and cache. Keyed by format, smallest first; with `"auto"` in `formats`, its files are under `auto` too. */