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
@@ -0,0 +1,502 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+ import "./chunk-R7K3D5W5.js";
4
+ import "./chunk-7XLK2GEG.js";
5
+ import "./chunk-NKXEPHRZ.js";
6
+ import "./chunk-AD3HAW3W.js";
7
+ import {
8
+ dirsOf,
9
+ shownDir
10
+ } from "./chunk-DDV6JEC2.js";
11
+ import {
12
+ slugWith
13
+ } from "./chunk-NCWFYT74.js";
14
+ import "./chunk-FVZ5JBRI.js";
15
+ import "./chunk-HPXAZ2HU.js";
16
+ import {
17
+ FIELD_NOTES
18
+ } from "./chunk-UU43WIZG.js";
19
+ import "./chunk-76NTVE34.js";
20
+ import {
21
+ serdeFloat
22
+ } from "./chunk-CMUWRPSQ.js";
23
+ import {
24
+ bail,
25
+ context,
26
+ parseFrontMatter
27
+ } from "./chunk-GRWMGC7D.js";
28
+ import {
29
+ isDir,
30
+ isFile,
31
+ isInside,
32
+ realPath,
33
+ slashes
34
+ } from "./chunk-VJWQSYEG.js";
35
+ import "./chunk-I3PS26CI.js";
36
+
37
+ // src/commands/new.ts
38
+ import fs from "node:fs";
39
+ import path from "node:path";
40
+ var slug = (text) => slugWith(text, "-", false);
41
+ function titleFrom(name) {
42
+ const words = name.replace(/[-_]/g, " ").trim();
43
+ return words === "" ? "" : words[0].toUpperCase() + words.slice(1);
44
+ }
45
+ var DATE_PREFIX = /^\d{4}-\d{2}-\d{2}-/;
46
+ function parts(file) {
47
+ const name = path.basename(file);
48
+ const dot = name.lastIndexOf(".");
49
+ return dot <= 0 ? { stem: name, ext: void 0 } : { stem: name.slice(0, dot), ext: name.slice(dot + 1) };
50
+ }
51
+ var entries = (dir) => {
52
+ try {
53
+ return fs.readdirSync(dir, { withFileTypes: true });
54
+ } catch {
55
+ return [];
56
+ }
57
+ };
58
+ function pagesIn(config, dir) {
59
+ const isPage = (file) => {
60
+ const ext = parts(file).ext;
61
+ return ext !== void 0 && config.templateFormats.some((f) => f.toLowerCase() === ext.toLowerCase());
62
+ };
63
+ const files = [], folders = [];
64
+ for (const entry of entries(dir)) {
65
+ const file = path.join(dir, entry.name);
66
+ if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
67
+ if (isDir(file)) {
68
+ const index = entries(file).map((e) => path.join(file, e.name)).find((p) => parts(p).stem === "index" && isPage(p));
69
+ if (index !== void 0) folders.push(index);
70
+ } else if (isPage(file) && parts(file).stem !== "index") {
71
+ files.push(file);
72
+ }
73
+ }
74
+ return { files, folders };
75
+ }
76
+ function filesUnder(dir) {
77
+ const out = [];
78
+ for (const entry of entries(dir)) {
79
+ const file = path.join(dir, entry.name);
80
+ if (entry.isDirectory()) out.push(...filesUnder(file));
81
+ else if (entry.isFile()) out.push(file);
82
+ }
83
+ return out;
84
+ }
85
+ function findBlueprint(config, root, named, folders, ext) {
86
+ const dirs = [dirsOf(config).input, ...config.themes].map((d) => path.join(d, "_blueprints"));
87
+ const names = [];
88
+ if (named !== void 0) names.push(named.replace(/^\/+|\/+$/g, ""));
89
+ else {
90
+ let rest = folders.replace(/^\/+|\/+$/g, "");
91
+ while (rest !== "") {
92
+ names.push(rest);
93
+ const slash = rest.lastIndexOf("/");
94
+ rest = slash === -1 ? "" : rest.slice(0, slash);
95
+ }
96
+ names.push("default");
97
+ }
98
+ for (const name of names) {
99
+ for (const dir of dirs) {
100
+ const at = path.join(dir, name);
101
+ const found = entries(path.dirname(at)).filter((e) => parts(e.name).stem === path.basename(at)).map((e) => path.join(path.dirname(at), e.name)).filter(isFile).sort();
102
+ const wanted = found.find((p) => ext !== void 0 && parts(p).ext?.toLowerCase() === ext.toLowerCase());
103
+ const pick = wanted ?? found[0];
104
+ if (pick !== void 0) return pick;
105
+ }
106
+ }
107
+ if (named !== void 0) {
108
+ const have = /* @__PURE__ */ new Set();
109
+ for (const dir of dirs) {
110
+ for (const file of filesUnder(dir)) {
111
+ const rel = slashes(path.relative(dir, file));
112
+ const dot = rel.lastIndexOf(".");
113
+ have.add(dot > rel.lastIndexOf("/") + 1 ? rel.slice(0, dot) : rel);
114
+ }
115
+ }
116
+ const shownDir2 = slashes(path.relative(root, dirs[0]));
117
+ const list = [...have].sort();
118
+ bail(`no blueprint named ${JSON.stringify(named)} in ${shownDir2}/ (${list.length === 0 ? "there are none" : `there's ${list.join(", ")}`})`);
119
+ }
120
+ return null;
121
+ }
122
+ function yamlString(text) {
123
+ const plain = new RegExp("^\\p{L}[\\p{L}\\p{N} _.,'()!?&/+-]*$", "u");
124
+ const word = ["true", "false", "null", "yes", "no", "on", "off", "y", "n"].includes(text.toLowerCase());
125
+ return plain.test(text) && !word && !text.endsWith(" ") && !text.includes(" -") ? text : JSON.stringify(text);
126
+ }
127
+ function tomlEntries(lines, close) {
128
+ const found = [];
129
+ let depth = 0;
130
+ let multi = null;
131
+ let start = null;
132
+ for (let i = 1; i < close; i++) {
133
+ const line = lines[i];
134
+ if (depth === 0 && multi === null) {
135
+ const text = line.trimStart();
136
+ if (text.startsWith("[")) return [found, i];
137
+ if (text !== "" && !text.startsWith("#")) start = i;
138
+ }
139
+ scan: for (let j = 0; j < line.length; j++) {
140
+ if (multi !== null) {
141
+ if (line.startsWith(multi, j)) {
142
+ multi = null;
143
+ j += 2;
144
+ } else if (multi === '"""' && line[j] === "\\") j += 1;
145
+ continue;
146
+ }
147
+ const c = line[j];
148
+ switch (c) {
149
+ case "#":
150
+ break scan;
151
+ case '"':
152
+ case "'": {
153
+ const triple = c.repeat(3);
154
+ if (line.startsWith(triple, j)) {
155
+ multi = triple;
156
+ j += 2;
157
+ continue;
158
+ }
159
+ j += 1;
160
+ while (j < line.length && line[j] !== c) j += c === '"' && line[j] === "\\" ? 2 : 1;
161
+ break;
162
+ }
163
+ case "[":
164
+ case "{":
165
+ depth++;
166
+ break;
167
+ case "]":
168
+ case "}":
169
+ depth--;
170
+ break;
171
+ }
172
+ }
173
+ if (depth <= 0 && multi === null) {
174
+ depth = 0;
175
+ if (start !== null) {
176
+ found.push([start, i + 1]);
177
+ start = null;
178
+ }
179
+ }
180
+ }
181
+ return [found, close];
182
+ }
183
+ function readJson(text) {
184
+ JSON.parse(text);
185
+ let i = 0;
186
+ const space = () => {
187
+ while (text[i] === " " || text[i] === " " || text[i] === "\n" || text[i] === "\r") i++;
188
+ };
189
+ const token = (re) => {
190
+ re.lastIndex = i;
191
+ const found = re.exec(text)[0];
192
+ i += found.length;
193
+ return found;
194
+ };
195
+ const value = () => {
196
+ space();
197
+ const c = text[i];
198
+ if (c === "{" || c === "[") {
199
+ i++;
200
+ const close = c === "{" ? "}" : "]";
201
+ const map = /* @__PURE__ */ new Map(), list = [];
202
+ space();
203
+ if (text[i] === close) {
204
+ i++;
205
+ return c === "{" ? map : list;
206
+ }
207
+ for (; ; ) {
208
+ if (c === "{") {
209
+ space();
210
+ const key = JSON.parse(token(STRING));
211
+ space();
212
+ i++;
213
+ map.set(key, value());
214
+ } else list.push(value());
215
+ space();
216
+ if (text[i++] === close) return c === "{" ? map : list;
217
+ }
218
+ }
219
+ if (c === '"') return JSON.parse(token(STRING));
220
+ const word = token(/true|false|null|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/y);
221
+ if (word === "true" || word === "false") return word === "true";
222
+ return word === "null" ? null : { number: serdeNumber(word) };
223
+ };
224
+ return value();
225
+ }
226
+ var STRING = /"(?:[^"\\]|\\.)*"/y;
227
+ var I64_MIN = -(2n ** 63n);
228
+ var U64_MAX = 2n ** 64n - 1n;
229
+ function serdeNumber(text) {
230
+ if (!/[.eE]/.test(text)) {
231
+ const n = BigInt(text);
232
+ if (text.startsWith("-") ? n !== 0n && n >= I64_MIN : n <= U64_MAX) return n.toString();
233
+ }
234
+ const x = Number(text);
235
+ if (!Number.isFinite(x)) throw new RangeError("number out of range");
236
+ return serdeFloat(x);
237
+ }
238
+ function jsonText(v, indent = "") {
239
+ if (v === null || typeof v === "boolean") return String(v);
240
+ if (typeof v === "string") return JSON.stringify(v);
241
+ const inner = indent + " ";
242
+ if (v instanceof Map) return v.size === 0 ? "{}" : `{
243
+ ${[...v].map(([key, item]) => `${inner}${JSON.stringify(key)}: ${jsonText(item, inner)}`).join(",\n")}
244
+ ${indent}}`;
245
+ if (Array.isArray(v)) return v.length === 0 ? "[]" : `[
246
+ ${v.map((item) => inner + jsonText(item, inner)).join(",\n")}
247
+ ${indent}]`;
248
+ return v.number;
249
+ }
250
+ function fillFrontMatter(source, fills) {
251
+ const newline = source.includes("\r\n") ? "\r\n" : "\n";
252
+ const firstLine = (source.split("\n")[0] ?? "").replace(/\r$/, "").trimEnd();
253
+ let format, fence;
254
+ switch (firstLine) {
255
+ case "+++":
256
+ [format, fence] = ["toml", "+++"];
257
+ break;
258
+ case "---toml":
259
+ [format, fence] = ["toml", "---"];
260
+ break;
261
+ case "---json":
262
+ [format, fence] = ["json", "---"];
263
+ break;
264
+ case "---":
265
+ case "---yaml":
266
+ case "---yml":
267
+ [format, fence] = ["yaml", "---"];
268
+ break;
269
+ // No front matter: give it one.
270
+ default:
271
+ return fillFrontMatter(`---${newline}---${newline}${source}`, fills);
272
+ }
273
+ const lines = source.match(/[^\n]*\n|[^\n]+$/g) ?? [];
274
+ const closeAt = lines.slice(1).findIndex((l) => l.trimEnd() === fence);
275
+ if (closeAt === -1) bail(`its front matter is missing the closing \`${fence}\``);
276
+ let close = closeAt + 1;
277
+ if (format === "json") {
278
+ const text = lines.slice(1, close).join("");
279
+ let data;
280
+ try {
281
+ data = readJson(text.trim() === "" ? "{}" : text);
282
+ } catch (e) {
283
+ throw context(e, "its JSON front matter doesn't parse");
284
+ }
285
+ if (!(data instanceof Map)) bail("its JSON front matter isn't an object");
286
+ for (const [key, fill] of fills) {
287
+ if ("text" in fill) data.set(key, fill.text);
288
+ else {
289
+ try {
290
+ data.set(key, readJson(fill.raw));
291
+ } catch {
292
+ data.set(key, fill.raw);
293
+ }
294
+ }
295
+ }
296
+ lines.splice(1, close - 1, jsonText(data).replace(/\n/g, newline) + newline);
297
+ return lines.join("");
298
+ }
299
+ const toml = format === "toml";
300
+ const written = (key, fill) => {
301
+ const value = "raw" in fill ? fill.raw : toml ? JSON.stringify(fill.text) : yamlString(fill.text);
302
+ return `${key}${toml ? " = " : ": "}${value}${newline}`;
303
+ };
304
+ let atTop = 1;
305
+ for (const [key, fill, first] of fills) {
306
+ const starts = (line) => {
307
+ const bare = line.replace(/^[ \t]+/, "");
308
+ const rest = bare.startsWith(key) ? bare.slice(key.length) : bare.startsWith(`"${key}"`) ? bare.slice(key.length + 2) : void 0;
309
+ return rest !== void 0 && rest.trimStart().startsWith(toml ? "=" : ":");
310
+ };
311
+ if (toml) {
312
+ const [found, rootEnd] = tomlEntries(lines, close);
313
+ const hit = found.find(([at]) => starts(lines[at]));
314
+ if (hit) {
315
+ const [at, end] = hit;
316
+ lines.splice(at, end - at, written(key, fill));
317
+ close -= end - at - 1;
318
+ continue;
319
+ }
320
+ let line;
321
+ if (first) line = atTop;
322
+ else if (found.length) line = found[found.length - 1][1];
323
+ else {
324
+ line = rootEnd;
325
+ while (line > 1 && lines[line - 1].trim() === "") line--;
326
+ }
327
+ if (first) atTop++;
328
+ lines.splice(line, 0, written(key, fill));
329
+ close++;
330
+ continue;
331
+ }
332
+ const index = lines.slice(1, close).findIndex((l) => !/^[ \t]/.test(l) && starts(l));
333
+ if (index !== -1) {
334
+ const at = index + 1;
335
+ let end = at + 1;
336
+ while (end < close && (/^[ \t]/.test(lines[end]) || lines[end].startsWith("- "))) end++;
337
+ lines.splice(at, end - at, written(key, fill));
338
+ close -= end - at - 1;
339
+ } else if (first) {
340
+ lines.splice(atTop, 0, written(key, fill));
341
+ atTop++;
342
+ close++;
343
+ } else {
344
+ let at = close;
345
+ while (at > 1 && lines[at - 1].trim() === "") at--;
346
+ lines.splice(at, 0, written(key, fill));
347
+ close++;
348
+ }
349
+ }
350
+ return lines.join("");
351
+ }
352
+ function hasKey(source, key) {
353
+ try {
354
+ return Object.hasOwn(parseFrontMatter(source).data, key);
355
+ } catch {
356
+ return false;
357
+ }
358
+ }
359
+ function under(base, given) {
360
+ let out = base;
361
+ for (const part of given.split("/")) {
362
+ if (part === "" || part === ".") continue;
363
+ if (part === ".." || path.sep === "\\" && /^[A-Za-z]:/.test(part)) return void 0;
364
+ out = path.join(out, part);
365
+ }
366
+ return given.startsWith("/") ? void 0 : out;
367
+ }
368
+ var pad = (n) => String(n).padStart(2, "0");
369
+ var today = () => {
370
+ const d = /* @__PURE__ */ new Date();
371
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
372
+ };
373
+ var utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
374
+ function readBlueprint(file, blueprints, shownInput) {
375
+ const shown = isInside(blueprints, file) ? [shownInput, "_blueprints", path.relative(blueprints, file)].join(path.sep) : file;
376
+ let bytes;
377
+ try {
378
+ bytes = fs.readFileSync(file);
379
+ } catch (e) {
380
+ throw context(e, `reading ${shown}`);
381
+ }
382
+ try {
383
+ return utf8.decode(bytes);
384
+ } catch {
385
+ return bail(`reading ${shown}: stream did not contain valid UTF-8`);
386
+ }
387
+ }
388
+ function newPage(config, options) {
389
+ const dirs = dirsOf(config);
390
+ let given = options.path.replace(/\\/g, "/");
391
+ while (given.startsWith("./")) given = given.slice(2);
392
+ if (given === "") bail("give the new page's path, like posts/pine-cones.md");
393
+ const shownInput = shownDir(config, config.input);
394
+ let input;
395
+ try {
396
+ input = fs.realpathSync.native(dirs.input);
397
+ } catch (e) {
398
+ throw context(e, `input directory ${shownInput} does not exist`);
399
+ }
400
+ const root = realPath(dirs.root);
401
+ const shownIn = (file2) => slashes(path.relative(root, file2));
402
+ const fromInput = under(input, given);
403
+ if (fromInput === void 0) bail(`${options.path}: a new page goes in the input folder (${slashes(path.relative(root, input))}/), so give a path from there`);
404
+ const fromRoot = under(root, given);
405
+ const target = fromRoot !== void 0 && input !== root && (fromRoot === input || fromRoot.startsWith(input + path.sep)) ? fromRoot : fromInput;
406
+ const rel = slashes(path.relative(input, target));
407
+ if (rel.split("/")[0].startsWith("_")) bail(`${options.path}: ${rel.split("/")[0]}/ isn't a folder for pages`);
408
+ const date = options.date ?? today();
409
+ const isFolder = given.endsWith("/") || isDir(target) || parts(target).ext === void 0;
410
+ let file, blueprint, title;
411
+ if (isFolder) {
412
+ const given2 = options.title;
413
+ if (given2 === void 0 || given2.trim() === "") bail(`${options.path} is a folder, so give the page a title to name its file after: ssqch new ${options.path.replace(/\/+$/, "")} --title "Pine cones"`);
414
+ title = given2;
415
+ const name = slug(title);
416
+ if (name === "") bail(`--title ${JSON.stringify(title)} has no letters or digits to name the file after`);
417
+ blueprint = findBlueprint(config, root, options.blueprint, rel, void 0);
418
+ const { files, folders } = pagesIn(config, target);
419
+ const counts = [];
420
+ for (const found of [...files, ...folders].map((p) => parts(p).ext)) {
421
+ if (found === void 0) continue;
422
+ const row = counts.find(([, e]) => e === found);
423
+ if (row) row[0]++;
424
+ else counts.push([1, found]);
425
+ }
426
+ counts.sort((a, b) => b[0] - a[0] || (a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0));
427
+ const ext = (blueprint === null ? void 0 : parts(blueprint).ext) ?? counts[0]?.[1] ?? "md";
428
+ const dated = [...files, ...folders].filter((p) => DATE_PREFIX.test(parts(p).stem === "index" ? path.basename(path.dirname(p)) : path.basename(p))).length;
429
+ const day = date.slice(0, 10);
430
+ const stem = dated * 2 > files.length + folders.length && DATE_PREFIX.test(`${day}-`) ? `${day}-${name}` : name;
431
+ file = folders.length > files.length ? path.join(target, stem, `index.${ext}`) : path.join(target, `${stem}.${ext}`);
432
+ } else {
433
+ const slash = rel.lastIndexOf("/");
434
+ let folders = slash === -1 ? "" : rel.slice(0, slash);
435
+ const { ext, stem } = parts(target);
436
+ let name = stem;
437
+ if (stem === "index") {
438
+ name = folders.slice(folders.lastIndexOf("/") + 1);
439
+ folders = folders.includes("/") ? folders.slice(0, folders.lastIndexOf("/")) : "";
440
+ }
441
+ blueprint = findBlueprint(config, root, options.blueprint, folders, ext);
442
+ title = options.title ?? titleFrom(name.replace(DATE_PREFIX, ""));
443
+ file = target;
444
+ }
445
+ if (fs.existsSync(file)) {
446
+ const another = isFolder ? "give it another --title" : "choose another file name";
447
+ bail(`${shownIn(file)} already exists. Those tracks are taken; ${another} (the file is left as it is)`);
448
+ }
449
+ const source = blueprint !== null ? readBlueprint(blueprint, path.join(dirs.input, "_blueprints"), shownInput) : "---\ntitle:\ndate:\n---\n\n";
450
+ const fills = [["title", { text: title }, true]];
451
+ if (hasKey(source, "date") || options.date !== void 0) fills.push(["date", { raw: date }, false]);
452
+ for (const [key, value] of options.set) {
453
+ if (key === "" || /[.: =]/.test(key)) bail(`--set ${key}=${value}: the key is one front matter key, like draft=true`);
454
+ fills.push([key, { raw: value }, false]);
455
+ }
456
+ let text;
457
+ try {
458
+ text = fillFrontMatter(source, fills);
459
+ } catch (e) {
460
+ throw context(e, blueprint !== null ? `in ${shownIn(realPath(blueprint))}` : "in the built-in blueprint");
461
+ }
462
+ try {
463
+ fs.mkdirSync(path.dirname(file), { recursive: true });
464
+ } catch (e) {
465
+ throw context(e, `creating ${path.dirname(file)}`);
466
+ }
467
+ try {
468
+ fs.writeFileSync(file, text);
469
+ } catch (e) {
470
+ throw context(e, `writing ${file}`);
471
+ }
472
+ return { path: file, blueprint: blueprint === null ? null : realPath(blueprint), title, date };
473
+ }
474
+ function runNew(config, command) {
475
+ if (command.format !== "text" && command.format !== "json") bail(`--format ${command.format}: use text or json`);
476
+ const set = [];
477
+ for (const pair of command.set) {
478
+ const eq = pair.indexOf("=");
479
+ if (eq === -1) bail(`--set ${pair}: give a key and a value, like --set draft=true`);
480
+ set.push([pair.slice(0, eq).trim(), pair.slice(eq + 1).trim()]);
481
+ }
482
+ const created = newPage(config, { path: command.path, title: command.title, date: command.date, blueprint: command.blueprint, set });
483
+ const dirs = dirsOf(config);
484
+ const root = realPath(dirs.root);
485
+ const shown = (file) => slashes(path.relative(root, file));
486
+ if (command.format === "json") {
487
+ const out = { schemaVersion: 1, path: shown(created.path), blueprint: created.blueprint === null ? null : shown(created.blueprint), title: created.title, date: created.date };
488
+ process.stdout.write(JSON.stringify(out, null, 2) + "\n");
489
+ return;
490
+ }
491
+ const from = created.blueprint !== null ? shown(created.blueprint) : `the built-in blueprint (a title and a date; ${shown(realPath(dirs.input))}/_blueprints/ has none for it)`;
492
+ const aside = config.quiet ? "" : ` ${FIELD_NOTES}`;
493
+ process.stdout.write(`Created ${shown(created.path)} from ${from}.${aside}
494
+ `);
495
+ }
496
+ export {
497
+ fillFrontMatter,
498
+ newPage,
499
+ runNew,
500
+ slug,
501
+ yamlString
502
+ };
@@ -0,0 +1,113 @@
1
+ import { createRequire as __ssqchCreateRequire } from "node:module";
2
+ const require = __ssqchCreateRequire(import.meta.url);
3
+
4
+ // src/quote.ts
5
+ var UNPRINTABLE = /[\p{Cc}\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Zl}\p{Zp}\p{Zs}\p{Grapheme_Extend}]/u;
6
+ function escaped(c, quote) {
7
+ switch (c) {
8
+ case "\0":
9
+ return "\\0";
10
+ case " ":
11
+ return "\\t";
12
+ case "\r":
13
+ return "\\r";
14
+ case "\n":
15
+ return "\\n";
16
+ case "\\":
17
+ return "\\\\";
18
+ case quote:
19
+ return `\\${quote}`;
20
+ case " ":
21
+ return " ";
22
+ }
23
+ return UNPRINTABLE.test(c) ? `\\u{${c.codePointAt(0).toString(16)}}` : c;
24
+ }
25
+ function quoted(text) {
26
+ let out = '"';
27
+ if (/^[\x20-\x7e]*$/.test(text) && !/["\\]/.test(text)) return `"${text}"`;
28
+ for (const c of text) out += escaped(c, '"');
29
+ return out + '"';
30
+ }
31
+ function quotedChar(c) {
32
+ return `'${escaped(c, "'")}'`;
33
+ }
34
+ var charCount = (text) => {
35
+ let n = 0;
36
+ for (const _ of text) n++;
37
+ return n;
38
+ };
39
+ var padEnd = (text, width) => text + " ".repeat(Math.max(0, width - charCount(text)));
40
+ var padStart = (text, width) => " ".repeat(Math.max(0, width - charCount(text))) + text;
41
+ function firstChars(text, n) {
42
+ if (text.length <= n) return text;
43
+ let out = "";
44
+ let i = 0;
45
+ for (const c of text) {
46
+ if (i++ === n) break;
47
+ out += c;
48
+ }
49
+ return out;
50
+ }
51
+ function jsString(value) {
52
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
53
+ if (Array.isArray(value)) return value.map((v) => v === void 0 || v === null ? "" : jsString(v)).join(",");
54
+ if (typeof value === "function") return "function () { [native code] }";
55
+ if (value !== null && typeof value === "object") return "[object Object]";
56
+ return String(value);
57
+ }
58
+ function serdeFloat(x) {
59
+ if (x === 0) return Object.is(x, -0) ? "-0.0" : "0.0";
60
+ const [mantissa, e] = x.toExponential().split("e");
61
+ const exp = Number(e);
62
+ const sign = x < 0 ? "-" : "";
63
+ const digits = mantissa.replace(/^-/, "").replace(".", "");
64
+ if (exp < -5 || exp > 15) return `${sign}${digits[0]}${digits.length > 1 ? `.${digits.slice(1)}` : ""}e${exp < 0 ? "-" : "+"}${Math.abs(exp)}`;
65
+ if (exp < 0) return `${sign}0.${"0".repeat(-exp - 1)}${digits}`;
66
+ return `${sign}${digits.slice(0, exp + 1).padEnd(exp + 1, "0")}.${digits.slice(exp + 1) || "0"}`;
67
+ }
68
+ function prettyJson(value, indent = "") {
69
+ if (typeof value === "number") return !Number.isFinite(value) ? "null" : Number.isInteger(value) && Math.abs(value) < 9e15 ? String(value) : serdeFloat(value);
70
+ if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
71
+ const inner = indent + " ";
72
+ if (Array.isArray(value)) return value.length ? `[
73
+ ${value.map((v) => inner + prettyJson(v, inner)).join(",\n")}
74
+ ${indent}]` : "[]";
75
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0);
76
+ return entries.length ? `{
77
+ ${entries.map(([k, v]) => `${inner}${JSON.stringify(k)}: ${prettyJson(v, inner)}`).join(",\n")}
78
+ ${indent}}` : "{}";
79
+ }
80
+ function toJsonValue(value, above = /* @__PURE__ */ new Set()) {
81
+ if (value === void 0 || value === null || typeof value === "function" || typeof value === "symbol") return null;
82
+ if (typeof value === "number") return Number.isFinite(value) ? value : null;
83
+ if (typeof value === "bigint") return Number(value);
84
+ if (typeof value !== "object") return value;
85
+ if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value.toISOString();
86
+ if (above.has(value)) return null;
87
+ above.add(value);
88
+ let out;
89
+ if (Array.isArray(value)) out = value.map((v) => toJsonValue(v, above));
90
+ else {
91
+ const obj = {};
92
+ for (const [key, v] of Object.entries(value)) {
93
+ if (v === void 0 || typeof v === "function" || typeof v === "symbol") continue;
94
+ obj[key] = toJsonValue(v, above);
95
+ }
96
+ out = obj;
97
+ }
98
+ above.delete(value);
99
+ return out;
100
+ }
101
+
102
+ export {
103
+ quoted,
104
+ quotedChar,
105
+ charCount,
106
+ padEnd,
107
+ padStart,
108
+ firstChars,
109
+ jsString,
110
+ serdeFloat,
111
+ prettyJson,
112
+ toJsonValue
113
+ };