nodality 1.0.151 → 1.0.153
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/layout/animator.js +1 -1
- package/layout/audio.js +1 -1
- package/layout/audionew.js +1 -1
- package/layout/base-2.js +1 -1
- package/layout/base.js +1 -1
- package/layout/beta-desktop-bar.js +1 -1
- package/layout/beta-mobile-bar.js +1 -1
- package/layout/box.js +1 -1
- package/layout/button.js +1 -1
- package/layout/cards.js +1 -1
- package/layout/center.js +1 -1
- package/layout/checkbox.js +1 -1
- package/layout/circle.js +1 -1
- package/layout/clean-row.js +1 -1
- package/layout/code.js +1 -1
- package/layout/container.js +1 -1
- package/layout/custom.js +1 -1
- package/layout/div-image.js +1 -1
- package/layout/dropdown-2025.js +1 -1
- package/layout/dropdown.js +1 -1
- package/layout/empty-element.js +1 -1
- package/layout/external-stylesheet.js +1 -1
- package/layout/flex-card.js +1 -1
- package/layout/flex-grid.js +1 -1
- package/layout/flex-row.js +1 -1
- package/layout/footer.js +1 -1
- package/layout/form-components/custom.js +1 -1
- package/layout/form-components/data-list.js +1 -1
- package/layout/form-components/floating-input.js +1 -1
- package/layout/form-components/form-all.js +1 -1
- package/layout/form-components/form.js +1 -1
- package/layout/form-components/image-picker.js +1 -1
- package/layout/form-components/picker.js +1 -1
- package/layout/form-components/radio.js +1 -1
- package/layout/form-components/radiogroup.js +1 -1
- package/layout/form-components/range.js +1 -1
- package/layout/free.js +1 -1
- package/layout/grid-new.js +1 -1
- package/layout/grid-switcher.js +1 -1
- package/layout/grid.js +1 -1
- package/layout/group.js +1 -1
- package/layout/header.js +1 -1
- package/layout/horizontal-scroller.js +1 -1
- package/layout/image-old.js +1 -1
- package/layout/image.js +1 -1
- package/layout/index.js +1 -1
- package/layout/label.js +1 -1
- package/layout/link.js +1 -1
- package/layout/list-OLD.js +1 -1
- package/layout/list.js +1 -1
- package/layout/meta-adder.js +1 -1
- package/layout/modal-2025.js +1 -1
- package/layout/modernwrap.js +1 -1
- package/layout/multiswitcher.js +1 -1
- package/layout/multiswitcherBeta.js +1 -1
- package/layout/nav-bar.js +1 -1
- package/layout/nav-factor/custom-div.js +1 -1
- package/layout/navBar-OLD.js +1 -1
- package/layout/new-flat-adder.js +1 -1
- package/layout/new-nav-bar.js +1 -1
- package/layout/offset-container.js +1 -1
- package/layout/polygon.js +1 -1
- package/layout/prerender-site.js +442 -0
- package/layout/prerender.js +1 -1
- package/layout/progress.js +1 -1
- package/layout/row.js +1 -1
- package/layout/saved-new-nav-bar.js +1 -1
- package/layout/scroll-video.js +1 -1
- package/layout/side-bar.js +1 -1
- package/layout/side-nav-bar.js +1 -1
- package/layout/simple-bar.js +1 -1
- package/layout/slider-2025.js +1 -1
- package/layout/spacer.js +1 -1
- package/layout/stack.js +1 -1
- package/layout/styler.js +1 -1
- package/layout/svg.js +1 -1
- package/layout/switcher.js +1 -1
- package/layout/table.js +1 -1
- package/layout/text-field.js +1 -1
- package/layout/text.js +1 -1
- package/layout/ulist.js +1 -1
- package/layout/video.js +1 -1
- package/layout/without-new.js +1 -1
- package/layout/wrap.js +1 -1
- package/layout/zoom-card.js +1 -1
- package/lib/card-getter.js +1 -1
- package/lib/designer.js +1 -1
- package/lib/element-mapper.js +1 -1
- package/lib/keyframe-animation.js +1 -1
- package/lib/link-getter.js +1 -1
- package/lib/scroll-video.js +1 -1
- package/lib/stacker.js +1 -1
- package/lib/theme.js +1 -1
- package/lib/transform-anim.js +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* nodality v1.0.153
|
|
3
|
+
* (c) 2026 Filip Vabrousek
|
|
4
|
+
* License: MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ════════════════════════════════════════════════════════════════════
|
|
8
|
+
// Nodality — full-site SSG batch renderer
|
|
9
|
+
// ════════════════════════════════════════════════════════════════════
|
|
10
|
+
//
|
|
11
|
+
// Higher-level wrapper around `prerender()` that handles the
|
|
12
|
+
// concerns every multi-page / multi-locale Nodality static site has:
|
|
13
|
+
//
|
|
14
|
+
// • Multi-locale process isolation (one Node subprocess per locale
|
|
15
|
+
// so ESM module-cache doesn't leak the wrong `t` across runs)
|
|
16
|
+
// • Per-locale output directories (default at root, others under
|
|
17
|
+
// /<locale>/)
|
|
18
|
+
// • Head-path rewrite for non-root locales (./script.js → ../script.js)
|
|
19
|
+
// • Body asset-path absolutization so `./assets/foo.jpg` works at
|
|
20
|
+
// any URL depth (becomes `/assets/foo.jpg`)
|
|
21
|
+
// • Per-page canonical + hreflang alternates + <html lang> injection
|
|
22
|
+
// • Sitemap.xml regeneration with hreflang entries
|
|
23
|
+
// • Mobile-first viewport during render (mobile users get no flicker)
|
|
24
|
+
// • Hydration handoff (clear-mount script before runtime scripts)
|
|
25
|
+
//
|
|
26
|
+
// Consumers provide a small config object and call `prerenderSite()`.
|
|
27
|
+
// Everything site-specific (page list, locale list, origin) lives in
|
|
28
|
+
// the config; everything generic stays in this module.
|
|
29
|
+
//
|
|
30
|
+
// ─── Minimal consumer usage ────────────────────────────────────────
|
|
31
|
+
//
|
|
32
|
+
// // scripts/prerender.mjs in the consumer project:
|
|
33
|
+
//
|
|
34
|
+
// import { prerenderSite } from "nodality/ssg-site";
|
|
35
|
+
// import path from "node:path";
|
|
36
|
+
// import { fileURLToPath } from "node:url";
|
|
37
|
+
//
|
|
38
|
+
// await prerenderSite({
|
|
39
|
+
// origin: "https://example.com",
|
|
40
|
+
// uploadDir: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../upload"),
|
|
41
|
+
// defaultLocale: "en",
|
|
42
|
+
// locales: ["en", "de", "fr"],
|
|
43
|
+
// pages: [
|
|
44
|
+
// { html: "index.html", entry: "app.js" },
|
|
45
|
+
// { html: "about.html", entry: "about.js" },
|
|
46
|
+
// ],
|
|
47
|
+
// });
|
|
48
|
+
//
|
|
49
|
+
// ─── Optional config keys ──────────────────────────────────────────
|
|
50
|
+
//
|
|
51
|
+
// viewport { width, height } default { 390, 844 } (mobile-first)
|
|
52
|
+
// mount CSS selector default "#mount"
|
|
53
|
+
// sitemap boolean default true (writes sitemap.xml)
|
|
54
|
+
// xDefaultLocale string default = defaultLocale
|
|
55
|
+
// assetPrefixes string[] default ["assets/", "dist/", "badge-",
|
|
56
|
+
// "apple-touch-icon", "favicon."]
|
|
57
|
+
// localStorageKey string default "h7lang"
|
|
58
|
+
//
|
|
59
|
+
// ─── Process model ─────────────────────────────────────────────────
|
|
60
|
+
//
|
|
61
|
+
// `prerenderSite()` distinguishes parent vs child runs by env var
|
|
62
|
+
// `NODALITY_SSG_LOCALE`. When called without it, it spawns a Node
|
|
63
|
+
// subprocess per locale (each child runs the SAME script with the
|
|
64
|
+
// locale set in env). When the env var is present, the call renders
|
|
65
|
+
// just that one locale to its output dir.
|
|
66
|
+
//
|
|
67
|
+
// This isolation is required because each page's entry script imports
|
|
68
|
+
// `./lang.js`, which calls `detectLang()` at module evaluation. ESM
|
|
69
|
+
// module cache would otherwise pin the first-imported locale across
|
|
70
|
+
// the whole process.
|
|
71
|
+
|
|
72
|
+
import { prerender } from "./prerender.js";
|
|
73
|
+
import { promises as fs } from "node:fs";
|
|
74
|
+
import path from "node:path";
|
|
75
|
+
import os from "node:os";
|
|
76
|
+
import { spawn } from "node:child_process";
|
|
77
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
78
|
+
|
|
79
|
+
const ENV_LOCALE = "NODALITY_SSG_LOCALE";
|
|
80
|
+
const ENV_CONFIG = "NODALITY_SSG_CONFIG";
|
|
81
|
+
|
|
82
|
+
const DEFAULT_ASSET_PREFIXES = [
|
|
83
|
+
"assets/",
|
|
84
|
+
"dist/",
|
|
85
|
+
"badge-",
|
|
86
|
+
"apple-touch-icon",
|
|
87
|
+
"favicon\\.",
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Render an entire static site across N locales.
|
|
92
|
+
*
|
|
93
|
+
* @param {object} config
|
|
94
|
+
* @param {string} config.origin — Public origin, e.g. "https://example.com"
|
|
95
|
+
* @param {string} config.uploadDir — Absolute path to the directory containing
|
|
96
|
+
* the template HTML + entry .js files. Output
|
|
97
|
+
* files are written under it (default locale
|
|
98
|
+
* at the root, others under /<locale>/).
|
|
99
|
+
* @param {string} [config.defaultLocale] — The locale code whose pages live at the
|
|
100
|
+
* root of uploadDir. All other locales get a
|
|
101
|
+
* same-named subdir. Optional — omit for a
|
|
102
|
+
* single-locale site with no locale tagging.
|
|
103
|
+
* @param {string[]} [config.locales] — All locale codes to render. Must include
|
|
104
|
+
* `defaultLocale` (if both given). Defaults
|
|
105
|
+
* to `[defaultLocale]` when only the default
|
|
106
|
+
* is set; defaults to a single untagged
|
|
107
|
+
* build when neither is set.
|
|
108
|
+
* @param {Array<{html:string,entry:string}>} config.pages
|
|
109
|
+
* — Each page's public HTML file (used as
|
|
110
|
+
* template) and the JS entry script that
|
|
111
|
+
* builds it.
|
|
112
|
+
* @param {{width:number,height:number}} [config.viewport={width:390,height:844}]
|
|
113
|
+
* @param {string} [config.mount="#mount"]
|
|
114
|
+
* @param {boolean} [config.sitemap=true]
|
|
115
|
+
* @param {string} [config.xDefaultLocale] — defaults to config.defaultLocale
|
|
116
|
+
* @param {string[]} [config.assetPrefixes] — Path prefixes that should be rewritten
|
|
117
|
+
* absolute (so they resolve at site root
|
|
118
|
+
* regardless of locale subdir depth).
|
|
119
|
+
* @param {string} [config.localStorageKey="h7lang"]
|
|
120
|
+
*
|
|
121
|
+
* @returns {Promise<void>}
|
|
122
|
+
*/
|
|
123
|
+
export async function prerenderSite(config) {
|
|
124
|
+
validateConfig(config);
|
|
125
|
+
|
|
126
|
+
// Child mode? Render exactly one locale and exit.
|
|
127
|
+
const childLocale = process.env[ENV_LOCALE];
|
|
128
|
+
if (childLocale !== undefined) {
|
|
129
|
+
// The env var carries a string; map the literal "null" sentinel
|
|
130
|
+
// back to a real null so single-locale paths work in the child.
|
|
131
|
+
const locale = childLocale === "__none__" ? null : childLocale;
|
|
132
|
+
return runChild(config, locale);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Single-locale (or unspecified) fast path: skip subprocess fanout.
|
|
136
|
+
// There's no ESM-cache-leak risk to guard against because only one
|
|
137
|
+
// locale will run in this process. Sitemap/hreflang are also no-ops
|
|
138
|
+
// when there's only one locale.
|
|
139
|
+
const startedAt = Date.now();
|
|
140
|
+
const isMulti = config.locales.length > 1;
|
|
141
|
+
|
|
142
|
+
if (!isMulti) {
|
|
143
|
+
const locale = config.locales[0];
|
|
144
|
+
console.log(`🌍 Prerendering ${config.pages.length} page(s)${locale ? ` (${locale})` : ""}…`);
|
|
145
|
+
console.log();
|
|
146
|
+
await runChild(config, locale);
|
|
147
|
+
const elapsed = ((Date.now() - startedAt) / 1000).toFixed(1);
|
|
148
|
+
console.log(`✅ Prerender done in ${elapsed}s — ${config.pages.length} page(s)`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Multi-locale: fan out one subprocess per locale, sequentially
|
|
153
|
+
// (parallel would scramble console output and risk thrashing CPU).
|
|
154
|
+
console.log(`🌍 Prerendering ${config.locales.length} locales × ${config.pages.length} pages…`);
|
|
155
|
+
console.log();
|
|
156
|
+
|
|
157
|
+
let failures = 0;
|
|
158
|
+
for (const locale of config.locales) {
|
|
159
|
+
const label = locale ?? "(default)";
|
|
160
|
+
console.log(`── ${label} ${"─".repeat(60 - String(label).length - 3)}`);
|
|
161
|
+
const ok = await runLocaleSubprocess(locale);
|
|
162
|
+
if (!ok) failures++;
|
|
163
|
+
console.log();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const elapsed = ((Date.now() - startedAt) / 1000).toFixed(1);
|
|
167
|
+
if (failures > 0) {
|
|
168
|
+
console.error(`❌ Prerender finished with ${failures}/${config.locales.length} failures in ${elapsed}s`);
|
|
169
|
+
throw new Error(`prerenderSite: ${failures} locale(s) failed`);
|
|
170
|
+
}
|
|
171
|
+
console.log(`✅ Prerender done in ${elapsed}s — ${config.locales.length} locales × ${config.pages.length} pages`);
|
|
172
|
+
|
|
173
|
+
if (config.sitemap !== false) {
|
|
174
|
+
await writeSitemap(config);
|
|
175
|
+
console.log(`✅ Sitemap regenerated — ${config.pages.length * config.locales.length} URLs`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function validateConfig(config) {
|
|
180
|
+
// Hard requirements — no sensible defaults possible.
|
|
181
|
+
const required = ["origin", "uploadDir", "pages"];
|
|
182
|
+
for (const k of required) {
|
|
183
|
+
if (!config[k]) throw new Error(`prerenderSite: config.${k} is required`);
|
|
184
|
+
}
|
|
185
|
+
if (!Array.isArray(config.pages) || config.pages.length === 0) {
|
|
186
|
+
throw new Error("prerenderSite: config.pages must be a non-empty array");
|
|
187
|
+
}
|
|
188
|
+
for (const p of config.pages) {
|
|
189
|
+
if (!p.html || !p.entry) {
|
|
190
|
+
throw new Error("prerenderSite: each page needs { html, entry }");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Soft defaults for the locale config — a single-locale site
|
|
195
|
+
// doesn't need to declare anything beyond the implicit "default".
|
|
196
|
+
// We mutate config here so the rest of the file can assume both
|
|
197
|
+
// keys are populated.
|
|
198
|
+
if (!config.defaultLocale && !config.locales) {
|
|
199
|
+
// Fully unspecified — single-locale build, no locale tagging.
|
|
200
|
+
// Use a sentinel `null` so subsequent code can skip <html lang>,
|
|
201
|
+
// hreflang, and localStorage injection.
|
|
202
|
+
config.defaultLocale = null;
|
|
203
|
+
config.locales = [null];
|
|
204
|
+
} else if (!config.locales) {
|
|
205
|
+
// Default declared but no list given — single-locale build at
|
|
206
|
+
// the root with that default locale's <html lang>.
|
|
207
|
+
config.locales = [config.defaultLocale];
|
|
208
|
+
} else if (!Array.isArray(config.locales) || config.locales.length === 0) {
|
|
209
|
+
throw new Error("prerenderSite: config.locales must be a non-empty array");
|
|
210
|
+
} else if (!config.defaultLocale) {
|
|
211
|
+
// Locales given but no default — assume the first entry is the
|
|
212
|
+
// one whose pages live at the root.
|
|
213
|
+
config.defaultLocale = config.locales[0];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (config.defaultLocale && !config.locales.includes(config.defaultLocale)) {
|
|
217
|
+
throw new Error(`prerenderSite: config.defaultLocale "${config.defaultLocale}" not in config.locales`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Spawn a Node subprocess running the SAME script the parent did,
|
|
223
|
+
* with NODALITY_SSG_LOCALE set so the child enters child-mode.
|
|
224
|
+
*/
|
|
225
|
+
function runLocaleSubprocess(locale) {
|
|
226
|
+
return new Promise((resolve) => {
|
|
227
|
+
// process.argv[1] is the entry script of the parent — typically
|
|
228
|
+
// the consumer's `scripts/prerender.mjs`. Re-invoke it so the
|
|
229
|
+
// child has the same imports + same config call.
|
|
230
|
+
const entry = process.argv[1];
|
|
231
|
+
if (!entry) {
|
|
232
|
+
console.error("prerenderSite: cannot determine entry script for subprocess");
|
|
233
|
+
resolve(false);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
// Encode null locale as a sentinel string so it survives the env
|
|
237
|
+
// round-trip (env vars are always strings).
|
|
238
|
+
const localeStr = locale === null ? "__none__" : locale;
|
|
239
|
+
const child = spawn(process.execPath, [entry], {
|
|
240
|
+
cwd: process.cwd(),
|
|
241
|
+
env: { ...process.env, [ENV_LOCALE]: localeStr },
|
|
242
|
+
stdio: "inherit",
|
|
243
|
+
});
|
|
244
|
+
child.on("exit", (code) => resolve(code === 0));
|
|
245
|
+
child.on("error", (err) => {
|
|
246
|
+
console.error(`subprocess for ${locale} failed to start: ${err.message}`);
|
|
247
|
+
resolve(false);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Render one locale. Reads each page's template, runs the entry
|
|
254
|
+
* script in jsdom via `prerender()`, post-processes the output to
|
|
255
|
+
* absolutize asset paths, and writes the file.
|
|
256
|
+
*/
|
|
257
|
+
async function runChild(config, locale) {
|
|
258
|
+
const {
|
|
259
|
+
origin,
|
|
260
|
+
uploadDir,
|
|
261
|
+
defaultLocale,
|
|
262
|
+
pages,
|
|
263
|
+
mount = "#mount",
|
|
264
|
+
viewport = { width: 390, height: 844 },
|
|
265
|
+
assetPrefixes = DEFAULT_ASSET_PREFIXES,
|
|
266
|
+
localStorageKey = "h7lang",
|
|
267
|
+
} = config;
|
|
268
|
+
|
|
269
|
+
// A null locale (single-locale, untagged) always renders to the
|
|
270
|
+
// root. Any other locale goes to root only if it equals the default.
|
|
271
|
+
const isSubdir = locale !== null && locale !== defaultLocale;
|
|
272
|
+
const localeDir = isSubdir ? path.join(uploadDir, locale) : uploadDir;
|
|
273
|
+
await fs.mkdir(localeDir, { recursive: true });
|
|
274
|
+
|
|
275
|
+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), `nodality-ssg-${locale}-`));
|
|
276
|
+
const stamp = Date.now();
|
|
277
|
+
|
|
278
|
+
// Asset-path rewrite regex (only for non-default locales). The
|
|
279
|
+
// lookbehind `(?<!\.)` is critical — without it the `./` in
|
|
280
|
+
// `../assets/` would match and silently re-break head paths.
|
|
281
|
+
const assetRewriteRe = new RegExp(
|
|
282
|
+
`(?<!\\.)\\.\\/(?=(?:${assetPrefixes.join("|")}))`,
|
|
283
|
+
"g"
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
for (const page of pages) {
|
|
288
|
+
const srcHtml = path.join(uploadDir, page.html);
|
|
289
|
+
const entryPath = path.join(uploadDir, page.entry);
|
|
290
|
+
const outPath = path.join(localeDir, page.html);
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
await fs.access(entryPath);
|
|
294
|
+
} catch {
|
|
295
|
+
console.warn(` ⚠️ ${page.html} skipped — entry ${page.entry} not found`);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Build a clean template from the live HTML — strip prior
|
|
300
|
+
// prerender output from #mount, rewrite head asset paths
|
|
301
|
+
// (./xxx → ../xxx) for non-default locales.
|
|
302
|
+
const tmplPath = path.join(tmpDir, page.html);
|
|
303
|
+
await fs.writeFile(tmplPath, await buildCleanTemplate(srcHtml, isSubdir, mount));
|
|
304
|
+
|
|
305
|
+
process.stdout.write(` ${page.html.padEnd(22)} `);
|
|
306
|
+
|
|
307
|
+
try {
|
|
308
|
+
// Build the prerender call. Locale-related options are
|
|
309
|
+
// skipped when this is a single-locale-untagged build
|
|
310
|
+
// (locale === null) so the static output has no <html lang>,
|
|
311
|
+
// no canonical, no hreflang, no localStorage seed. The
|
|
312
|
+
// consumer's site looks like a vanilla single-page build.
|
|
313
|
+
const isLocaleAware = locale !== null;
|
|
314
|
+
const result = await prerender({
|
|
315
|
+
template: tmplPath,
|
|
316
|
+
output: outPath,
|
|
317
|
+
mount,
|
|
318
|
+
locale: isLocaleAware ? locale : undefined,
|
|
319
|
+
localStorageKey,
|
|
320
|
+
viewport,
|
|
321
|
+
url: urlFor(config, locale, page.html),
|
|
322
|
+
htmlLang: isLocaleAware ? locale : undefined,
|
|
323
|
+
canonical: isLocaleAware && config.locales.length > 1
|
|
324
|
+
? urlFor(config, locale, page.html)
|
|
325
|
+
: undefined,
|
|
326
|
+
alternates: isLocaleAware && config.locales.length > 1
|
|
327
|
+
? alternatesFor(config, page.html)
|
|
328
|
+
: undefined,
|
|
329
|
+
build: async () => {
|
|
330
|
+
const importUrl = `${pathToFileURL(entryPath).href}?t=${stamp}-${page.entry}`;
|
|
331
|
+
await import(importUrl);
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Post-process body asset paths only for non-default locales.
|
|
336
|
+
if (isSubdir) {
|
|
337
|
+
let html = await fs.readFile(outPath, "utf8");
|
|
338
|
+
const before = html.length;
|
|
339
|
+
html = html.replace(assetRewriteRe, "/");
|
|
340
|
+
if (html.length !== before) {
|
|
341
|
+
await fs.writeFile(outPath, html, "utf8");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
console.log(`→ ${path.relative(uploadDir, outPath).padEnd(40)} ${(result.bytes / 1024).toFixed(1).padStart(6)} KB`);
|
|
346
|
+
} catch (err) {
|
|
347
|
+
console.log(`✘ FAILED`);
|
|
348
|
+
console.error(` ${err.message}`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
} finally {
|
|
352
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Read the live HTML at `htmlPath`, strip everything inside the
|
|
358
|
+
* mount container, and (for non-default locales) rewrite head
|
|
359
|
+
* <script src>/<link href>/importmap paths from `./` to `../` so
|
|
360
|
+
* they resolve one directory up from the locale's subdir.
|
|
361
|
+
*/
|
|
362
|
+
async function buildCleanTemplate(htmlPath, isSubdir, mount) {
|
|
363
|
+
// Lazy import jsdom so this module can be loaded in environments
|
|
364
|
+
// that haven't installed it (same pattern as prerender.js).
|
|
365
|
+
const { JSDOM } = await import("jsdom");
|
|
366
|
+
const live = await fs.readFile(htmlPath, "utf8");
|
|
367
|
+
const dom = new JSDOM(live);
|
|
368
|
+
const doc = dom.window.document;
|
|
369
|
+
|
|
370
|
+
// Empty the mount so prerender starts fresh (idempotent re-runs).
|
|
371
|
+
const mountEl = doc.querySelector(mount);
|
|
372
|
+
if (mountEl) mountEl.innerHTML = "";
|
|
373
|
+
|
|
374
|
+
if (isSubdir) {
|
|
375
|
+
for (const el of doc.querySelectorAll('script[src^="./"]')) {
|
|
376
|
+
el.setAttribute("src", "../" + el.getAttribute("src").slice(2));
|
|
377
|
+
}
|
|
378
|
+
for (const el of doc.querySelectorAll('link[href^="./"]')) {
|
|
379
|
+
el.setAttribute("href", "../" + el.getAttribute("href").slice(2));
|
|
380
|
+
}
|
|
381
|
+
for (const im of doc.querySelectorAll('script[type="importmap"]')) {
|
|
382
|
+
const text = im.textContent || "";
|
|
383
|
+
im.textContent = text.replace(/"\.\//g, '"../');
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const cleaned = dom.serialize();
|
|
388
|
+
dom.window.close();
|
|
389
|
+
return cleaned;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** URL for a (locale, page) pair under this site's origin. */
|
|
393
|
+
function urlFor(config, locale, page) {
|
|
394
|
+
// Null locale (untagged) and the default locale both live at root.
|
|
395
|
+
const slash = (locale === null || locale === config.defaultLocale) ? "" : `${locale}/`;
|
|
396
|
+
const tail = page === "index.html" ? slash : `${slash}${page}`;
|
|
397
|
+
return `${config.origin}/${tail}`;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** hreflang alternates for one page (all locales + x-default). */
|
|
401
|
+
function alternatesFor(config, page) {
|
|
402
|
+
const xDefault = config.xDefaultLocale || config.defaultLocale;
|
|
403
|
+
const alts = config.locales.map((l) => ({ hreflang: l, href: urlFor(config, l, page) }));
|
|
404
|
+
alts.push({ hreflang: "x-default", href: urlFor(config, xDefault, page) });
|
|
405
|
+
return alts;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Write the sitemap.xml covering every (locale, page) URL. */
|
|
409
|
+
async function writeSitemap(config) {
|
|
410
|
+
const now = new Date().toISOString().slice(0, 10);
|
|
411
|
+
const entries = [];
|
|
412
|
+
for (const page of config.pages) {
|
|
413
|
+
for (const locale of config.locales) {
|
|
414
|
+
const loc = urlFor(config, locale, page.html);
|
|
415
|
+
const alts = alternatesFor(config, page.html);
|
|
416
|
+
const altLines = alts
|
|
417
|
+
.map((a) => ` <xhtml:link rel="alternate" hreflang="${a.hreflang}" href="${a.href}" />`)
|
|
418
|
+
.join("\n");
|
|
419
|
+
const priority = page.html === "index.html" ? "1.0"
|
|
420
|
+
: (page.html === "privacy.html" || page.html === "delete-account.html") ? "0.4"
|
|
421
|
+
: "0.8";
|
|
422
|
+
const changefreq = (page.html === "privacy.html" || page.html === "delete-account.html")
|
|
423
|
+
? "yearly" : "monthly";
|
|
424
|
+
entries.push(
|
|
425
|
+
` <url>\n` +
|
|
426
|
+
` <loc>${loc}</loc>\n` +
|
|
427
|
+
` <lastmod>${now}</lastmod>\n` +
|
|
428
|
+
` <changefreq>${changefreq}</changefreq>\n` +
|
|
429
|
+
` <priority>${priority}</priority>\n` +
|
|
430
|
+
altLines + "\n" +
|
|
431
|
+
` </url>`
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const xml =
|
|
436
|
+
`<?xml version="1.0" encoding="UTF-8"?>\n` +
|
|
437
|
+
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"\n` +
|
|
438
|
+
` xmlns:xhtml="http://www.w3.org/1999/xhtml">\n` +
|
|
439
|
+
entries.join("\n") + "\n" +
|
|
440
|
+
`</urlset>\n`;
|
|
441
|
+
await fs.writeFile(path.join(config.uploadDir, "sitemap.xml"), xml, "utf8");
|
|
442
|
+
}
|
package/layout/prerender.js
CHANGED
package/layout/progress.js
CHANGED
package/layout/row.js
CHANGED
package/layout/scroll-video.js
CHANGED
package/layout/side-bar.js
CHANGED
package/layout/side-nav-bar.js
CHANGED
package/layout/simple-bar.js
CHANGED
package/layout/slider-2025.js
CHANGED
package/layout/spacer.js
CHANGED
package/layout/stack.js
CHANGED
package/layout/styler.js
CHANGED
package/layout/svg.js
CHANGED
package/layout/switcher.js
CHANGED
package/layout/table.js
CHANGED
package/layout/text-field.js
CHANGED
package/layout/text.js
CHANGED
package/layout/ulist.js
CHANGED
package/layout/video.js
CHANGED
package/layout/without-new.js
CHANGED
package/layout/wrap.js
CHANGED
package/layout/zoom-card.js
CHANGED
package/lib/card-getter.js
CHANGED
package/lib/designer.js
CHANGED
package/lib/element-mapper.js
CHANGED
package/lib/link-getter.js
CHANGED
package/lib/scroll-video.js
CHANGED