@v-office/site-checks 0.0.1 → 0.2.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.
- package/README.md +151 -3
- package/dist/astro.d.mts +37 -0
- package/dist/astro.mjs +56 -0
- package/dist/dist-checks.d.mts +21 -0
- package/dist/dist-checks.mjs +410 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +2 -0
- package/dist/options-CANJso9Q.d.mts +95 -0
- package/dist/report-xp_FHnYb.mjs +2538 -0
- package/dist/runner-CK4iXk8Z.d.mts +169 -0
- package/instructions/CHANGELOG.md +2 -0
- package/instructions/MIGRATION.md +2 -0
- package/instructions/versions/0.1.0/CHANGELOG.md +79 -0
- package/instructions/versions/0.1.0/MIGRATION.md +61 -0
- package/instructions/versions/0.2.0/CHANGELOG.md +64 -0
- package/instructions/versions/0.2.0/MIGRATION.md +65 -0
- package/package.json +33 -4
- package/index.js +0 -2
|
@@ -0,0 +1,2538 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseHTML } from "linkedom";
|
|
4
|
+
import { brotliCompressSync, constants } from "node:zlib";
|
|
5
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
//#region src/checks/consentGate.ts
|
|
8
|
+
/** The consent kit's files in a site: its presence under `src/lib/consent/` is what makes the
|
|
9
|
+
* check apply; the vendors the site enables and the fleet registry's review of them. */
|
|
10
|
+
const KIT_DIR = "src/lib/consent/";
|
|
11
|
+
const ENABLED_FILE = "src/data/consent.ts";
|
|
12
|
+
const REGISTRY_FILE = "src/data/consent-registry.snapshot.json";
|
|
13
|
+
/** The kit's click-to-load frame (`ConsentEmbed.astro`): a third-party frame inside it loads after
|
|
14
|
+
* consent, so it is not a leak. */
|
|
15
|
+
const EMBED_TEMPLATE = "template[data-embed-content]";
|
|
16
|
+
const hostOf = (url) => {
|
|
17
|
+
try {
|
|
18
|
+
return new URL(url).host;
|
|
19
|
+
} catch {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/** No third-party script or iframe loads outside the consent layer (the kit injects a vendor's
|
|
24
|
+
* script after consent, so one in the HTML loads before it), and no vendor the site enables is
|
|
25
|
+
* still unapproved in the fleet's consent registry. Skipped in a project without the kit. */
|
|
26
|
+
const consentGate = {
|
|
27
|
+
id: "consent-gate",
|
|
28
|
+
title: "Third-party resources wait for consent",
|
|
29
|
+
severity: "error",
|
|
30
|
+
begin: (ctx) => {
|
|
31
|
+
const sources = ctx.sourceFiles(/* @__PURE__ */ new Set([".ts", ".json"]));
|
|
32
|
+
const byRel = new Map(sources.map((file) => [ctx.rel(file), file]));
|
|
33
|
+
if (![...byRel.keys()].some((rel) => rel.startsWith(KIT_DIR))) return null;
|
|
34
|
+
const siteHost = ctx.config.site ? hostOf(ctx.config.site) : void 0;
|
|
35
|
+
const allowed = new Set(ctx.options.consentAllowedHosts);
|
|
36
|
+
const findings = [];
|
|
37
|
+
return {
|
|
38
|
+
visit: (page) => {
|
|
39
|
+
for (const el of page.document.querySelectorAll("script[src], iframe[src]")) {
|
|
40
|
+
const raw = (el.getAttribute("src") ?? "").trim();
|
|
41
|
+
const src = raw.startsWith("//") ? `https:${raw}` : raw;
|
|
42
|
+
if (!/^https?:\/\//i.test(src)) continue;
|
|
43
|
+
const host = hostOf(src);
|
|
44
|
+
if (!host || host === siteHost || allowed.has(host)) continue;
|
|
45
|
+
if (el.closest(EMBED_TEMPLATE)) continue;
|
|
46
|
+
findings.push({
|
|
47
|
+
path: page.path,
|
|
48
|
+
message: `A third-party <${el.tagName.toLowerCase()}> from ${host} loads before consent. Frame it with ConsentEmbed, or register the vendor so the kit injects it after consent; list a consent-free host in consentAllowedHosts.`
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
finish: () => {
|
|
53
|
+
const enabledFile = byRel.get(ENABLED_FILE);
|
|
54
|
+
const registryFile = byRel.get(REGISTRY_FILE);
|
|
55
|
+
if (!enabledFile || !registryFile) return findings;
|
|
56
|
+
const enabled = ctx.readSource(enabledFile).match(/ENABLED_VENDOR_IDS\b[^=]*=\s*\[([^\]]*)\]/);
|
|
57
|
+
if (!enabled) return findings;
|
|
58
|
+
const ids = [...enabled[1].matchAll(/["'`]([^"'`]+)["'`]/g)].map((m) => m[1]);
|
|
59
|
+
const registry = JSON.parse(ctx.readSource(registryFile));
|
|
60
|
+
const status = new Map((registry.vendors ?? []).map((v) => [v.id, v.reviewStatus]));
|
|
61
|
+
for (const id of ids) if (!status.has(id)) findings.push({
|
|
62
|
+
path: ENABLED_FILE,
|
|
63
|
+
message: `The enabled vendor "${id}" is not in the consent registry.`
|
|
64
|
+
});
|
|
65
|
+
else if (status.get(id) !== "approved") findings.push({
|
|
66
|
+
path: ENABLED_FILE,
|
|
67
|
+
message: `The enabled vendor "${id}" is "${status.get(id)}" in the consent registry, not approved.`
|
|
68
|
+
});
|
|
69
|
+
return findings;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/context.ts
|
|
76
|
+
const SKIPPED_TEXT_TAGS = /* @__PURE__ */ new Set([
|
|
77
|
+
"SCRIPT",
|
|
78
|
+
"STYLE",
|
|
79
|
+
"NOSCRIPT",
|
|
80
|
+
"TEMPLATE"
|
|
81
|
+
]);
|
|
82
|
+
const collectFiles = (dir, base = dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
83
|
+
const full = path.join(dir, entry.name);
|
|
84
|
+
return entry.isDirectory() ? collectFiles(full, base) : [path.relative(base, full).split(path.sep).join("/")];
|
|
85
|
+
});
|
|
86
|
+
function* filesUnder(dir, extensions) {
|
|
87
|
+
if (!fs.existsSync(dir)) return;
|
|
88
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
89
|
+
const full = path.join(dir, entry.name);
|
|
90
|
+
if (entry.isDirectory()) {
|
|
91
|
+
if (entry.name !== "node_modules") yield* filesUnder(full, extensions);
|
|
92
|
+
} else if (extensions.has(path.extname(entry.name).toLowerCase())) yield full;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** `about-us/index.html` → `/about-us/`, `imprint.html` → `/imprint`, `index.html` → `/`. */
|
|
96
|
+
const fileToUrl = (file) => {
|
|
97
|
+
if (file === "index.html") return "/";
|
|
98
|
+
if (file.endsWith("/index.html")) return `/${file.slice(0, -10)}`;
|
|
99
|
+
if (file.endsWith(".html")) return `/${file.slice(0, -5)}`;
|
|
100
|
+
return `/${file}`;
|
|
101
|
+
};
|
|
102
|
+
const textOf$1 = (node) => {
|
|
103
|
+
let text = "";
|
|
104
|
+
for (const child of node.childNodes) if (child.nodeType === 3) text += child.textContent ?? "";
|
|
105
|
+
else if (child.nodeType === 1) {
|
|
106
|
+
const el = child;
|
|
107
|
+
if (!SKIPPED_TEXT_TAGS.has(el.tagName)) text += ` ${textOf$1(el)} `;
|
|
108
|
+
}
|
|
109
|
+
return text;
|
|
110
|
+
};
|
|
111
|
+
const commentsOf = (node, into) => {
|
|
112
|
+
for (const child of node.childNodes) if (child.nodeType === 8) into.push(child.textContent ?? "");
|
|
113
|
+
else if (child.nodeType === 1) commentsOf(child, into);
|
|
114
|
+
};
|
|
115
|
+
const readPackageJson = (root) => {
|
|
116
|
+
const file = path.join(root, "package.json");
|
|
117
|
+
if (!fs.existsSync(file)) return {
|
|
118
|
+
dependencies: {},
|
|
119
|
+
devDependencies: {}
|
|
120
|
+
};
|
|
121
|
+
const pkg = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
122
|
+
return {
|
|
123
|
+
dependencies: pkg.dependencies ?? {},
|
|
124
|
+
devDependencies: pkg.devDependencies ?? {}
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/** Lists `distDir` once. Throws when it cannot be read: the runner fails every check then. */
|
|
128
|
+
const loadBuildOutput = (distDir) => {
|
|
129
|
+
const files = collectFiles(distDir).sort();
|
|
130
|
+
const fileSet = new Set(files);
|
|
131
|
+
const serves = (urlPath) => {
|
|
132
|
+
let p = urlPath.split(/[?#]/, 1)[0] ?? "";
|
|
133
|
+
try {
|
|
134
|
+
p = decodeURIComponent(p);
|
|
135
|
+
} catch {}
|
|
136
|
+
p = p.replace(/^\/+/, "");
|
|
137
|
+
if (p === "") return fileSet.has("index.html");
|
|
138
|
+
if (p.endsWith("/")) return fileSet.has(`${p}index.html`);
|
|
139
|
+
return fileSet.has(p) || fileSet.has(`${p}/index.html`) || fileSet.has(`${p}.html`);
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
distDir,
|
|
143
|
+
files,
|
|
144
|
+
has: (file) => fileSet.has(file),
|
|
145
|
+
read: (file) => fs.readFileSync(path.join(distDir, file), "utf8"),
|
|
146
|
+
serves
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
/** No `dist/`: no files, nothing served. */
|
|
150
|
+
const noBuildOutput = (distDir) => ({
|
|
151
|
+
distDir,
|
|
152
|
+
files: [],
|
|
153
|
+
has: () => false,
|
|
154
|
+
read: (file) => {
|
|
155
|
+
throw new Error(`No built output to read ${file} from`);
|
|
156
|
+
},
|
|
157
|
+
serves: () => false
|
|
158
|
+
});
|
|
159
|
+
const loadDistContext = (distDir, opts) => ({
|
|
160
|
+
...loadBuildOutput(distDir),
|
|
161
|
+
isAstro: opts.isAstro,
|
|
162
|
+
origin: opts.siteUrl ? new URL(opts.siteUrl).origin : void 0
|
|
163
|
+
});
|
|
164
|
+
const loadContext = (input) => {
|
|
165
|
+
const { root, srcDir, publicDir, distDir, config, options } = input;
|
|
166
|
+
const hasDist = fs.existsSync(distDir);
|
|
167
|
+
return {
|
|
168
|
+
...hasDist ? loadBuildOutput(distDir) : noBuildOutput(distDir),
|
|
169
|
+
root,
|
|
170
|
+
srcDir,
|
|
171
|
+
publicDir,
|
|
172
|
+
hasDist,
|
|
173
|
+
config,
|
|
174
|
+
options,
|
|
175
|
+
sourceFiles: (extensions) => [...filesUnder(srcDir, extensions)].sort(),
|
|
176
|
+
readSource: (absolute) => fs.readFileSync(absolute, "utf8"),
|
|
177
|
+
rel: (absolute) => path.relative(root, absolute).split(path.sep).join("/"),
|
|
178
|
+
packageJson: readPackageJson(root)
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
const readPage = (ctx, file) => {
|
|
182
|
+
const url = fileToUrl(file);
|
|
183
|
+
const { document } = parseHTML(ctx.read(file));
|
|
184
|
+
const baseHref = document.querySelector("base[href]")?.getAttribute("href");
|
|
185
|
+
const base = baseHref ? new URL(baseHref, `http://site.invalid${url}`).pathname : url;
|
|
186
|
+
const redirect = [...document.querySelectorAll("meta[http-equiv]")].some((meta) => meta.getAttribute("http-equiv")?.toLowerCase() === "refresh");
|
|
187
|
+
const noindex = [...document.querySelectorAll("meta[name=\"robots\"]")].some((meta) => /\bnoindex\b/i.test(meta.getAttribute("content") ?? ""));
|
|
188
|
+
const root = document.documentElement;
|
|
189
|
+
let text;
|
|
190
|
+
const visibleText = () => {
|
|
191
|
+
if (text === void 0) {
|
|
192
|
+
const body = document.body ?? root;
|
|
193
|
+
text = body ? textOf$1(body).replace(/\s+/g, " ").trim() : "";
|
|
194
|
+
}
|
|
195
|
+
return text;
|
|
196
|
+
};
|
|
197
|
+
let attributes;
|
|
198
|
+
const attributeValues = () => {
|
|
199
|
+
if (attributes === void 0) {
|
|
200
|
+
attributes = [];
|
|
201
|
+
for (const el of document.querySelectorAll("*")) for (const name of el.getAttributeNames()) {
|
|
202
|
+
const value = el.getAttribute(name);
|
|
203
|
+
if (value) attributes.push(value);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return attributes;
|
|
207
|
+
};
|
|
208
|
+
let comments;
|
|
209
|
+
return {
|
|
210
|
+
path: file,
|
|
211
|
+
url,
|
|
212
|
+
base,
|
|
213
|
+
redirect,
|
|
214
|
+
noindex,
|
|
215
|
+
document,
|
|
216
|
+
visibleText,
|
|
217
|
+
attributeValues,
|
|
218
|
+
comments: () => {
|
|
219
|
+
if (comments === void 0) {
|
|
220
|
+
comments = [];
|
|
221
|
+
if (root) commentsOf(root, comments);
|
|
222
|
+
}
|
|
223
|
+
return comments;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
/** Elements that start a new line of text: their text never runs into the text beside them. */
|
|
228
|
+
const BLOCK_TAGS = new Set("ADDRESS ARTICLE ASIDE BLOCKQUOTE BR DD DETAILS DIV DL DT FIGCAPTION FIGURE FOOTER H1 H2 H3 H4 H5 H6 HEADER HR LI MAIN NAV OL P PRE SECTION SUMMARY TABLE TD TH TR UL".split(" "));
|
|
229
|
+
/** An element's readable text, whitespace collapsed: a space at every block boundary, so
|
|
230
|
+
* `<p>Schön.</p><p>3 Zimmer.</p>` reads "Schön. 3 Zimmer.", and none inside a word split across
|
|
231
|
+
* inline elements (`<b>Ha</b>us` stays "Haus"). Script, style, noscript and template text is left
|
|
232
|
+
* out. */
|
|
233
|
+
const blockText = (el) => {
|
|
234
|
+
if (!el) return "";
|
|
235
|
+
const walk = (node) => {
|
|
236
|
+
let text = "";
|
|
237
|
+
for (const child of node.childNodes) if (child.nodeType === 3) text += child.textContent ?? "";
|
|
238
|
+
else if (child.nodeType === 1) {
|
|
239
|
+
const inner = child;
|
|
240
|
+
if (SKIPPED_TEXT_TAGS.has(inner.tagName)) continue;
|
|
241
|
+
text += BLOCK_TAGS.has(inner.tagName) ? ` ${walk(inner)} ` : walk(inner);
|
|
242
|
+
}
|
|
243
|
+
return text;
|
|
244
|
+
};
|
|
245
|
+
return walk(el).replace(/\s+/g, " ").trim();
|
|
246
|
+
};
|
|
247
|
+
/** Same-site URL references only: no scheme (`https:`, `mailto:`, `tel:`, `data:`, …), not
|
|
248
|
+
* protocol-relative, not a fragment — or an absolute URL on the site's own `origin`. */
|
|
249
|
+
const isSameSiteReference = (value, origin) => {
|
|
250
|
+
const v = value.trim();
|
|
251
|
+
if (v === "" || v.startsWith("#") || v.startsWith("//")) return false;
|
|
252
|
+
if (!/^[a-z][a-z0-9+.-]*:/i.test(v)) return true;
|
|
253
|
+
if (!origin) return false;
|
|
254
|
+
try {
|
|
255
|
+
return new URL(v).origin === origin;
|
|
256
|
+
} catch {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/** Resolves a same-site reference against the page it appears on; the URL path only. */
|
|
261
|
+
const resolveReference = (page, value) => new URL(value.trim(), `http://site.invalid${page.base}`).pathname;
|
|
262
|
+
/** The URLs an element references: `href`, `src`, `poster`, every `srcset` candidate. */
|
|
263
|
+
const referencedUrls = (el) => {
|
|
264
|
+
const urls = [];
|
|
265
|
+
for (const attr of [
|
|
266
|
+
"href",
|
|
267
|
+
"src",
|
|
268
|
+
"poster"
|
|
269
|
+
]) {
|
|
270
|
+
const value = el.getAttribute(attr);
|
|
271
|
+
if (value) urls.push(value);
|
|
272
|
+
}
|
|
273
|
+
const srcset = el.getAttribute("srcset");
|
|
274
|
+
if (srcset) for (const candidate of srcset.split(",")) {
|
|
275
|
+
const url = candidate.trim().split(/\s+/, 1)[0];
|
|
276
|
+
if (url) urls.push(url);
|
|
277
|
+
}
|
|
278
|
+
return urls;
|
|
279
|
+
};
|
|
280
|
+
/** The text of an XML element as a value: `&`, `<`, `>`, `"`, `'` and numeric
|
|
281
|
+
* character references decoded. A sitemap writes `/sonne-&-meer/` as `/sonne-&-meer/`. */
|
|
282
|
+
const xmlText = (text) => text.replace(/&(?:#x([0-9a-f]+)|#(\d+)|(amp|lt|gt|quot|apos));/gi, (entity, hex, dec, name) => {
|
|
283
|
+
if (hex) return String.fromCodePoint(parseInt(hex, 16));
|
|
284
|
+
if (dec) return String.fromCodePoint(parseInt(dec, 10));
|
|
285
|
+
return {
|
|
286
|
+
amp: "&",
|
|
287
|
+
lt: "<",
|
|
288
|
+
gt: ">",
|
|
289
|
+
quot: "\"",
|
|
290
|
+
apos: "'"
|
|
291
|
+
}[name.toLowerCase()] ?? entity;
|
|
292
|
+
});
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/checks/copy.ts
|
|
295
|
+
/** Pages the copy checks read: not a redirect stub, not the 404 page, not an excluded path. An
|
|
296
|
+
* entry covers the path and everything below it, with or without a locale prefix: `/impressum`
|
|
297
|
+
* also covers `/de/impressum`. */
|
|
298
|
+
const excluded = (page, paths) => {
|
|
299
|
+
if (page.redirect || page.path === "404.html") return true;
|
|
300
|
+
const url = page.url.length > 1 ? page.url.replace(/\/+$/, "") : page.url;
|
|
301
|
+
const unprefixed = url.replace(/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i, "") || "/";
|
|
302
|
+
return paths.some((entry) => {
|
|
303
|
+
const p = `/${entry.replace(/^\/+|\/+$/g, "")}`;
|
|
304
|
+
return [url, unprefixed].some((u) => u === p || u.startsWith(`${p}/`));
|
|
305
|
+
});
|
|
306
|
+
};
|
|
307
|
+
const excerpt$2 = (text, max = 90) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
308
|
+
/** Quotes and whitespace removed, lower-cased: two renderings of one sentence compare equal. */
|
|
309
|
+
const normalize$3 = (text) => text.toLowerCase().replace(/[„“”"‚’'«»]/g, "").replace(/\s+/g, " ").trim();
|
|
310
|
+
const SKIPPED = /* @__PURE__ */ new Set([
|
|
311
|
+
"SCRIPT",
|
|
312
|
+
"STYLE",
|
|
313
|
+
"NOSCRIPT",
|
|
314
|
+
"TEMPLATE"
|
|
315
|
+
]);
|
|
316
|
+
/** The elements prose lives in. A nested one counts on its own; its parent keeps only its own
|
|
317
|
+
* text, so a card heading is never glued onto the sentence of the `<p>` below it. */
|
|
318
|
+
const BLOCKS = /* @__PURE__ */ new Set([
|
|
319
|
+
"P",
|
|
320
|
+
"H1",
|
|
321
|
+
"H2",
|
|
322
|
+
"H3",
|
|
323
|
+
"H4",
|
|
324
|
+
"H5",
|
|
325
|
+
"H6",
|
|
326
|
+
"LI",
|
|
327
|
+
"BLOCKQUOTE",
|
|
328
|
+
"FIGCAPTION",
|
|
329
|
+
"DT",
|
|
330
|
+
"DD"
|
|
331
|
+
]);
|
|
332
|
+
/** A block's own text: nested prose blocks left out (they count on their own), inline elements
|
|
333
|
+
* joined as rendered, so `<em>Deich</em>.` reads "Deich." and not "Deich .". */
|
|
334
|
+
const ownText = (el) => {
|
|
335
|
+
const walk = (node) => {
|
|
336
|
+
let text = "";
|
|
337
|
+
for (const child of node.childNodes) if (child.nodeType === 3) text += child.textContent ?? "";
|
|
338
|
+
else if (child.nodeType === 1) {
|
|
339
|
+
const inner = child;
|
|
340
|
+
if (inner.tagName === "BR") text += " ";
|
|
341
|
+
else if (!SKIPPED.has(inner.tagName) && !BLOCKS.has(inner.tagName)) text += walk(inner);
|
|
342
|
+
}
|
|
343
|
+
return text;
|
|
344
|
+
};
|
|
345
|
+
return walk(el).replace(/\s+/g, " ").trim();
|
|
346
|
+
};
|
|
347
|
+
const proseBlocks = (page) => [...page.document.body?.querySelectorAll([...BLOCKS].join(",")) ?? []].filter((el) => !el.closest("script, style, noscript, template, dialog, [hidden]")).map(ownText).filter(Boolean);
|
|
348
|
+
/** A period after one of these is not a sentence end: "Nr. 07" and "ca. 80 qm" stay one sentence,
|
|
349
|
+
* so two different titles are not cut to one identical fragment. */
|
|
350
|
+
const ABBREVIATIONS = new Set("nr. str. tel. abb. bzw. ca. evtl. ggf. ggfs. inkl. exkl. z.b. u.a. hr. fr. dr. prof. st. ggü. max. min.".split(" "));
|
|
351
|
+
/** The sentences of the prose: a block split after sentence punctuation, re-joined after an
|
|
352
|
+
* abbreviation or before a leading digit. Feed labels ("4 Gäste · 2 Schlafzimmer") carry no
|
|
353
|
+
* sentence punctuation and identical cards repeat them by design, so they never count. */
|
|
354
|
+
const sentencesOf = (blocks) => blocks.flatMap((block) => {
|
|
355
|
+
const out = [];
|
|
356
|
+
for (const part of block.split(/(?<=[.!?…])\s+/)) {
|
|
357
|
+
const prev = out.at(-1);
|
|
358
|
+
const lastWord = prev?.split(/\s+/).pop()?.toLowerCase() ?? "";
|
|
359
|
+
if (prev !== void 0 && (ABBREVIATIONS.has(lastWord) || /^\d/.test(part))) out[out.length - 1] = `${prev} ${part}`;
|
|
360
|
+
else out.push(part);
|
|
361
|
+
}
|
|
362
|
+
return out;
|
|
363
|
+
}).map((s) => s.trim()).filter((s) => /[.!?…]$/.test(s));
|
|
364
|
+
/** A sentence shorter than this is a label ("Mehr erfahren."), not prose. */
|
|
365
|
+
const MIN_SENTENCE = 25;
|
|
366
|
+
/** Wordings a recorded customer correction bans, found in the rendered text of a page. A warning:
|
|
367
|
+
* the rendered text includes the feed's descriptions, and an owner's new wording must not stop the
|
|
368
|
+
* nightly builds. */
|
|
369
|
+
const bannedCopy = {
|
|
370
|
+
id: "banned-copy",
|
|
371
|
+
title: "Wordings banned by a recorded correction",
|
|
372
|
+
severity: "warning",
|
|
373
|
+
begin: (ctx) => {
|
|
374
|
+
if (!ctx.hasDist || ctx.options.bannedCopy.length === 0) return null;
|
|
375
|
+
const skip = [...ctx.options.copyExcludePaths, ...ctx.options.bannedCopyExcludePaths];
|
|
376
|
+
const bans = ctx.options.bannedCopy.map((ban) => ({
|
|
377
|
+
...ban,
|
|
378
|
+
re: new RegExp(ban.pattern, "g")
|
|
379
|
+
}));
|
|
380
|
+
const findings = [];
|
|
381
|
+
return {
|
|
382
|
+
visit: (page) => {
|
|
383
|
+
if (excluded(page, skip)) return;
|
|
384
|
+
const text = blockText(page.document.body);
|
|
385
|
+
for (const ban of bans) for (const match of text.matchAll(ban.re)) if (match[0]) findings.push({
|
|
386
|
+
path: page.path,
|
|
387
|
+
message: `"${excerpt$2(match[0], 70)}" is a banned wording: ${ban.why}`
|
|
388
|
+
});
|
|
389
|
+
},
|
|
390
|
+
finish: () => findings
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
/** The same sentence rendered twice on one page: a copy accident a reader sees at once. Within one
|
|
395
|
+
* page only; across pages a shared section and an accident look the same. Waits while every page
|
|
396
|
+
* is noindex (a site before launch repeats placeholder copy by design). A warning: the feed's
|
|
397
|
+
* descriptions are on the page too. */
|
|
398
|
+
const duplicateSentences = {
|
|
399
|
+
id: "duplicate-sentences",
|
|
400
|
+
title: "A sentence printed twice on one page",
|
|
401
|
+
severity: "warning",
|
|
402
|
+
begin: (ctx) => {
|
|
403
|
+
if (!ctx.hasDist) return null;
|
|
404
|
+
const allowed = new Set(ctx.options.allowDuplicateSentences.map(normalize$3));
|
|
405
|
+
const findings = [];
|
|
406
|
+
let indexable = 0;
|
|
407
|
+
return {
|
|
408
|
+
visit: (page) => {
|
|
409
|
+
if (!page.redirect && !page.noindex) indexable += 1;
|
|
410
|
+
if (excluded(page, ctx.options.copyExcludePaths)) return;
|
|
411
|
+
const seen = /* @__PURE__ */ new Map();
|
|
412
|
+
for (const sentence of sentencesOf(proseBlocks(page))) {
|
|
413
|
+
if (sentence.length < MIN_SENTENCE) continue;
|
|
414
|
+
const key = normalize$3(sentence);
|
|
415
|
+
const count = (seen.get(key) ?? 0) + 1;
|
|
416
|
+
seen.set(key, count);
|
|
417
|
+
if (count === 2 && !allowed.has(key)) findings.push({
|
|
418
|
+
path: page.path,
|
|
419
|
+
message: `The same sentence is rendered twice on the page: "${excerpt$2(sentence)}"`
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
finish: () => indexable === 0 ? [] : findings
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
/** A quote shorter than this is a phrase, not a quotation worth tracing. */
|
|
428
|
+
const MIN_QUOTE = 30;
|
|
429
|
+
/** Every string value of a JSON document, decoded: a review's `\"` and `\n` are its words. */
|
|
430
|
+
const jsonStrings = (value) => typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap(jsonStrings) : value && typeof value === "object" ? Object.values(value).flatMap(jsonStrings) : [];
|
|
431
|
+
/** A source file's text: a JSON file's string values, any other file as written (a Markdown
|
|
432
|
+
* capture quotes with `> `, which is not part of the words). */
|
|
433
|
+
const sourceText = (file) => {
|
|
434
|
+
const text = fs.readFileSync(file, "utf8");
|
|
435
|
+
if (file.endsWith(".json")) return jsonStrings(JSON.parse(text)).join(" ");
|
|
436
|
+
return text.replace(/^>\s?/gm, "");
|
|
437
|
+
};
|
|
438
|
+
const readSources = (root, rel) => {
|
|
439
|
+
const full = path.join(root, rel);
|
|
440
|
+
if (!fs.existsSync(full)) return null;
|
|
441
|
+
if (!fs.statSync(full).isDirectory()) return [sourceText(full)];
|
|
442
|
+
return fs.readdirSync(full, { withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => sourceText(path.join(full, entry.name)));
|
|
443
|
+
};
|
|
444
|
+
/** Every `<blockquote>` quotes, word for word, a source the site recorded (`quoteSources`): a quote
|
|
445
|
+
* matching none was paraphrased or made up. The attribution (`cite`, `footer`, `figcaption`) is
|
|
446
|
+
* not part of the quote. A configured source that is missing is a finding, not a skip: the step
|
|
447
|
+
* that writes it stopped and the check would verify nothing. */
|
|
448
|
+
const quoteSources = {
|
|
449
|
+
id: "quote-sources",
|
|
450
|
+
title: "Quotes match their sources",
|
|
451
|
+
severity: "warning",
|
|
452
|
+
begin: (ctx) => {
|
|
453
|
+
if (!ctx.hasDist || ctx.options.quoteSources.length === 0) return null;
|
|
454
|
+
const findings = [];
|
|
455
|
+
const corpusParts = [];
|
|
456
|
+
for (const rel of ctx.options.quoteSources) {
|
|
457
|
+
const parts = readSources(ctx.root, rel);
|
|
458
|
+
if (parts === null) findings.push({
|
|
459
|
+
path: rel,
|
|
460
|
+
message: `The quote source ${rel} is missing: the step that writes it did not run, so no quote was verified against it.`
|
|
461
|
+
});
|
|
462
|
+
else corpusParts.push(...parts);
|
|
463
|
+
}
|
|
464
|
+
const corpus = normalize$3(corpusParts.join(" "));
|
|
465
|
+
const where = ctx.options.quoteSources.join(", ");
|
|
466
|
+
return {
|
|
467
|
+
visit: (page) => {
|
|
468
|
+
if (excluded(page, ctx.options.copyExcludePaths)) return;
|
|
469
|
+
for (const quote of page.document.querySelectorAll("blockquote")) {
|
|
470
|
+
const copy = quote.cloneNode(true);
|
|
471
|
+
for (const attribution of copy.querySelectorAll("cite, footer, figcaption")) attribution.remove();
|
|
472
|
+
const text = blockText(copy);
|
|
473
|
+
if (text.length >= MIN_QUOTE && !corpus.includes(normalize$3(text))) findings.push({
|
|
474
|
+
path: page.path,
|
|
475
|
+
message: `A <blockquote> is not word for word in ${where}: "${excerpt$2(text)}"`
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
finish: () => findings
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/checks/donorTerms.ts
|
|
485
|
+
/** More than this and the point is made; the runner keeps 25 anyway. */
|
|
486
|
+
const MAX_RAW_FINDINGS = 100;
|
|
487
|
+
const normalize$2 = (text) => text.normalize("NFC").toLowerCase().replace(/\s+/g, " ");
|
|
488
|
+
const excerpt$1 = (haystack, term) => {
|
|
489
|
+
const at = haystack.indexOf(term);
|
|
490
|
+
const start = Math.max(0, at - 30);
|
|
491
|
+
const end = Math.min(haystack.length, at + term.length + 30);
|
|
492
|
+
return `${start > 0 ? "…" : ""}${haystack.slice(start, end)}${end < haystack.length ? "…" : ""}`;
|
|
493
|
+
};
|
|
494
|
+
/** Every site starts from a template ("donor") site, and nothing of it may ship: its brand, people,
|
|
495
|
+
* places, phone, email, domain, asset names. The site lists the terms in `site-checks.config.json`
|
|
496
|
+
* (`donorTerms`); without them the check skips, which the report shows. Matched in the visible
|
|
497
|
+
* text, the title, the inline scripts and styles (JSON-LD shows in search results) and the
|
|
498
|
+
* attributes of every built page, in the built file names and in the shipped JS and CSS, where an
|
|
499
|
+
* island's copy lives. */
|
|
500
|
+
const donorTerms = {
|
|
501
|
+
id: "donor-terms",
|
|
502
|
+
title: "Terms of the template site in the built output",
|
|
503
|
+
severity: "error",
|
|
504
|
+
begin: (ctx) => {
|
|
505
|
+
const terms = [...new Set(ctx.options.donorTerms.map(normalize$2).filter(Boolean))];
|
|
506
|
+
if (terms.length === 0 || !ctx.hasDist) return null;
|
|
507
|
+
const findings = [];
|
|
508
|
+
/** One finding per term and place: the first text of `texts` that contains it. */
|
|
509
|
+
const scan = (texts, path, where) => {
|
|
510
|
+
for (const term of terms) {
|
|
511
|
+
if (findings.length >= MAX_RAW_FINDINGS) return;
|
|
512
|
+
const hit = texts.map(normalize$2).find((haystack) => haystack.includes(term));
|
|
513
|
+
if (hit !== void 0) findings.push({
|
|
514
|
+
path,
|
|
515
|
+
message: `donor term "${term}" in ${where}: "${excerpt$1(hit, term)}"`
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
return {
|
|
520
|
+
visit: (page) => {
|
|
521
|
+
scan([page.visibleText()], page.path, "the visible text");
|
|
522
|
+
scan(page.attributeValues(), page.path, "an attribute");
|
|
523
|
+
scan([...page.document.querySelectorAll("title, script:not([src]), style")].map((el) => el.textContent ?? ""), page.path, "the title or inline code");
|
|
524
|
+
},
|
|
525
|
+
finish: () => {
|
|
526
|
+
for (const file of ctx.files) {
|
|
527
|
+
scan([file], file, "a file name");
|
|
528
|
+
if (/\.(m?js|css)$/.test(file)) scan([ctx.read(file)], file, "shipped code");
|
|
529
|
+
}
|
|
530
|
+
return findings;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/checks/htmlComments.ts
|
|
537
|
+
/** Astro passes an HTML comment in a template straight into the built page, where a visitor reads
|
|
538
|
+
* it with View Source. Markdown pages too. */
|
|
539
|
+
const SOURCE_EXTENSIONS$1 = /* @__PURE__ */ new Set([
|
|
540
|
+
".astro",
|
|
541
|
+
".tsx",
|
|
542
|
+
".jsx",
|
|
543
|
+
".md",
|
|
544
|
+
".mdx",
|
|
545
|
+
".html"
|
|
546
|
+
]);
|
|
547
|
+
const MESSAGE = "An HTML comment ships to the built page, readable with View Source. Use {/* … */} in .astro and JSX markup, // in frontmatter, and remove it from Markdown.";
|
|
548
|
+
const htmlComments = {
|
|
549
|
+
id: "html-comments",
|
|
550
|
+
title: "HTML comments in the source",
|
|
551
|
+
severity: "error",
|
|
552
|
+
begin: (ctx) => ({ finish: () => {
|
|
553
|
+
const findings = [];
|
|
554
|
+
for (const file of ctx.sourceFiles(SOURCE_EXTENSIONS$1)) {
|
|
555
|
+
const text = ctx.readSource(file);
|
|
556
|
+
let index = text.indexOf("<!--");
|
|
557
|
+
while (index !== -1) {
|
|
558
|
+
const line = text.slice(0, index).split("\n").length;
|
|
559
|
+
findings.push({
|
|
560
|
+
path: `${ctx.rel(file)}:${line}`,
|
|
561
|
+
message: MESSAGE
|
|
562
|
+
});
|
|
563
|
+
index = text.indexOf("<!--", index + 4);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return findings;
|
|
567
|
+
} })
|
|
568
|
+
};
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/checks/imageFormats.ts
|
|
571
|
+
const RASTER = /* @__PURE__ */ new Set([
|
|
572
|
+
".jpg",
|
|
573
|
+
".jpeg",
|
|
574
|
+
".png",
|
|
575
|
+
".webp"
|
|
576
|
+
]);
|
|
577
|
+
/** Icons browsers and web manifests load as PNG by name: an AVIF beside them serves nobody. */
|
|
578
|
+
const ICON = /^public\/(?:apple-touch-icon|favicon|icon-\d+)[^/]*\.png$/;
|
|
579
|
+
/** The URLs an element references for an image: `src`, `poster`, every `srcset` candidate. */
|
|
580
|
+
const imageUrls = (el) => {
|
|
581
|
+
const urls = [];
|
|
582
|
+
for (const attr of ["src", "poster"]) {
|
|
583
|
+
const value = el.getAttribute(attr);
|
|
584
|
+
if (value) urls.push(value);
|
|
585
|
+
}
|
|
586
|
+
const srcset = el.getAttribute("srcset");
|
|
587
|
+
if (srcset) for (const candidate of srcset.split(",")) {
|
|
588
|
+
const url = candidate.trim().split(/\s+/, 1)[0];
|
|
589
|
+
if (url) urls.push(url);
|
|
590
|
+
}
|
|
591
|
+
return urls;
|
|
592
|
+
};
|
|
593
|
+
/** A raster image under `public/` without an AVIF sibling: it renders, it just costs every visitor
|
|
594
|
+
* bandwidth. The site's own files decide this, so it refuses the build. */
|
|
595
|
+
const imageFormats = {
|
|
596
|
+
id: "image-formats",
|
|
597
|
+
title: "Image formats",
|
|
598
|
+
severity: "error",
|
|
599
|
+
begin: (ctx) => {
|
|
600
|
+
const ignored = new Set(ctx.options.imageIgnore);
|
|
601
|
+
return { finish: () => {
|
|
602
|
+
const findings = [];
|
|
603
|
+
for (const file of filesUnder(ctx.publicDir, RASTER)) {
|
|
604
|
+
const rel = ctx.rel(file);
|
|
605
|
+
if (ignored.has(rel) || ICON.test(rel)) continue;
|
|
606
|
+
const stem = file.slice(0, -path.extname(file).length);
|
|
607
|
+
if (fs.existsSync(`${stem}.avif`)) continue;
|
|
608
|
+
findings.push({
|
|
609
|
+
path: rel,
|
|
610
|
+
message: "A raster image ships without an AVIF sibling; it renders and just costs the visitor bandwidth. Encode one (scripts/to-avif.mjs), or list the file in imageIgnore with a reason."
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return findings;
|
|
614
|
+
} };
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
/** A feed photo from the vOffice image hosts requested as JPEG or PNG where the host would serve
|
|
618
|
+
* WebP. A warning: the photos come from the PMS feed, so a page shows them, and the finding, only
|
|
619
|
+
* once the feed has them; that must not stop the nightly builds that update prices. */
|
|
620
|
+
const feedImageFormats = {
|
|
621
|
+
id: "feed-image-formats",
|
|
622
|
+
title: "Feed photo formats",
|
|
623
|
+
severity: "warning",
|
|
624
|
+
begin: (ctx) => {
|
|
625
|
+
if (!ctx.hasDist) return null;
|
|
626
|
+
const patterns = ctx.options.feedImagePatterns.map((source) => new RegExp(source, "i"));
|
|
627
|
+
const findings = [];
|
|
628
|
+
return {
|
|
629
|
+
visit: (page) => {
|
|
630
|
+
for (const el of page.document.querySelectorAll("img, source, video")) for (const url of imageUrls(el)) if (patterns.some((pattern) => pattern.test(url))) findings.push({
|
|
631
|
+
path: page.path,
|
|
632
|
+
message: `A feed photo is requested as JPEG or PNG: ${url}. Pass it through webpUrl() so the host serves WebP.`
|
|
633
|
+
});
|
|
634
|
+
},
|
|
635
|
+
finish: () => findings
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/checks/launchHead.ts
|
|
641
|
+
/** Hosts a site is previewed on before it has its own domain: a `site` there is not a launch. */
|
|
642
|
+
const PREVIEW_HOST = /(?:^|\.)(?:cloudfront\.net|vercel\.app|netlify\.app|pages\.dev|github\.io)$|^(?:localhost|127\.0\.0\.1)$|\.local$/i;
|
|
643
|
+
/** The site's production host, when the Astro config names one that is not a preview origin. */
|
|
644
|
+
const productionSite = (ctx) => {
|
|
645
|
+
if (!ctx.config.site) return void 0;
|
|
646
|
+
try {
|
|
647
|
+
return PREVIEW_HOST.test(new URL(ctx.config.site).hostname) ? void 0 : ctx.config.site;
|
|
648
|
+
} catch {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
const isAbsolute = (url) => !!url && /^https?:\/\/[^/]/i.test(url.trim());
|
|
653
|
+
/** A page the launch head applies to: indexable, read by someone, not the 404 page. */
|
|
654
|
+
const indexable = (page) => !page.redirect && !page.noindex && page.path !== "404.html";
|
|
655
|
+
/** A check over the launched site's indexable pages: it waits while the site is a preview (no
|
|
656
|
+
* production `site` in the Astro config) or every page is noindex (the preview's blanket robots
|
|
657
|
+
* meta), and starts with the build that lifts it. */
|
|
658
|
+
const launchCheck = (base, inspect) => ({
|
|
659
|
+
...base,
|
|
660
|
+
begin: (ctx) => {
|
|
661
|
+
const site = productionSite(ctx);
|
|
662
|
+
if (!ctx.hasDist || !site) return null;
|
|
663
|
+
const findings = [];
|
|
664
|
+
let launched = false;
|
|
665
|
+
return {
|
|
666
|
+
visit: (page) => {
|
|
667
|
+
if (!indexable(page)) return;
|
|
668
|
+
launched = true;
|
|
669
|
+
findings.push(...inspect(page, site));
|
|
670
|
+
},
|
|
671
|
+
finish: () => launched ? findings : []
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
/** Every indexable page of the launched site names its canonical URL, absolute (the `site` origin
|
|
676
|
+
* and the path, no query): without one, a search engine picks among `/x`, `/x/` and `/x?ref=…`. */
|
|
677
|
+
const canonicalLink = launchCheck({
|
|
678
|
+
id: "canonical-link",
|
|
679
|
+
title: "Indexable pages name their canonical URL",
|
|
680
|
+
severity: "error"
|
|
681
|
+
}, (page) => {
|
|
682
|
+
const href = page.document.querySelector("link[rel=\"canonical\"]")?.getAttribute("href");
|
|
683
|
+
if (isAbsolute(href)) return [];
|
|
684
|
+
return [{
|
|
685
|
+
path: page.path,
|
|
686
|
+
message: href ? `The canonical URL "${href}" is not absolute: build it from the Astro \`site\` and the page path.` : "No <link rel=\"canonical\">: give every indexable page its absolute URL, from the Astro `site` and the path."
|
|
687
|
+
}];
|
|
688
|
+
});
|
|
689
|
+
/** Every indexable page of the launched site carries `og:url` and `og:image`, absolute: a shared
|
|
690
|
+
* link renders bare without them. A warning: a rental page's image is the feed's first photo. */
|
|
691
|
+
const openGraph = launchCheck({
|
|
692
|
+
id: "open-graph",
|
|
693
|
+
title: "Indexable pages carry a share preview",
|
|
694
|
+
severity: "warning"
|
|
695
|
+
}, (page) => {
|
|
696
|
+
const meta = (name) => page.document.querySelector(`meta[property="${name}"], meta[name="${name}"]`)?.getAttribute("content");
|
|
697
|
+
const missing = ["og:url", "og:image"].filter((name) => !isAbsolute(meta(name)));
|
|
698
|
+
return missing.length === 0 ? [] : [{
|
|
699
|
+
path: page.path,
|
|
700
|
+
message: `No absolute ${missing.join(" and ")}: a shared link renders without its preview.`
|
|
701
|
+
}];
|
|
702
|
+
});
|
|
703
|
+
/** The launched site declares `trailingSlash: "never"`: one URL form everywhere means one CDN rule
|
|
704
|
+
* set (`/x/` → 301 `/x`) and one redirect-map convention. Unset, the CDN decides per request and
|
|
705
|
+
* `/x` and `/x/` are two URLs for one page. */
|
|
706
|
+
const trailingSlash = {
|
|
707
|
+
id: "trailing-slash",
|
|
708
|
+
title: "The site declares trailingSlash \"never\"",
|
|
709
|
+
severity: "warning",
|
|
710
|
+
begin: (ctx) => {
|
|
711
|
+
if (!ctx.hasDist || !productionSite(ctx)) return null;
|
|
712
|
+
let launched = false;
|
|
713
|
+
return {
|
|
714
|
+
visit: (page) => {
|
|
715
|
+
if (indexable(page)) launched = true;
|
|
716
|
+
},
|
|
717
|
+
finish: () => !launched || ctx.config.trailingSlash === "never" ? [] : [{ message: `trailingSlash is "${ctx.config.trailingSlash ?? "ignore"}" in the Astro config: set it to "never" and write internal links without a trailing slash.` }]
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
//#endregion
|
|
722
|
+
//#region src/checks/listingLinks.ts
|
|
723
|
+
/** A page that lists rentals renders the list into its HTML too, inside this container, so a
|
|
724
|
+
* crawler running no JavaScript sees the rentals the live island will show. The search page of
|
|
725
|
+
* the site starter marks its server-rendered results this way. */
|
|
726
|
+
const LIST_CONTAINER = "[data-prerendered-results]";
|
|
727
|
+
/** The live search island; a page that mounts it lists rentals, container or not. */
|
|
728
|
+
const LIST_ISLAND = "SearchResults";
|
|
729
|
+
/** Below this many pages the build is a starter with an empty feed, where an empty list says
|
|
730
|
+
* nothing about the site's code. */
|
|
731
|
+
const SMALL_BUILD = 10;
|
|
732
|
+
const normalize$1 = (urlPath) => {
|
|
733
|
+
const p = urlPath.split(/[?#]/, 1)[0] ?? "";
|
|
734
|
+
return p.length > 1 ? p.replace(/\/+$/, "") : p;
|
|
735
|
+
};
|
|
736
|
+
/** The page as a listing, when it is one: its markup marks it, or `listingPages` names it. Links
|
|
737
|
+
* are those of the list's own markup: the container, else what the island rendered on the server
|
|
738
|
+
* (a client-only island renders nothing). A page known only from `listingPages` has neither, and
|
|
739
|
+
* its header, navigation and footer links are not a list either. */
|
|
740
|
+
const asListing = (ctx, configured, page) => {
|
|
741
|
+
const container = page.document.querySelector(LIST_CONTAINER);
|
|
742
|
+
const islands = [...page.document.querySelectorAll("astro-island")].filter((el) => (el.getAttribute("component-url") ?? "").includes(LIST_ISLAND));
|
|
743
|
+
const url = normalize$1(page.url);
|
|
744
|
+
if (!container && islands.length === 0 && !configured.has(url)) return null;
|
|
745
|
+
const anchors = container ? [...container.querySelectorAll("a[href]")] : islands.length > 0 ? islands.flatMap((island) => [...island.querySelectorAll("a[href]")]) : [...page.document.querySelectorAll("a[href]")].filter((a) => !a.closest("header, nav, footer"));
|
|
746
|
+
const links = /* @__PURE__ */ new Set();
|
|
747
|
+
for (const a of anchors) {
|
|
748
|
+
const href = a.getAttribute("href") ?? "";
|
|
749
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("#")) continue;
|
|
750
|
+
const target = normalize$1(new URL(href, `http://site.invalid${page.base}`).pathname);
|
|
751
|
+
if (target !== url && ctx.serves(target)) links.add(target);
|
|
752
|
+
}
|
|
753
|
+
return {
|
|
754
|
+
path: page.path,
|
|
755
|
+
url,
|
|
756
|
+
links: links.size
|
|
757
|
+
};
|
|
758
|
+
};
|
|
759
|
+
/** Every page that lists rentals is indexable: a hidden listing hides its rentals with it. The
|
|
760
|
+
* site's own noindex routes decide this, not the feed, so it refuses the build. Skipped while
|
|
761
|
+
* every page is noindex (a site before launch). */
|
|
762
|
+
const listingNoindex = {
|
|
763
|
+
id: "listing-noindex",
|
|
764
|
+
title: "Rental listings are indexable",
|
|
765
|
+
severity: "error",
|
|
766
|
+
begin: (ctx) => {
|
|
767
|
+
if (!ctx.hasDist) return null;
|
|
768
|
+
const configured = new Set(ctx.options.listingPages.map(normalize$1));
|
|
769
|
+
const hidden = [];
|
|
770
|
+
let indexable = 0;
|
|
771
|
+
return {
|
|
772
|
+
visit: (page) => {
|
|
773
|
+
if (page.redirect) return;
|
|
774
|
+
if (!page.noindex) indexable += 1;
|
|
775
|
+
else if (asListing(ctx, configured, page)) hidden.push(page.path);
|
|
776
|
+
},
|
|
777
|
+
finish: () => indexable === 0 ? [] : hidden.map((path) => ({
|
|
778
|
+
path,
|
|
779
|
+
message: "A page that lists rentals is noindex; the rentals it lists are hidden with it. Take it out of the noindex routes."
|
|
780
|
+
}))
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
/** Every page that lists rentals carries links to them in its built HTML; a crawler without
|
|
785
|
+
* JavaScript otherwise sees an empty list. A warning: the links come from the PMS feed, and an
|
|
786
|
+
* empty or booked-out feed must not stop the nightly builds that update prices. Runs once some
|
|
787
|
+
* listing page has links, or the build is more than a starter's handful of pages. */
|
|
788
|
+
const listingLinks = {
|
|
789
|
+
id: "listing-links",
|
|
790
|
+
title: "Rental listings reach crawlers",
|
|
791
|
+
severity: "warning",
|
|
792
|
+
begin: (ctx) => {
|
|
793
|
+
if (!ctx.hasDist) return null;
|
|
794
|
+
const configured = new Set(ctx.options.listingPages.map(normalize$1));
|
|
795
|
+
const clientOnly = new Map(ctx.options.listingClientOnly.map((c) => [normalize$1(c.path), c]));
|
|
796
|
+
const listings = [];
|
|
797
|
+
let pages = 0;
|
|
798
|
+
return {
|
|
799
|
+
visit: (page) => {
|
|
800
|
+
if (page.redirect) return;
|
|
801
|
+
pages += 1;
|
|
802
|
+
const listing = asListing(ctx, configured, page);
|
|
803
|
+
if (listing) listings.push(listing);
|
|
804
|
+
},
|
|
805
|
+
finish: () => {
|
|
806
|
+
const findings = [];
|
|
807
|
+
if (!listings.some((l) => l.links > 0) && pages <= SMALL_BUILD) return findings;
|
|
808
|
+
for (const listing of listings) if (listing.links === 0 && !clientOnly.has(listing.url)) findings.push({
|
|
809
|
+
path: listing.path,
|
|
810
|
+
message: "No links to rentals in the HTML: a crawler running no JavaScript sees an empty list. Render the list server-side (the search page's prerendered results), or list the page in listingClientOnly with the reason."
|
|
811
|
+
});
|
|
812
|
+
return findings;
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
};
|
|
817
|
+
//#endregion
|
|
818
|
+
//#region src/checks/loadOrder.ts
|
|
819
|
+
/** Libraries that serve one feature a visitor reaches later (a map, a chart, a 3D view): `name` is
|
|
820
|
+
* the package (a chunk named after it), `signature` a string only its code carries. */
|
|
821
|
+
const ON_DEMAND = [
|
|
822
|
+
{
|
|
823
|
+
name: "maplibre-gl",
|
|
824
|
+
signature: "maplibregl"
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
name: "mapbox-gl",
|
|
828
|
+
signature: "mapboxgl"
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
name: "leaflet",
|
|
832
|
+
signature: "leaflet-container"
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
name: "chart.js",
|
|
836
|
+
signature: "Chart.register"
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
name: "echarts",
|
|
840
|
+
signature: "echarts"
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
name: "three",
|
|
844
|
+
signature: "WebGLRenderer"
|
|
845
|
+
}
|
|
846
|
+
];
|
|
847
|
+
/** A signature counts only in a library-sized chunk: a small consumer may name the library. */
|
|
848
|
+
const LIBRARY_KB = 50;
|
|
849
|
+
/** A start-up chunk above this (brotli) is named, as a question, not an accusation. */
|
|
850
|
+
const LARGE_CHUNK_KB = 150;
|
|
851
|
+
/** A first-paint photo from this size up must come in several widths. */
|
|
852
|
+
const ONE_SIZE_KB = 100;
|
|
853
|
+
/** Static imports and re-exports only: `import"./a.js"`, `export{…}from"./a.js"`. `import("./a.js")`
|
|
854
|
+
* is the fix (loaded on demand), so it is not followed. */
|
|
855
|
+
const STATIC_IMPORT = /(?:^|[;\n}])\s*(?:import|export)\s*(?:[\w$*{},\s]*?from\s*)?["'](\.{1,2}\/[^"']+\.js)["']/g;
|
|
856
|
+
const INLINE_IMPORT = /(?:import|from)\s*["'](\/[^"']+\.js)["']/g;
|
|
857
|
+
/** Nothing under these is fetched at start: template content, a closed dialog, a hidden subtree. */
|
|
858
|
+
const INERT = "template, dialog, [hidden]";
|
|
859
|
+
const STRIP_CLASS = /(?:^|\s)(?:snap-x|overflow-x-(?:auto|scroll))(?:\s|$)/;
|
|
860
|
+
const few = (pages) => {
|
|
861
|
+
const list = [...pages];
|
|
862
|
+
return list.slice(0, 3).join(", ") + (list.length > 3 ? ` (+${list.length - 3} more)` : "");
|
|
863
|
+
};
|
|
864
|
+
const add = (map, key, page) => map.set(key, (map.get(key) ?? /* @__PURE__ */ new Set()).add(page));
|
|
865
|
+
/** What a built page fetches at start on a slow phone, where each of these costs seconds before
|
|
866
|
+
* the largest picture paints and no other check sees it:
|
|
867
|
+
* - an on-demand library (a map engine, a chart library) in the start-up code: module scripts and
|
|
868
|
+
* the islands that hydrate without waiting for visibility, with every chunk they import
|
|
869
|
+
* statically;
|
|
870
|
+
* - on a page with two or more card swipe strips, a photo after a strip's first carrying a URL
|
|
871
|
+
* (native lazy loading reaches sideways on slow links);
|
|
872
|
+
* - a large first-paint photo (not lazy) in one size only, without a width `srcset`;
|
|
873
|
+
* - a `font-display: swap` face without a `size-adjust` stand-in behind it, which reflows the line.
|
|
874
|
+
* A warning: each is a cost, not a fault. */
|
|
875
|
+
const loadOrder = {
|
|
876
|
+
id: "load-order",
|
|
877
|
+
title: "What pages load at start",
|
|
878
|
+
severity: "warning",
|
|
879
|
+
begin: (ctx) => {
|
|
880
|
+
if (!ctx.hasDist) return null;
|
|
881
|
+
const chunks = /* @__PURE__ */ new Map();
|
|
882
|
+
const chunk = (file) => {
|
|
883
|
+
let known = chunks.get(file);
|
|
884
|
+
if (!known) {
|
|
885
|
+
const code = ctx.has(file) ? ctx.read(file) : "";
|
|
886
|
+
const deps = [...code.matchAll(STATIC_IMPORT)].map((m) => path.posix.normalize(path.posix.join(path.posix.dirname(file), m[1])));
|
|
887
|
+
const kb = code ? brotliCompressSync(code, { params: { [constants.BROTLI_PARAM_QUALITY]: 5 } }).length / 1024 : 0;
|
|
888
|
+
const base = path.posix.basename(file);
|
|
889
|
+
known = {
|
|
890
|
+
deps,
|
|
891
|
+
kb,
|
|
892
|
+
library: ON_DEMAND.find((lib) => base.startsWith(`${lib.name}.`) || kb > LIBRARY_KB && code.includes(lib.signature))?.name
|
|
893
|
+
};
|
|
894
|
+
chunks.set(file, known);
|
|
895
|
+
}
|
|
896
|
+
return known;
|
|
897
|
+
};
|
|
898
|
+
const toFile = (url) => url?.startsWith("/") ? (url.split(/[?#]/, 1)[0] ?? "").replace(/^\/+/, "") : null;
|
|
899
|
+
const libraries = /* @__PURE__ */ new Map();
|
|
900
|
+
const large = /* @__PURE__ */ new Map();
|
|
901
|
+
const strips = /* @__PURE__ */ new Map();
|
|
902
|
+
const oneSize = /* @__PURE__ */ new Map();
|
|
903
|
+
const faces = /* @__PURE__ */ new Map();
|
|
904
|
+
const startup = (page) => {
|
|
905
|
+
const roots = /* @__PURE__ */ new Set();
|
|
906
|
+
for (const script of page.document.querySelectorAll("script[type=\"module\"]")) {
|
|
907
|
+
const src = toFile(script.getAttribute("src"));
|
|
908
|
+
if (src) roots.add(src);
|
|
909
|
+
for (const m of (script.textContent ?? "").matchAll(INLINE_IMPORT)) {
|
|
910
|
+
const file = toFile(m[1]);
|
|
911
|
+
if (file) roots.add(file);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
for (const island of page.document.querySelectorAll("astro-island")) {
|
|
915
|
+
if (island.getAttribute("client") === "visible") continue;
|
|
916
|
+
for (const attr of ["component-url", "renderer-url"]) {
|
|
917
|
+
const file = toFile(island.getAttribute(attr));
|
|
918
|
+
if (file) roots.add(file);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const seen = /* @__PURE__ */ new Set();
|
|
922
|
+
const stack = [...roots];
|
|
923
|
+
while (stack.length > 0) {
|
|
924
|
+
const file = stack.pop();
|
|
925
|
+
if (seen.has(file)) continue;
|
|
926
|
+
seen.add(file);
|
|
927
|
+
stack.push(...chunk(file).deps);
|
|
928
|
+
}
|
|
929
|
+
for (const file of seen) {
|
|
930
|
+
const { library, kb } = chunk(file);
|
|
931
|
+
if (library) add(libraries, library, page.path);
|
|
932
|
+
else if (kb > LARGE_CHUNK_KB) add(large, `${file} (${Math.round(kb)} KB compressed)`, page.path);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
const swipeStrips = (page) => {
|
|
936
|
+
let extra = 0;
|
|
937
|
+
let count = 0;
|
|
938
|
+
for (const strip of page.document.querySelectorAll("[class]")) {
|
|
939
|
+
if (!STRIP_CLASS.test(strip.getAttribute("class") ?? "") || strip.closest(INERT)) continue;
|
|
940
|
+
const live = [...strip.querySelectorAll("img")].slice(1).filter((img) => ["src", "srcset"].some((a) => /^(?!data:)\S/.test(img.getAttribute(a) ?? "")));
|
|
941
|
+
if (live.length > 0) {
|
|
942
|
+
count += 1;
|
|
943
|
+
extra += live.length;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
if (count >= 2) strips.set(page.path, extra);
|
|
947
|
+
};
|
|
948
|
+
const sizeKb = (url) => {
|
|
949
|
+
const file = toFile(url);
|
|
950
|
+
if (!file || !ctx.has(file)) return null;
|
|
951
|
+
return fs.statSync(path.join(ctx.distDir, decodeURI(file))).size / 1024;
|
|
952
|
+
};
|
|
953
|
+
const widths = (el) => [el, ...el.querySelectorAll("[srcset]")].some((node) => ((node.getAttribute("srcset") ?? "").match(/\s\d+w\b/g) ?? []).length >= 2);
|
|
954
|
+
const oneSizePhotos = (page) => {
|
|
955
|
+
const note = (url) => {
|
|
956
|
+
const kb = sizeKb(url);
|
|
957
|
+
if (kb !== null && kb >= ONE_SIZE_KB) add(oneSize, `${url} (${Math.round(kb)} KB)`, page.path);
|
|
958
|
+
};
|
|
959
|
+
for (const link of page.document.querySelectorAll("link[rel=\"preload\"][as=\"image\"]")) if (!link.hasAttribute("imagesrcset")) note(link.getAttribute("href"));
|
|
960
|
+
for (const img of page.document.querySelectorAll("img")) {
|
|
961
|
+
if (img.closest(INERT) || img.getAttribute("loading") === "lazy") continue;
|
|
962
|
+
const picture = img.closest("picture");
|
|
963
|
+
if (widths(picture ?? img)) continue;
|
|
964
|
+
const first = picture?.querySelector("source[srcset]")?.getAttribute("srcset")?.trim().split(/[\s,]/, 1)[0];
|
|
965
|
+
note(first ?? img.getAttribute("src"));
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
const sheets = /* @__PURE__ */ new Map();
|
|
969
|
+
const sheet = (file) => {
|
|
970
|
+
if (!sheets.has(file)) sheets.set(file, ctx.has(file) ? ctx.read(file) : "");
|
|
971
|
+
return sheets.get(file);
|
|
972
|
+
};
|
|
973
|
+
/** A URL path, resolved against the document that names it (a page, or a stylesheet). */
|
|
974
|
+
const resolve = (url, base) => new URL(url, `http://site.invalid${base}`).pathname;
|
|
975
|
+
const swappedFaces = (page) => {
|
|
976
|
+
const sources = [...[...page.document.querySelectorAll("style")].map((s) => ({
|
|
977
|
+
css: s.textContent ?? "",
|
|
978
|
+
base: page.base
|
|
979
|
+
})), ...[...page.document.querySelectorAll("link[rel=\"stylesheet\"][href]")].flatMap((link) => {
|
|
980
|
+
const file = toFile(resolve(link.getAttribute("href"), page.base));
|
|
981
|
+
return file ? [{
|
|
982
|
+
css: sheet(file),
|
|
983
|
+
base: `/${file}`
|
|
984
|
+
}] : [];
|
|
985
|
+
})];
|
|
986
|
+
const css = sources.map((source) => source.css).join("\n");
|
|
987
|
+
const declared = sources.flatMap(({ css: text, base }) => [...text.matchAll(/@font-face\s*\{([^}]*)\}/g)].map((m) => {
|
|
988
|
+
const url = /url\(["']?([^"')]+)/.exec(m[1])?.[1];
|
|
989
|
+
return {
|
|
990
|
+
family: (/font-family:\s*([^;]+)/.exec(m[1])?.[1] ?? "").trim().replace(/^["']|["']$/g, ""),
|
|
991
|
+
swap: /font-display:\s*swap/.test(m[1]),
|
|
992
|
+
file: url && !url.startsWith("data:") ? resolve(url, base) : "",
|
|
993
|
+
adjusted: /size-adjust\s*:/.test(m[1])
|
|
994
|
+
};
|
|
995
|
+
}));
|
|
996
|
+
const adjusted = new Set(declared.filter((f) => f.adjusted).map((f) => f.family));
|
|
997
|
+
const stacks = [...css.replace(/@font-face\s*\{[^}]*\}/g, "").matchAll(/font-family:\s*([^;}]+)/g)].map((m) => m[1].split(",").map((s) => s.trim().replace(/^["']|["']$/g, "")));
|
|
998
|
+
const preloaded = new Set([...page.document.querySelectorAll("link[rel=\"preload\"][href]")].map((l) => resolve(l.getAttribute("href"), page.base)));
|
|
999
|
+
for (const face of declared) if (face.swap && !face.adjusted && face.file && preloaded.has(face.file)) {
|
|
1000
|
+
if (stacks.filter((stack) => stack[0] === face.family).some((stack) => !adjusted.has(stack[1] ?? ""))) add(faces, face.family, page.path);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
return {
|
|
1004
|
+
visit: (page) => {
|
|
1005
|
+
if (page.redirect) return;
|
|
1006
|
+
startup(page);
|
|
1007
|
+
swipeStrips(page);
|
|
1008
|
+
oneSizePhotos(page);
|
|
1009
|
+
swappedFaces(page);
|
|
1010
|
+
},
|
|
1011
|
+
finish: () => {
|
|
1012
|
+
const findings = [];
|
|
1013
|
+
for (const [library, pages] of libraries) findings.push({ message: `The start-up code of ${pages.size} page(s) includes ${library}: ${few(pages)}. Load it with import() when its section nears the viewport or on first use.` });
|
|
1014
|
+
for (const [file, pages] of large) findings.push({ message: `${file} loads at start on ${pages.size} page(s): needed that early? ${few(pages)}` });
|
|
1015
|
+
for (const [page, extra] of strips) findings.push({
|
|
1016
|
+
path: page,
|
|
1017
|
+
message: `${extra} photo(s) after the first in the card swipe strips carry a URL. Render only the first slide's src/srcset and hand the rest theirs on first interaction.`
|
|
1018
|
+
});
|
|
1019
|
+
for (const [photo, pages] of oneSize) findings.push({ message: `${photo} loads at start in one size only, on ${few(pages)}. Ship width variants in a srcset with a measured sizes; a preload names the same srcset/sizes pair.` });
|
|
1020
|
+
for (const [family, pages] of faces) findings.push({ message: `The preloaded face "${family}" swaps in without a width-matched stand-in (size-adjust) behind it, on ${few(pages)}. Add a local() stand-in with size-adjust right after it in the stack.` });
|
|
1021
|
+
return findings;
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
//#endregion
|
|
1027
|
+
//#region src/checks/optimizeDeps.ts
|
|
1028
|
+
const SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1029
|
+
".ts",
|
|
1030
|
+
".tsx",
|
|
1031
|
+
".js",
|
|
1032
|
+
".jsx",
|
|
1033
|
+
".mjs",
|
|
1034
|
+
".astro"
|
|
1035
|
+
]);
|
|
1036
|
+
/** `import … from "x"`, `import "x"`, `export … from "x"` and `import("x")`. Type-only forms load
|
|
1037
|
+
* nothing and are skipped. */
|
|
1038
|
+
const IMPORT_RE = /\b(?:import|export)\s+(type\s+)?(?:[^'"`;]*?\s+from\s+)?['"]([^'"]+)['"]|\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
1039
|
+
/** The package a specifier belongs to: `@scope/name` or `name`. */
|
|
1040
|
+
const packageOf = (specifier) => {
|
|
1041
|
+
const parts = specifier.split("/");
|
|
1042
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? specifier;
|
|
1043
|
+
};
|
|
1044
|
+
/** Styles and assets are served, not pre-bundled: `maplibre-gl/dist/maplibre-gl.css` is no entry. */
|
|
1045
|
+
const ASSET = /\.(?:css|scss|sass|less|json|svg|png|jpe?g|webp|avif|gif|woff2?)$/i;
|
|
1046
|
+
const isBare = (specifier) => !/^[./#]/.test(specifier) && !/^(?:node|astro|virtual|data):/.test(specifier) && !ASSET.test(specifier);
|
|
1047
|
+
/** Every runtime package `src/` imports is either reached by the dev server's startup crawl or
|
|
1048
|
+
* named in `vite.optimizeDeps.include`; one that is neither gets discovered mid-session, which
|
|
1049
|
+
* re-stamps every pre-bundled dependency and leaves an open tab asking for files that no longer
|
|
1050
|
+
* exist. The sites' convention is to list every runtime package, which is what is checked: a bare
|
|
1051
|
+
* specifier of a `dependencies` package, not exactly in `include` and not ignored. A warning: it
|
|
1052
|
+
* slows the dev server, it changes nothing a visitor sees. */
|
|
1053
|
+
const optimizeDeps = {
|
|
1054
|
+
id: "optimize-deps",
|
|
1055
|
+
title: "Runtime packages missing from vite.optimizeDeps.include",
|
|
1056
|
+
severity: "warning",
|
|
1057
|
+
begin: (ctx) => ({ finish: () => {
|
|
1058
|
+
const included = new Set(ctx.config.optimizeDepsInclude);
|
|
1059
|
+
const ignored = new Set(ctx.options.optimizeDepsIgnore);
|
|
1060
|
+
const runtime = ctx.packageJson.dependencies;
|
|
1061
|
+
const importers = /* @__PURE__ */ new Map();
|
|
1062
|
+
for (const file of ctx.sourceFiles(SOURCE_EXTENSIONS)) {
|
|
1063
|
+
const text = ctx.readSource(file);
|
|
1064
|
+
for (const match of text.matchAll(IMPORT_RE)) {
|
|
1065
|
+
const [, typeOnly, fromSpecifier, dynamicSpecifier] = match;
|
|
1066
|
+
const specifier = fromSpecifier ?? dynamicSpecifier;
|
|
1067
|
+
if (typeOnly || !specifier || !isBare(specifier)) continue;
|
|
1068
|
+
const pkg = packageOf(specifier);
|
|
1069
|
+
if (pkg === "astro" || pkg.startsWith("@types/") || !(pkg in runtime)) continue;
|
|
1070
|
+
if (included.has(specifier) || ignored.has(specifier) || ignored.has(pkg)) continue;
|
|
1071
|
+
const files = importers.get(specifier) ?? [];
|
|
1072
|
+
const rel = ctx.rel(file);
|
|
1073
|
+
if (!files.includes(rel)) files.push(rel);
|
|
1074
|
+
importers.set(specifier, files);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
const findings = [];
|
|
1078
|
+
for (const [specifier, files] of [...importers].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1079
|
+
const shown = files.slice(0, 3).join(", ");
|
|
1080
|
+
const more = files.length > 3 ? ` (+${files.length - 3} more)` : "";
|
|
1081
|
+
findings.push({
|
|
1082
|
+
path: files[0],
|
|
1083
|
+
message: `"${specifier}" is imported by ${shown}${more} but not in vite.optimizeDeps.include. Add it there, or to optimizeDepsIgnore in site-checks.config.json if only server-side code uses it.`
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
return findings;
|
|
1087
|
+
} })
|
|
1088
|
+
};
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region src/checks/pageHeads.ts
|
|
1091
|
+
const MAX_TITLE = 60;
|
|
1092
|
+
const MAX_DESCRIPTION = 160;
|
|
1093
|
+
/** The head of every indexable page as a search result shows it: a title over 60 or a description
|
|
1094
|
+
* over 160 characters is cut, an empty description is replaced by whatever the crawler picks, and a
|
|
1095
|
+
* title or description another page repeats makes the two compete. A missing title or description
|
|
1096
|
+
* is the build worker's `page-metadata` finding, not repeated here. A warning: the page works. */
|
|
1097
|
+
const pageHeads = {
|
|
1098
|
+
id: "page-heads",
|
|
1099
|
+
title: "Titles and descriptions of indexable pages",
|
|
1100
|
+
severity: "warning",
|
|
1101
|
+
begin: (ctx) => {
|
|
1102
|
+
if (!ctx.hasDist) return null;
|
|
1103
|
+
const findings = [];
|
|
1104
|
+
const titles = /* @__PURE__ */ new Map();
|
|
1105
|
+
const descriptions = /* @__PURE__ */ new Map();
|
|
1106
|
+
const remember = (map, value, path) => map.set(value, [...map.get(value) ?? [], path]);
|
|
1107
|
+
return {
|
|
1108
|
+
visit: (page) => {
|
|
1109
|
+
if (page.redirect || page.noindex || page.path === "404.html") return;
|
|
1110
|
+
const title = page.document.querySelector("title")?.textContent?.trim();
|
|
1111
|
+
const description = page.document.querySelector("meta[name=\"description\"]")?.getAttribute("content")?.trim();
|
|
1112
|
+
if (title) {
|
|
1113
|
+
if (title.length > MAX_TITLE) findings.push({
|
|
1114
|
+
path: page.path,
|
|
1115
|
+
message: `The title has ${title.length} characters; search results cut it after ${MAX_TITLE}.`
|
|
1116
|
+
});
|
|
1117
|
+
remember(titles, title, page.path);
|
|
1118
|
+
}
|
|
1119
|
+
if (description !== void 0) {
|
|
1120
|
+
if (description === "") findings.push({
|
|
1121
|
+
path: page.path,
|
|
1122
|
+
message: "The description is empty; search results show whatever the crawler picks."
|
|
1123
|
+
});
|
|
1124
|
+
else if (description.length > MAX_DESCRIPTION) findings.push({
|
|
1125
|
+
path: page.path,
|
|
1126
|
+
message: `The description has ${description.length} characters; search results cut it after ${MAX_DESCRIPTION}.`
|
|
1127
|
+
});
|
|
1128
|
+
if (description) remember(descriptions, description, page.path);
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1131
|
+
finish: () => {
|
|
1132
|
+
const duplicates = (map, what) => {
|
|
1133
|
+
for (const [value, pages] of map) {
|
|
1134
|
+
if (pages.length < 2) continue;
|
|
1135
|
+
const shown = pages.slice(0, 3).join(", ");
|
|
1136
|
+
const more = pages.length > 3 ? ` (+${pages.length - 3} more)` : "";
|
|
1137
|
+
findings.push({
|
|
1138
|
+
path: pages[0],
|
|
1139
|
+
message: `The ${what} "${value}" is repeated by ${shown}${more}; each indexable page needs its own.`
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
duplicates(titles, "title");
|
|
1144
|
+
duplicates(descriptions, "description");
|
|
1145
|
+
return findings;
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region src/checks/pageStructure.ts
|
|
1152
|
+
/** Not in the document's structure: icon internals answer no alt or label question, template markup
|
|
1153
|
+
* is not in the page until a script clones it. */
|
|
1154
|
+
const OUTSIDE = "svg, script, style, noscript, template";
|
|
1155
|
+
/** A control of these types names itself by its value, or is no control a visitor fills in. */
|
|
1156
|
+
const SELF_NAMING = /* @__PURE__ */ new Set([
|
|
1157
|
+
"hidden",
|
|
1158
|
+
"submit",
|
|
1159
|
+
"button",
|
|
1160
|
+
"image",
|
|
1161
|
+
"reset"
|
|
1162
|
+
]);
|
|
1163
|
+
/** Below this many h3 the ratio is noise; above it, many h3 under few h2 buries the outline. */
|
|
1164
|
+
const RATIO_FLOOR = 10;
|
|
1165
|
+
const RATIO_TIMES = 3;
|
|
1166
|
+
const inDocument = (page, selector) => [...page.document.querySelectorAll(selector)].filter((el) => !el.closest(OUTSIDE));
|
|
1167
|
+
/** Each rule's fault on one page, keyed by rule id, as a printable detail. */
|
|
1168
|
+
const structureFaults = (page) => {
|
|
1169
|
+
const faults = /* @__PURE__ */ new Map();
|
|
1170
|
+
const levels = inDocument(page, "h1, h2, h3, h4, h5, h6").map((h) => Number(h.tagName[1]));
|
|
1171
|
+
const h1 = levels.filter((level) => level === 1).length;
|
|
1172
|
+
if (h1 !== 1) faults.set("one-h1", h1 === 0 ? "no <h1>: a page names itself once" : `${h1} <h1>: a page names itself once`);
|
|
1173
|
+
for (let i = 1; i < levels.length; i += 1) if (levels[i] > levels[i - 1] + 1) {
|
|
1174
|
+
faults.set("heading-skip", `<h${levels[i - 1]}> is followed by <h${levels[i]}>`);
|
|
1175
|
+
break;
|
|
1176
|
+
}
|
|
1177
|
+
const h2 = levels.filter((level) => level === 2).length;
|
|
1178
|
+
const h3 = levels.filter((level) => level === 3).length;
|
|
1179
|
+
if (h3 >= RATIO_FLOOR && h3 > RATIO_TIMES * Math.max(h2, 1)) faults.set("heading-ratio", `${h3} <h3> under ${h2} <h2>: usually a card title marked up as a heading. A name on a card is a label; style a <p> to look the same`);
|
|
1180
|
+
if (inDocument(page, "main").length === 0) faults.set("landmark-main", "no <main> landmark");
|
|
1181
|
+
const noAlt = inDocument(page, "img").filter((img) => !img.hasAttribute("alt"));
|
|
1182
|
+
if (noAlt.length > 0) faults.set("img-alt", `${noAlt.length} <img> without alt, e.g. ${noAlt[0].getAttribute("src") ?? "(no src)"}`);
|
|
1183
|
+
const labelled = new Set(inDocument(page, "label[for]").map((label) => label.getAttribute("for")));
|
|
1184
|
+
const unlabelled = inDocument(page, "input, select, textarea").filter((control) => {
|
|
1185
|
+
const type = (control.getAttribute("type") ?? "text").toLowerCase();
|
|
1186
|
+
if (control.tagName === "INPUT" && SELF_NAMING.has(type)) return false;
|
|
1187
|
+
if (control.closest("[aria-hidden=\"true\"]")) return false;
|
|
1188
|
+
if ([
|
|
1189
|
+
"aria-label",
|
|
1190
|
+
"aria-labelledby",
|
|
1191
|
+
"title"
|
|
1192
|
+
].some((a) => control.hasAttribute(a))) return false;
|
|
1193
|
+
const id = control.getAttribute("id");
|
|
1194
|
+
if (id && labelled.has(id)) return false;
|
|
1195
|
+
return !control.closest("label");
|
|
1196
|
+
});
|
|
1197
|
+
if (unlabelled.length > 0) faults.set("control-label", `${unlabelled.length} control(s) without a label: ${unlabelled.slice(0, 3).map((c) => `<${c.tagName.toLowerCase()}${c.getAttribute("id") ? ` #${c.getAttribute("id")}` : ""}>`).join(", ")}`);
|
|
1198
|
+
const tables = inDocument(page, "table").flatMap((table) => {
|
|
1199
|
+
const problems = [];
|
|
1200
|
+
if (!table.querySelector("caption")) problems.push("no <caption>");
|
|
1201
|
+
const headers = [...table.querySelectorAll("th")];
|
|
1202
|
+
if (headers.length === 0) problems.push("no <th>");
|
|
1203
|
+
else if (!headers.some((th) => th.hasAttribute("scope"))) problems.push("<th> without scope");
|
|
1204
|
+
return problems.length > 0 ? [problems.join(" + ")] : [];
|
|
1205
|
+
});
|
|
1206
|
+
if (tables.length > 0) faults.set("table-headers", `${tables.length} table(s): ${tables.slice(0, 2).join("; ")}`);
|
|
1207
|
+
return faults;
|
|
1208
|
+
};
|
|
1209
|
+
/** The built pages' own structure, which a screen reader navigates by and nothing else reads: one
|
|
1210
|
+
* `<h1>`, no skipped heading level, a `<main>` landmark, `alt` on every image, a label on every
|
|
1211
|
+
* control, a caption and scoped headers on every table, and no flood of small headings under few
|
|
1212
|
+
* sections. Contrast, focus order and keyboard traps are not decidable from static markup. A
|
|
1213
|
+
* warning: the alt text of feed photos and the headings of feed text come from the PMS. A site
|
|
1214
|
+
* declines a rule in `structureIgnore`. */
|
|
1215
|
+
const pageStructure = {
|
|
1216
|
+
id: "page-structure",
|
|
1217
|
+
title: "Page outline, landmarks, alt text, labels and tables",
|
|
1218
|
+
severity: "warning",
|
|
1219
|
+
begin: (ctx) => {
|
|
1220
|
+
if (!ctx.hasDist) return null;
|
|
1221
|
+
const ignored = new Set(ctx.options.structureIgnore);
|
|
1222
|
+
const findings = [];
|
|
1223
|
+
return {
|
|
1224
|
+
visit: (page) => {
|
|
1225
|
+
if (page.redirect) return;
|
|
1226
|
+
for (const [rule, detail] of structureFaults(page)) if (!ignored.has(rule)) findings.push({
|
|
1227
|
+
path: page.path,
|
|
1228
|
+
message: `${rule}: ${detail}.`
|
|
1229
|
+
});
|
|
1230
|
+
},
|
|
1231
|
+
finish: () => findings
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
//#endregion
|
|
1236
|
+
//#region src/checks/rentalFacts.ts
|
|
1237
|
+
/** The markers the platform's rental blocks carry for this check (`GATE_MARKERS` in
|
|
1238
|
+
* `@v-office/website-headless`): the fact row, the owner's description, the amenity section and
|
|
1239
|
+
* its all-amenities dialog. */
|
|
1240
|
+
const MARKERS = {
|
|
1241
|
+
stats: "[data-rental-stats]",
|
|
1242
|
+
description: "[data-rental-description]",
|
|
1243
|
+
amenities: "[data-rental-amenities]",
|
|
1244
|
+
amenitiesModal: "[data-amenities-modal]"
|
|
1245
|
+
};
|
|
1246
|
+
/** The fact row's style part: a page with it but without the marker means the markers moved. */
|
|
1247
|
+
const FACTS_PART = "[data-part=\"rental-facts\"]";
|
|
1248
|
+
/** German number words in feed prose ("zwei separate Schlafzimmer"). "ein/eine/einem/einen" are
|
|
1249
|
+
* left out: mostly the indefinite article ("In einem Schlafzimmer …" is one of the bedrooms), and
|
|
1250
|
+
* counting them as 1 would make every house that describes its rooms one by one contradict its
|
|
1251
|
+
* own fact. "eins" is only ever the numeral. */
|
|
1252
|
+
const WORDS = {
|
|
1253
|
+
eins: 1,
|
|
1254
|
+
zwei: 2,
|
|
1255
|
+
drei: 3,
|
|
1256
|
+
vier: 4,
|
|
1257
|
+
fünf: 5,
|
|
1258
|
+
sechs: 6,
|
|
1259
|
+
sieben: 7,
|
|
1260
|
+
acht: 8,
|
|
1261
|
+
neun: 9,
|
|
1262
|
+
zehn: 10,
|
|
1263
|
+
elf: 11,
|
|
1264
|
+
zwölf: 12
|
|
1265
|
+
};
|
|
1266
|
+
/** Grouped thousands first, or `\d+` matches only the tail: "2.000 m²" would read as 0. Never the
|
|
1267
|
+
* tail of a decimal ("2,5 Badezimmer" is no count of 5) or of a longer word ("dreizehn" is not
|
|
1268
|
+
* "zehn": a compound number is not read at all). */
|
|
1269
|
+
const NUM = `(?<![\\d.,\\p{L}])(\\d{1,3}(?:\\.\\d{3})+|\\d+|${Object.keys(WORDS).join("|")})`;
|
|
1270
|
+
/** "ca." / "etwa" / "rund": the author's own approximation, a rounded statement. The group is
|
|
1271
|
+
* load-bearing: without it `?` binds to the trailing `\s*` and only hedged figures match. */
|
|
1272
|
+
const HEDGE = "(?:(?:ca\\.|etwa|rund)\\s*)";
|
|
1273
|
+
const toNumber = (token) => {
|
|
1274
|
+
const plain = token.replace(/\./g, "");
|
|
1275
|
+
return /^\d+$/.test(plain) ? Number(plain) : WORDS[plain.toLowerCase()] ?? NaN;
|
|
1276
|
+
};
|
|
1277
|
+
/** Prose pattern (group 1 the number) and fact pattern (group 1 the number, or `km` a kilometre
|
|
1278
|
+
* figure), in every form a site renders and the older ones. Prose is matched case-insensitively:
|
|
1279
|
+
* a sentence may open with the number word ("Drei Schlafzimmer …"). */
|
|
1280
|
+
const KINDS = [
|
|
1281
|
+
{
|
|
1282
|
+
kind: "occupancy",
|
|
1283
|
+
prose: new RegExp(`(?:Platz für|für)\\s+(?:bis zu\\s+)?${HEDGE}?${NUM}\\s+Personen`, "giu"),
|
|
1284
|
+
fact: /^(\d+) (?:Gäste|Gast)$/
|
|
1285
|
+
},
|
|
1286
|
+
{
|
|
1287
|
+
kind: "bedrooms",
|
|
1288
|
+
prose: new RegExp(`${HEDGE}?${NUM}\\s+(?:separate\\s+)?Schlafzimmer`, "giu"),
|
|
1289
|
+
fact: /^(\d+) Schlafzimmer$/
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
kind: "bathrooms",
|
|
1293
|
+
prose: new RegExp(`${HEDGE}?${NUM}\\s+(?:Badezimmer|Bäder|Bad)(?![\\p{L}])`, "giu"),
|
|
1294
|
+
fact: /^(\d+) (?:Badezimmer|Bäder|Bad)$/
|
|
1295
|
+
},
|
|
1296
|
+
{
|
|
1297
|
+
kind: "area",
|
|
1298
|
+
prose: new RegExp(`${HEDGE}?${NUM}\\s*(?:qm|m²)`, "giu"),
|
|
1299
|
+
fact: /^(\d{1,3}(?:\.\d{3})+|\d+) m²$/
|
|
1300
|
+
},
|
|
1301
|
+
{
|
|
1302
|
+
kind: "beach",
|
|
1303
|
+
prose: new RegExp(`Strand:?\\s*${HEDGE}?${NUM}\\s*m(?![\\p{L}])`, "giu"),
|
|
1304
|
+
fact: /^Strand:? (?:(\d{1,3}(?:\.\d{3})+|\d+) m|(?<km>\d+(?:,\d+)?) km)$/
|
|
1305
|
+
}
|
|
1306
|
+
];
|
|
1307
|
+
/** Kinds a unit can be described part by part (per floor, per room). Not `area`: a second m²
|
|
1308
|
+
* figure is a plot or a terrace, not a share of the living space. */
|
|
1309
|
+
const PART_KINDS = /* @__PURE__ */ new Set([
|
|
1310
|
+
"occupancy",
|
|
1311
|
+
"bedrooms",
|
|
1312
|
+
"bathrooms"
|
|
1313
|
+
]);
|
|
1314
|
+
/** Occupancy only: a capacity that belongs to a room or a furnishing ("eine Sauna für bis zu zwei
|
|
1315
|
+
* Personen"). Never applied to other kinds: "Zimmer" is inside "Badezimmer" and "Schlafzimmer". */
|
|
1316
|
+
const NOT_CAPACITY = /Schlafzimmer|Zimmer|Bett|Sofa|Couch|Küche|Tisch|Essplatz|Essbereich|Sauna|Whirlpool|Gartenmöbel|Terrasse|Sitzgruppe|Balkon/i;
|
|
1317
|
+
/** The unit as the clause's subject: whichever subject comes first governs the claim. */
|
|
1318
|
+
const UNIT_SUBJECT = /Ferienwohnung|Ferienhaus|Wohnung|Apartment|Appartement|Unterkunft|Ferienunterkunft|Objekt|Haus\b|Hauses\b/i;
|
|
1319
|
+
/** ':' ends a clause too: in "… Bereich des Hauses: Eine Sauna für …" the sauna governs. */
|
|
1320
|
+
const CLAUSE_END = /[.!?•:]/g;
|
|
1321
|
+
/** A part stated alone, with no total on the page ("im Erdgeschoss zwei Schlafzimmer"). Loose
|
|
1322
|
+
* stems: feeds carry typos ("Erdgschoss") and both the -ss and -ß spellings. */
|
|
1323
|
+
const PART_SCOPE = /(?:Erd|Ober|Dach|Unter|Zwischen)g\p{L}*scho|Souterrain|Etage|Stockwerk|die anderen|die beiden anderen|weitere[nrs]?(?![\p{L}])/iu;
|
|
1324
|
+
const OUTDOOR_SCOPE = /Grundst\p{L}*ck|Garten|Gartens|Terrasse|Wiese|Parzelle|Areal|Rasen|Außenbereich|Hofst\p{L}*|Innenhof/iu;
|
|
1325
|
+
const clauseBefore = (prose, start) => {
|
|
1326
|
+
let from = 0;
|
|
1327
|
+
for (const match of prose.slice(0, start).matchAll(CLAUSE_END)) from = match.index + 1;
|
|
1328
|
+
return prose.slice(from, start);
|
|
1329
|
+
};
|
|
1330
|
+
const roomScoped = (prose, start) => {
|
|
1331
|
+
const clause = clauseBefore(prose, start);
|
|
1332
|
+
const other = NOT_CAPACITY.exec(clause);
|
|
1333
|
+
if (!other) return false;
|
|
1334
|
+
const unit = UNIT_SUBJECT.exec(clause);
|
|
1335
|
+
return !unit || unit.index > other.index;
|
|
1336
|
+
};
|
|
1337
|
+
/** German puts the noun after the measurement ("auf einem 3000 m² großen Grundstück"), so this
|
|
1338
|
+
* looks both ways. */
|
|
1339
|
+
const outdoorScoped = (prose, start, end) => OUTDOOR_SCOPE.test(`${clauseBefore(prose, start)} ${prose.slice(end, end + 60).split(".")[0]}`);
|
|
1340
|
+
const partScoped = (prose, start) => PART_SCOPE.test(clauseBefore(prose, start));
|
|
1341
|
+
/** The first fact a kind reads, with its tolerance: a km fact is metres rounded to its last digit
|
|
1342
|
+
* ("4,2 km" is 4150–4250 m), every other fact is exact. */
|
|
1343
|
+
const factValue = (pattern, facts) => {
|
|
1344
|
+
for (const fact of facts) {
|
|
1345
|
+
const match = pattern.exec(fact);
|
|
1346
|
+
if (!match) continue;
|
|
1347
|
+
const km = match.groups?.km;
|
|
1348
|
+
if (km) {
|
|
1349
|
+
const decimals = km.split(",")[1]?.length ?? 0;
|
|
1350
|
+
return {
|
|
1351
|
+
value: Math.round(Number(km.replace(",", ".")) * 1e3),
|
|
1352
|
+
tolerance: 500 / 10 ** decimals
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
return {
|
|
1356
|
+
value: toNumber(match[1]),
|
|
1357
|
+
tolerance: 0
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
return null;
|
|
1361
|
+
};
|
|
1362
|
+
const textOf = blockText;
|
|
1363
|
+
/** A perk line renders on every rental page, so a perk naming a unit property must hold on every
|
|
1364
|
+
* unit; the amenity that proves it, by the perk's word. */
|
|
1365
|
+
const PERK_AMENITIES = {
|
|
1366
|
+
Rauchfrei: "Nichtraucher",
|
|
1367
|
+
WLAN: "WLAN"
|
|
1368
|
+
};
|
|
1369
|
+
const PERKS_FILE = "src/data/perks.ts";
|
|
1370
|
+
/** One rental page's disagreements between the owner's structured facts and their own words. */
|
|
1371
|
+
const scanRental = (slug, input) => {
|
|
1372
|
+
const { facts, prose, amenities, perks } = input;
|
|
1373
|
+
const found = [];
|
|
1374
|
+
let compared = 0;
|
|
1375
|
+
for (const { kind, prose: proseRe, fact } of KINDS) {
|
|
1376
|
+
const stated = factValue(fact, facts);
|
|
1377
|
+
if (!stated) continue;
|
|
1378
|
+
const { value, tolerance } = stated;
|
|
1379
|
+
const offenders = /* @__PURE__ */ new Map();
|
|
1380
|
+
let agrees = false;
|
|
1381
|
+
for (const match of prose.matchAll(proseRe)) {
|
|
1382
|
+
const start = match.index;
|
|
1383
|
+
if (kind === "occupancy" && roomScoped(prose, start)) continue;
|
|
1384
|
+
if (kind === "area" && outdoorScoped(prose, start, start + match[0].length)) continue;
|
|
1385
|
+
const got = toNumber(match[1]);
|
|
1386
|
+
if (Number.isNaN(got)) continue;
|
|
1387
|
+
if (PART_KINDS.has(kind) && got < value && partScoped(prose, start)) continue;
|
|
1388
|
+
compared += 1;
|
|
1389
|
+
if (Math.abs(got - value) <= tolerance) {
|
|
1390
|
+
agrees = true;
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1393
|
+
const hedged = /ca\.|etwa|rund/i.test(match[0]);
|
|
1394
|
+
offenders.set(got, (offenders.get(got) ?? true) && hedged);
|
|
1395
|
+
}
|
|
1396
|
+
for (const [got, hedged] of [...offenders].sort((a, b) => a[0] - b[0])) {
|
|
1397
|
+
if (agrees && PART_KINDS.has(kind) && got <= value) continue;
|
|
1398
|
+
found.push({
|
|
1399
|
+
kind,
|
|
1400
|
+
key: `${slug} ${kind} prose=${got} feed=${value}`,
|
|
1401
|
+
message: `The description says ${got}${hedged ? " (approximately)" : ""}, the ${kind} fact says ${value}. Both come from the PMS: the customer corrects one of them there.`
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
for (const perk of perks) {
|
|
1406
|
+
const word = Object.keys(PERK_AMENITIES).find((w) => perk.includes(w));
|
|
1407
|
+
if (word && !amenities.includes(PERK_AMENITIES[word])) found.push({
|
|
1408
|
+
kind: "perk",
|
|
1409
|
+
key: `${slug} perk ${word}`,
|
|
1410
|
+
message: `Every rental page promises "${perk}", but this unit has no "${PERK_AMENITIES[word]}" amenity.`
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
return {
|
|
1414
|
+
found,
|
|
1415
|
+
compared
|
|
1416
|
+
};
|
|
1417
|
+
};
|
|
1418
|
+
const slugOf = (page) => page.url.replace(/\/+$/, "").split("/").pop() || page.path;
|
|
1419
|
+
/** On rental pages, the owner's structured facts (guests, bedrooms, bathrooms, area, beach
|
|
1420
|
+
* distance) against the same facts in their own description. Where they disagree, a guest books on
|
|
1421
|
+
* one and reads the other. German prose only. It cannot say which is right: both are the
|
|
1422
|
+
* customer's, so it is a warning, and `factCheckAccepted` records one the customer confirmed. */
|
|
1423
|
+
const rentalFacts = {
|
|
1424
|
+
id: "rental-facts",
|
|
1425
|
+
title: "Rental facts agree with the description",
|
|
1426
|
+
severity: "warning",
|
|
1427
|
+
begin: (ctx) => {
|
|
1428
|
+
if (!ctx.hasDist) return null;
|
|
1429
|
+
const accepted = new Set(ctx.options.factCheckAccepted.map((line) => line.trim().split(/\s+/).join(" ")));
|
|
1430
|
+
const perksFile = path.join(ctx.root, PERKS_FILE);
|
|
1431
|
+
const perks = fs.existsSync(perksFile) ? [...fs.readFileSync(perksFile, "utf8").matchAll(/^\s*"([^"]+)",\s*$/gm)].map((m) => m[1]) : [];
|
|
1432
|
+
const findings = [];
|
|
1433
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1434
|
+
let marked = 0;
|
|
1435
|
+
let unmarked;
|
|
1436
|
+
return {
|
|
1437
|
+
visit: (page) => {
|
|
1438
|
+
if (page.redirect) return;
|
|
1439
|
+
const { document } = page;
|
|
1440
|
+
const stats = [...document.querySelectorAll(MARKERS.stats)];
|
|
1441
|
+
if (stats.length === 0) {
|
|
1442
|
+
if (document.querySelector(FACTS_PART)) unmarked ??= page.path;
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
marked += 1;
|
|
1446
|
+
const description = document.querySelector(MARKERS.description);
|
|
1447
|
+
if (!description) return;
|
|
1448
|
+
const facts = stats.flatMap((row) => [...row.querySelectorAll("span")].map((span) => (span.textContent ?? "").replace(/\s+/g, " ").trim()));
|
|
1449
|
+
const slug = slugOf(page);
|
|
1450
|
+
const { found } = scanRental(slug, {
|
|
1451
|
+
facts,
|
|
1452
|
+
prose: textOf(description),
|
|
1453
|
+
amenities: textOf(document.querySelector(MARKERS.amenitiesModal) ?? document.querySelector(MARKERS.amenities)),
|
|
1454
|
+
perks
|
|
1455
|
+
});
|
|
1456
|
+
for (const f of found) {
|
|
1457
|
+
seen.add(f.key);
|
|
1458
|
+
if (!accepted.has(f.key)) findings.push({
|
|
1459
|
+
path: page.path,
|
|
1460
|
+
message: `${f.message} To ship it as it is: "${f.key}" in factCheckAccepted.`
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
},
|
|
1464
|
+
finish: () => {
|
|
1465
|
+
if (unmarked && marked === 0) findings.push({
|
|
1466
|
+
path: unmarked,
|
|
1467
|
+
message: "The rental fact row carries no data-rental-stats marker, so no rental page was compared. The marker comes from @v-office/website-components; a site's own fact row adds it."
|
|
1468
|
+
});
|
|
1469
|
+
if (marked > 0) {
|
|
1470
|
+
for (const key of accepted) if (!seen.has(key)) findings.push({ message: `factCheckAccepted lists "${key}", which no longer disagrees: remove the entry.` });
|
|
1471
|
+
}
|
|
1472
|
+
return findings;
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
//#endregion
|
|
1478
|
+
//#region src/checks/sitemapNoindex.ts
|
|
1479
|
+
const SITEMAP_INDEX = "sitemap-index.xml";
|
|
1480
|
+
const LLMS = "llms.txt";
|
|
1481
|
+
const normalize = (urlPath) => {
|
|
1482
|
+
let p = urlPath.split(/[?#]/, 1)[0] ?? "";
|
|
1483
|
+
try {
|
|
1484
|
+
p = decodeURIComponent(p);
|
|
1485
|
+
} catch {}
|
|
1486
|
+
return p.length > 1 ? p.replace(/\/+$/, "") : p;
|
|
1487
|
+
};
|
|
1488
|
+
/** `https://www.example.de/a/` and `/a/` → `/a`. */
|
|
1489
|
+
const toPath = (loc) => {
|
|
1490
|
+
const value = loc.trim();
|
|
1491
|
+
try {
|
|
1492
|
+
return normalize(new URL(value).pathname);
|
|
1493
|
+
} catch {
|
|
1494
|
+
return normalize(value);
|
|
1495
|
+
}
|
|
1496
|
+
};
|
|
1497
|
+
const locs = (xml) => [...xml.matchAll(/<loc>\s*([^<]+?)\s*<\/loc>/g)].map((m) => xmlText(m[1]));
|
|
1498
|
+
/** The URL lists the build publishes agree with the pages it built: no sitemap entry whose own page
|
|
1499
|
+
* says noindex or is not in the build, no `llms.txt` link to a page that is not there. Skipped when
|
|
1500
|
+
* the build publishes neither (a site before launch). */
|
|
1501
|
+
const sitemapNoindex = {
|
|
1502
|
+
id: "sitemap-noindex",
|
|
1503
|
+
title: "Published URL lists match the built pages",
|
|
1504
|
+
severity: "error",
|
|
1505
|
+
begin: (ctx) => {
|
|
1506
|
+
if (!ctx.hasDist) return null;
|
|
1507
|
+
const start = ctx.has(SITEMAP_INDEX) ? [SITEMAP_INDEX] : ctx.files.filter((f) => /^sitemap[^/]*\.xml$/.test(f));
|
|
1508
|
+
if (start.length === 0 && !ctx.has(LLMS)) return null;
|
|
1509
|
+
const noindex = /* @__PURE__ */ new Map();
|
|
1510
|
+
return {
|
|
1511
|
+
visit: (page) => {
|
|
1512
|
+
if (!page.redirect && page.noindex) noindex.set(normalize(page.url), page.path);
|
|
1513
|
+
},
|
|
1514
|
+
finish: () => {
|
|
1515
|
+
const findings = [];
|
|
1516
|
+
const sitemaps = new Map(start.map((file) => [file, ""]));
|
|
1517
|
+
for (const [sitemap, index] of sitemaps) {
|
|
1518
|
+
if (!ctx.has(sitemap)) {
|
|
1519
|
+
findings.push({
|
|
1520
|
+
path: index,
|
|
1521
|
+
message: `The sitemap index names ${sitemap}, which is not in the build.`
|
|
1522
|
+
});
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
const xml = ctx.read(sitemap);
|
|
1526
|
+
if (/<sitemapindex\b/i.test(xml)) {
|
|
1527
|
+
for (const loc of locs(xml)) {
|
|
1528
|
+
const child = toPath(loc).replace(/^\//, "");
|
|
1529
|
+
if (!sitemaps.has(child)) sitemaps.set(child, sitemap);
|
|
1530
|
+
}
|
|
1531
|
+
continue;
|
|
1532
|
+
}
|
|
1533
|
+
for (const loc of locs(xml)) {
|
|
1534
|
+
const urlPath = toPath(loc);
|
|
1535
|
+
if (!ctx.serves(urlPath)) findings.push({
|
|
1536
|
+
path: sitemap,
|
|
1537
|
+
message: `The sitemap lists ${loc}, which is not in the build.`
|
|
1538
|
+
});
|
|
1539
|
+
else if (noindex.has(urlPath)) findings.push({
|
|
1540
|
+
path: sitemap,
|
|
1541
|
+
message: `The sitemap lists ${loc}, whose page says noindex: the sitemap filter and the noindex routes disagree.`
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (ctx.has(LLMS)) for (const match of ctx.read(LLMS).matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
1546
|
+
const link = match[1];
|
|
1547
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(link) && !ctx.config.site) continue;
|
|
1548
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(link)) {
|
|
1549
|
+
let host;
|
|
1550
|
+
try {
|
|
1551
|
+
host = new URL(link).host;
|
|
1552
|
+
} catch {
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
if (host !== new URL(ctx.config.site).host) continue;
|
|
1556
|
+
}
|
|
1557
|
+
if (!ctx.serves(toPath(link))) findings.push({
|
|
1558
|
+
path: LLMS,
|
|
1559
|
+
message: `llms.txt links ${link}, which is not in the build.`
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
return findings;
|
|
1563
|
+
}
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
//#endregion
|
|
1568
|
+
//#region src/checks/syncOnce.ts
|
|
1569
|
+
const LOADER_FILES = ["src/content.config.ts", "src/content/config.ts"];
|
|
1570
|
+
/** A loader written inline, as opposed to `glob()` or `file()`. */
|
|
1571
|
+
const INLINE_LOADER = /\bloader\s*:\s*\{/;
|
|
1572
|
+
/** It talks to the PMS. */
|
|
1573
|
+
const LIVE_FETCH = /\bfetch\s*\(|createWebsiteSDK|createVofficeSdk|\.static\./;
|
|
1574
|
+
/** The reuse idiom: the loader keeps the sync token in the store's meta and, when the token the
|
|
1575
|
+
* build was started with is still the same, serves the entries it already has. */
|
|
1576
|
+
const REUSE_IDIOM = [
|
|
1577
|
+
/CONTENT_SYNC_TOKEN/,
|
|
1578
|
+
/\bmeta\.get\(/,
|
|
1579
|
+
/\bstore\.keys\(\)/
|
|
1580
|
+
];
|
|
1581
|
+
/** `astro check` and `astro build` each run the content loader, so an unguarded loader pays every
|
|
1582
|
+
* remote fetch twice on every build, against a rate-limited PMS. The build worker starts both with
|
|
1583
|
+
* one `CONTENT_SYNC_TOKEN`; a loader that keys its store on it syncs once. A text heuristic, hence
|
|
1584
|
+
* a warning. */
|
|
1585
|
+
const syncOnce = {
|
|
1586
|
+
id: "sync-once",
|
|
1587
|
+
title: "Content loaders sync the PMS once per build",
|
|
1588
|
+
severity: "warning",
|
|
1589
|
+
begin: (ctx) => {
|
|
1590
|
+
const loader = ctx.sourceFiles(/* @__PURE__ */ new Set([".ts"])).find((file) => LOADER_FILES.includes(ctx.rel(file)));
|
|
1591
|
+
if (!loader) return null;
|
|
1592
|
+
return { finish: () => {
|
|
1593
|
+
const text = ctx.readSource(loader);
|
|
1594
|
+
if (!INLINE_LOADER.test(text) || !LIVE_FETCH.test(text)) return [];
|
|
1595
|
+
if (REUSE_IDIOM.every((idiom) => idiom.test(text))) return [];
|
|
1596
|
+
return [{
|
|
1597
|
+
path: ctx.rel(loader),
|
|
1598
|
+
message: "A content loader fetches the PMS without the CONTENT_SYNC_TOKEN idiom; astro check and astro build each sync it, twice per build. Keep the token in the store's meta (meta.get) and reuse the entries (store.keys()) when it matches."
|
|
1599
|
+
}];
|
|
1600
|
+
} };
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
//#endregion
|
|
1604
|
+
//#region src/env.ts
|
|
1605
|
+
/** The env files a production build reads, in the order Vite applies them (a later file wins per
|
|
1606
|
+
* key). The `.local` pair is left out on purpose: it is the developer's machine, never what the
|
|
1607
|
+
* deployed site builds against, and a site must not commit it. */
|
|
1608
|
+
const BUILD_ENV_FILES = [".env", ".env.production"];
|
|
1609
|
+
/** Files Vite loads after the committed ones in every mode; committed, they win in CI too. */
|
|
1610
|
+
const LOCAL_ENV_FILES = [".env.local", ".env.production.local"];
|
|
1611
|
+
const ASSIGNMENT = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;
|
|
1612
|
+
/** `KEY=value` lines of one env file: `export` allowed, a value in matching quotes unquoted, a
|
|
1613
|
+
* ` # comment` after the value (quoted or not) dropped. The last assignment of a key wins. */
|
|
1614
|
+
const parseEnv = (text) => {
|
|
1615
|
+
const env = {};
|
|
1616
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1617
|
+
const match = ASSIGNMENT.exec(line);
|
|
1618
|
+
if (!match) continue;
|
|
1619
|
+
let value = match[2].trim();
|
|
1620
|
+
const quoted = /^(["'])(.*?)\1(?:\s+#.*)?$/.exec(value);
|
|
1621
|
+
value = quoted ? quoted[2] : value.replace(/\s+#.*$/, "").trim();
|
|
1622
|
+
env[match[1]] = value;
|
|
1623
|
+
}
|
|
1624
|
+
return env;
|
|
1625
|
+
};
|
|
1626
|
+
const readEnvFile = (root, file) => {
|
|
1627
|
+
const full = path.join(root, file);
|
|
1628
|
+
return fs.existsSync(full) ? parseEnv(fs.readFileSync(full, "utf8")) : {};
|
|
1629
|
+
};
|
|
1630
|
+
/** What a production build of the site reads from its committed env files. */
|
|
1631
|
+
const buildEnv = (root) => Object.assign({}, ...BUILD_ENV_FILES.map((file) => readEnvFile(root, file)));
|
|
1632
|
+
/** The SDK's env names (`SDK_ENV` in `@v-office/website-headless`) a build reads, and the two v9
|
|
1633
|
+
* config switches of the Website SDK CLI. */
|
|
1634
|
+
const SDK_NAMES = [
|
|
1635
|
+
"CMS_BACKEND",
|
|
1636
|
+
"CMS_STAGE",
|
|
1637
|
+
"HUB_API_KEY",
|
|
1638
|
+
"HUB_GRAPHQL_URL",
|
|
1639
|
+
"HUB_V0_API_BASE_URL",
|
|
1640
|
+
"HUB_V1_API_BASE_URL",
|
|
1641
|
+
"IMAGE_PROXY_BASE_URL",
|
|
1642
|
+
"HUB_RENTAL_SCOPE_PROPERTY_KIND",
|
|
1643
|
+
"HUB_RENTAL_IDS_SEARCH"
|
|
1644
|
+
];
|
|
1645
|
+
/** The SDK env the build runs with, resolved the way the site starter does: a value in the
|
|
1646
|
+
* process env wins over the committed files (Vite's order), and what neither sets comes from what
|
|
1647
|
+
* AI Studio's builder passes: the website's PMS generation as `PMS_BACKEND`, its key as
|
|
1648
|
+
* `PMS_TOKEN`. A template site commits no backend, so without the fallback a v9 site there would
|
|
1649
|
+
* read as no site at all. */
|
|
1650
|
+
const sdkEnv = (root, processEnv = process.env) => {
|
|
1651
|
+
const env = {};
|
|
1652
|
+
for (const [name, value] of Object.entries(buildEnv(root))) if (value.trim()) env[name] = value.trim();
|
|
1653
|
+
for (const name of SDK_NAMES) {
|
|
1654
|
+
const value = processEnv[name]?.trim();
|
|
1655
|
+
if (value) env[name] = value;
|
|
1656
|
+
}
|
|
1657
|
+
if (!env.CMS_BACKEND && processEnv.PMS_BACKEND?.trim()) env.CMS_BACKEND = processEnv.PMS_BACKEND.trim();
|
|
1658
|
+
if (env.CMS_BACKEND === "v9" && !env.HUB_API_KEY && processEnv.PMS_TOKEN?.trim()) env.HUB_API_KEY = processEnv.PMS_TOKEN.trim();
|
|
1659
|
+
return env;
|
|
1660
|
+
};
|
|
1661
|
+
/** What the developer's `.local` files set. */
|
|
1662
|
+
const localEnv = (root) => Object.assign({}, ...LOCAL_ENV_FILES.map((file) => readEnvFile(root, file)));
|
|
1663
|
+
//#endregion
|
|
1664
|
+
//#region src/checks/v9.ts
|
|
1665
|
+
/** The be-on! Hub endpoints per stage, as `@v-office/website-headless` resolves `CMS_STAGE` for v9
|
|
1666
|
+
* (`sdk/endpoints.ts`). Production is what a live v9 site calls. */
|
|
1667
|
+
const HUB = {
|
|
1668
|
+
production: {
|
|
1669
|
+
api: "https://api.voffice.be-on.io",
|
|
1670
|
+
imageProxy: "https://imgproxy.voffice.be-on.io"
|
|
1671
|
+
},
|
|
1672
|
+
development: {
|
|
1673
|
+
api: "https://api.voffice.demo-on.de",
|
|
1674
|
+
imageProxy: "https://imgproxy.voffice.demo-on.de"
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
const hubUrls = (stage) => ({
|
|
1678
|
+
HUB_V1_API_BASE_URL: `${HUB[stage].api}/api/v1`,
|
|
1679
|
+
HUB_V0_API_BASE_URL: `${HUB[stage].api}/api/v0`,
|
|
1680
|
+
HUB_GRAPHQL_URL: `${HUB[stage].api}/graphql`,
|
|
1681
|
+
IMAGE_PROXY_BASE_URL: HUB[stage].imageProxy
|
|
1682
|
+
});
|
|
1683
|
+
/** The build's SDK env, when it builds a v9 site: `CMS_BACKEND=v9` from the process env, the
|
|
1684
|
+
* committed `.env` / `.env.production`, or AI Studio's `PMS_BACKEND` (`sdkEnv`). Every v9 check
|
|
1685
|
+
* starts here, so a v10 site, or one with no backend at all, never runs one. */
|
|
1686
|
+
const v9Env = (ctx) => {
|
|
1687
|
+
const env = sdkEnv(ctx.root);
|
|
1688
|
+
return env.CMS_BACKEND === "v9" ? env : null;
|
|
1689
|
+
};
|
|
1690
|
+
const sameUrl = (a, b) => (a ?? "").replace(/\/+$/, "") === b.replace(/\/+$/, "");
|
|
1691
|
+
/** The `.local` env files git tracks; empty outside a git checkout (nothing to tell then). */
|
|
1692
|
+
const committedLocalFiles = (root) => LOCAL_ENV_FILES.filter((file) => {
|
|
1693
|
+
try {
|
|
1694
|
+
execFileSync("git", [
|
|
1695
|
+
"ls-files",
|
|
1696
|
+
"--error-unmatch",
|
|
1697
|
+
"--",
|
|
1698
|
+
file
|
|
1699
|
+
], {
|
|
1700
|
+
cwd: root,
|
|
1701
|
+
stdio: "ignore"
|
|
1702
|
+
});
|
|
1703
|
+
return true;
|
|
1704
|
+
} catch {
|
|
1705
|
+
return false;
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
/** A launched v9 site builds against the production be-on! Hub: the build's env says
|
|
1709
|
+
* `CMS_STAGE=production`, or names the production Hub URLs. The Hub URLs are baked in at build
|
|
1710
|
+
* time, so a site built against the demo Hub renders fine, only with the demo catalogue. Also
|
|
1711
|
+
* refused: a committed `.env.local` (Vite loads it after `.env` in every mode, so CI builds from
|
|
1712
|
+
* it) and a committed `HUB_API_KEY` that is the developer's local key. Waits while every page is
|
|
1713
|
+
* noindex, and while the Astro `site` is a preview host or unset: before launch a site builds
|
|
1714
|
+
* against the test Hub on purpose. v9 only. */
|
|
1715
|
+
const v9ProductionHub = {
|
|
1716
|
+
id: "v9-production-hub",
|
|
1717
|
+
title: "A launched v9 site calls the production Hub",
|
|
1718
|
+
severity: "error",
|
|
1719
|
+
begin: (ctx) => {
|
|
1720
|
+
const env = v9Env(ctx);
|
|
1721
|
+
if (!env || !ctx.hasDist || !productionSite(ctx)) return null;
|
|
1722
|
+
let launched = false;
|
|
1723
|
+
return {
|
|
1724
|
+
visit: (page) => {
|
|
1725
|
+
if (!page.redirect && !page.noindex && page.path !== "404.html") launched = true;
|
|
1726
|
+
},
|
|
1727
|
+
finish: () => {
|
|
1728
|
+
if (!launched) return [];
|
|
1729
|
+
const findings = [];
|
|
1730
|
+
const where = `the build's env (${BUILD_ENV_FILES.join(" / ")} or the process env)`;
|
|
1731
|
+
for (const file of committedLocalFiles(ctx.root)) findings.push({
|
|
1732
|
+
path: file,
|
|
1733
|
+
message: `${file} is committed: Vite loads it after .env in every mode, so the live site builds from it. Untrack it (git rm --cached) and keep it ignored.`
|
|
1734
|
+
});
|
|
1735
|
+
if (env.CMS_STAGE) {
|
|
1736
|
+
if (env.CMS_STAGE !== "production") findings.push({
|
|
1737
|
+
path: ".env",
|
|
1738
|
+
message: `CMS_STAGE is "${env.CMS_STAGE}" in ${where}: the live site calls the ${env.CMS_STAGE} Hub. Set CMS_STAGE=production.`
|
|
1739
|
+
});
|
|
1740
|
+
} else {
|
|
1741
|
+
const expected = hubUrls("production");
|
|
1742
|
+
const wrong = Object.keys(expected).filter((name) => !sameUrl(env[name], expected[name]));
|
|
1743
|
+
if (wrong.length > 0) findings.push({
|
|
1744
|
+
path: ".env",
|
|
1745
|
+
message: `${where[0].toUpperCase()}${where.slice(1)} does not call the production Hub: ${wrong.map((name) => `${name}=${env[name] || "(unset)"}`).join(", ")}. Set ${wrong.map((name) => `${name}=${expected[name]}`).join(", ")}, or CMS_STAGE=production without the URLs.`
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
const key = env.HUB_API_KEY;
|
|
1749
|
+
if (key && key === localEnv(ctx.root).HUB_API_KEY) findings.push({
|
|
1750
|
+
path: ".env",
|
|
1751
|
+
message: "HUB_API_KEY in the build's env is the key of .env.local, the developer's key: production needs this customer's production key, which be-on! issues."
|
|
1752
|
+
});
|
|
1753
|
+
return findings;
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
/** How long the Hub may take to answer before the check gives up. */
|
|
1759
|
+
const HUB_TIMEOUT_MS = 6e4;
|
|
1760
|
+
/** The Website SDK CLI's v9 config, from the build's SDK env (`sdkEnv`): the stage's endpoints with
|
|
1761
|
+
* `CMS_STAGE`, else the URL variables, and the key. */
|
|
1762
|
+
const cliConfig = (env) => {
|
|
1763
|
+
const stage = env.CMS_STAGE === "production" || env.CMS_STAGE === "development" ? env.CMS_STAGE : void 0;
|
|
1764
|
+
const urls = stage ? hubUrls(stage) : env;
|
|
1765
|
+
return {
|
|
1766
|
+
backend: "v9",
|
|
1767
|
+
apiKey: env.HUB_API_KEY ?? "",
|
|
1768
|
+
graphqlUrl: urls.HUB_GRAPHQL_URL ?? "",
|
|
1769
|
+
imageProxyBaseUrl: urls.IMAGE_PROXY_BASE_URL ?? "",
|
|
1770
|
+
...urls.HUB_V0_API_BASE_URL ? { v0ApiBaseUrl: urls.HUB_V0_API_BASE_URL } : {},
|
|
1771
|
+
...urls.HUB_V1_API_BASE_URL ? { v1ApiBaseUrl: urls.HUB_V1_API_BASE_URL } : {},
|
|
1772
|
+
...env.HUB_RENTAL_SCOPE_PROPERTY_KIND === "facility" || env.HUB_RENTAL_SCOPE_PROPERTY_KIND === "objectGroup" ? { rentalScopePropertyKind: env.HUB_RENTAL_SCOPE_PROPERTY_KIND } : {},
|
|
1773
|
+
...env.HUB_RENTAL_IDS_SEARCH === "true" || env.HUB_RENTAL_IDS_SEARCH === "false" ? { rentalIdsSearch: env.HUB_RENTAL_IDS_SEARCH === "true" } : {}
|
|
1774
|
+
};
|
|
1775
|
+
};
|
|
1776
|
+
const sdkVersion = (root) => {
|
|
1777
|
+
try {
|
|
1778
|
+
const file = path.join(root, "node_modules", "@v-office", "website-sdk", "package.json");
|
|
1779
|
+
return JSON.parse(fs.readFileSync(file, "utf8")).version ?? "unknown version";
|
|
1780
|
+
} catch {
|
|
1781
|
+
return "unknown version";
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
const run = (cli, args, cwd) => new Promise((resolve) => {
|
|
1785
|
+
execFile(cli, args, {
|
|
1786
|
+
cwd,
|
|
1787
|
+
timeout: HUB_TIMEOUT_MS,
|
|
1788
|
+
maxBuffer: 1048576
|
|
1789
|
+
}, (err, stdout, stderr) => resolve({
|
|
1790
|
+
code: err ? typeof err.code === "number" ? err.code : 1 : 0,
|
|
1791
|
+
output: `${stdout}${stderr}`.trim()
|
|
1792
|
+
}));
|
|
1793
|
+
});
|
|
1794
|
+
/** Every be-on! Hub filter the site's search needs (the scope filter, the Merkliste's rental-id
|
|
1795
|
+
* filter, each searchable backend-filter definition) exists in the Hub the site builds against.
|
|
1796
|
+
* A filter the Hub does not serve matches nothing, or everything once a date is set. Asks the Hub
|
|
1797
|
+
* through the site's own `website-sdk hub-filters check`, with the build's env and the SDK
|
|
1798
|
+
* options in `hubFilterOptions`. A warning: the outcome is the Hub's data, and a Hub that cannot be
|
|
1799
|
+
* asked must not stop the nightly builds; it is reported, never passed. v9 only. */
|
|
1800
|
+
const v9HubFilters = {
|
|
1801
|
+
id: "v9-hub-filters",
|
|
1802
|
+
title: "The be-on! Hub serves the filters the v9 site needs",
|
|
1803
|
+
severity: "warning",
|
|
1804
|
+
begin: (ctx) => {
|
|
1805
|
+
const env = v9Env(ctx);
|
|
1806
|
+
if (!env) return null;
|
|
1807
|
+
return { finish: async () => {
|
|
1808
|
+
const cli = path.join(ctx.root, "node_modules", ".bin", process.platform === "win32" ? "website-sdk.cmd" : "website-sdk");
|
|
1809
|
+
if (!fs.existsSync(cli)) return [{ message: "node_modules/.bin/website-sdk is missing, so the Hub could not be asked. Install @v-office/website-sdk." }];
|
|
1810
|
+
const config = cliConfig(env);
|
|
1811
|
+
if (!config.apiKey || !config.graphqlUrl) return [{ message: "No HUB_API_KEY or Hub URLs in the build's env, so the Hub could not be asked." }];
|
|
1812
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "site-checks-hub-"));
|
|
1813
|
+
try {
|
|
1814
|
+
const configFile = path.join(dir, "config.json");
|
|
1815
|
+
const optionsFile = path.join(dir, "options.json");
|
|
1816
|
+
fs.writeFileSync(configFile, JSON.stringify(config));
|
|
1817
|
+
fs.writeFileSync(optionsFile, JSON.stringify(ctx.options.hubFilterOptions));
|
|
1818
|
+
const { code, output } = await run(cli, [
|
|
1819
|
+
"--backend",
|
|
1820
|
+
"v9",
|
|
1821
|
+
"--config",
|
|
1822
|
+
configFile,
|
|
1823
|
+
"--options",
|
|
1824
|
+
optionsFile,
|
|
1825
|
+
"hub-filters",
|
|
1826
|
+
"check"
|
|
1827
|
+
], ctx.root);
|
|
1828
|
+
if (code === 0) return [];
|
|
1829
|
+
if (/Unknown subcommand "hub-filters"/.test(output)) return [{ message: `The installed @v-office/website-sdk (${sdkVersion(ctx.root)}) has no \`hub-filters check\`, so the Hub could not be asked. Update @v-office/website-sdk.` }];
|
|
1830
|
+
return [{ message: `The be-on! Hub (${new URL(config.graphqlUrl).host}) does not serve every filter the site needs: ${output || `website-sdk exited ${code}`} Add the missing entries in the Hub (website-sdk hub-filters request) or drop them from the site's SDK options.` }];
|
|
1831
|
+
} finally {
|
|
1832
|
+
fs.rmSync(dir, {
|
|
1833
|
+
recursive: true,
|
|
1834
|
+
force: true
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
} };
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
//#endregion
|
|
1841
|
+
//#region src/jsComments.ts
|
|
1842
|
+
/** One pass over JavaScript (or the script parts of a component): its comments, and the code with
|
|
1843
|
+
* them blanked. String and template literals are kept whole, so `//` in `"https://…"` or `/*` in
|
|
1844
|
+
* `'a /* b'` is no comment; `${…}` inside a template is code again, to its matching `}`. `'…'` and
|
|
1845
|
+
* `"…"` end at their quote or at a newline (an apostrophe in markup text shields only the rest of
|
|
1846
|
+
* its line). A block comment keeps its newlines, so line starts stay line starts. A regular
|
|
1847
|
+
* expression literal (`/[/*]/g`) is kept whole too, where a `/` can only start one: after an
|
|
1848
|
+
* operator or opening bracket, or a keyword such as `return`. */
|
|
1849
|
+
/** Where a `/` begins a regular expression rather than a division: after one of these, an arrow,
|
|
1850
|
+
* or a keyword that takes an expression. Never after a lone `<` or `>`, so markup paths stay text,
|
|
1851
|
+
* and never after `)`, where a division is the common case. */
|
|
1852
|
+
const BEFORE_REGEX = /* @__PURE__ */ new Set("(,=:[!&|?{};");
|
|
1853
|
+
const KEYWORD_BEFORE = /\b(?:return|typeof|case|do|else|in|of|void|yield|await|delete|new)\s*$/;
|
|
1854
|
+
const startsRegex = (code) => {
|
|
1855
|
+
const before = code.trimEnd();
|
|
1856
|
+
return before === "" || BEFORE_REGEX.has(before.at(-1)) || before.endsWith("=>") || KEYWORD_BEFORE.test(before);
|
|
1857
|
+
};
|
|
1858
|
+
/** The index past a regular expression literal starting at `start`, its flags included: `/` inside
|
|
1859
|
+
* a character class or after `\` does not end it. A newline first means it was no literal: the
|
|
1860
|
+
* `/` alone is consumed. */
|
|
1861
|
+
const regexEnd = (text, start) => {
|
|
1862
|
+
let inClass = false;
|
|
1863
|
+
for (let j = start + 1; j < text.length; j += 1) {
|
|
1864
|
+
const ch = text[j];
|
|
1865
|
+
if (ch === "\\") j += 1;
|
|
1866
|
+
else if (ch === "\n") break;
|
|
1867
|
+
else if (ch === "[") inClass = true;
|
|
1868
|
+
else if (ch === "]") inClass = false;
|
|
1869
|
+
else if (ch === "/" && !inClass) {
|
|
1870
|
+
let end = j + 1;
|
|
1871
|
+
while (end < text.length && /[a-z]/i.test(text[end])) end += 1;
|
|
1872
|
+
return end;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
return start + 1;
|
|
1876
|
+
};
|
|
1877
|
+
const scan = (text) => {
|
|
1878
|
+
let out = "";
|
|
1879
|
+
const comments = [];
|
|
1880
|
+
let i = 0;
|
|
1881
|
+
const n = text.length;
|
|
1882
|
+
const templates = [];
|
|
1883
|
+
let depth = 0;
|
|
1884
|
+
while (i < n) {
|
|
1885
|
+
const c = text[i];
|
|
1886
|
+
if (templates.length > 0 && templates.at(-1) === -1) {
|
|
1887
|
+
if (c === "\\") {
|
|
1888
|
+
out += text.slice(i, i + 2);
|
|
1889
|
+
i += 2;
|
|
1890
|
+
} else if (c === "`") {
|
|
1891
|
+
templates.pop();
|
|
1892
|
+
out += c;
|
|
1893
|
+
i += 1;
|
|
1894
|
+
} else if (text.startsWith("${", i)) {
|
|
1895
|
+
templates[templates.length - 1] = depth;
|
|
1896
|
+
depth += 1;
|
|
1897
|
+
out += "${";
|
|
1898
|
+
i += 2;
|
|
1899
|
+
} else {
|
|
1900
|
+
out += c;
|
|
1901
|
+
i += 1;
|
|
1902
|
+
}
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
if (c === "\\") {
|
|
1906
|
+
out += text.slice(i, i + 2);
|
|
1907
|
+
i += 2;
|
|
1908
|
+
} else if (text.startsWith("//", i)) {
|
|
1909
|
+
const end = text.indexOf("\n", i);
|
|
1910
|
+
comments.push(text.slice(i, end === -1 ? n : end));
|
|
1911
|
+
out += " ";
|
|
1912
|
+
i = end === -1 ? n : end;
|
|
1913
|
+
} else if (text.startsWith("/*", i)) {
|
|
1914
|
+
const close = text.indexOf("*/", i + 2);
|
|
1915
|
+
const end = close === -1 ? n : close + 2;
|
|
1916
|
+
comments.push(text.slice(i, end));
|
|
1917
|
+
out += ` ${"\n".repeat((text.slice(i, end).match(/\n/g) ?? []).length)}`;
|
|
1918
|
+
i = end;
|
|
1919
|
+
} else if (c === "/" && startsRegex(out)) {
|
|
1920
|
+
const end = regexEnd(text, i);
|
|
1921
|
+
out += text.slice(i, end);
|
|
1922
|
+
i = end;
|
|
1923
|
+
} else if (c === "'" || c === "\"") {
|
|
1924
|
+
let j = i + 1;
|
|
1925
|
+
while (j < n && text[j] !== c && text[j] !== "\n") j += text[j] === "\\" ? 2 : 1;
|
|
1926
|
+
if (j < n && text[j] === c) j += 1;
|
|
1927
|
+
out += text.slice(i, j);
|
|
1928
|
+
i = j;
|
|
1929
|
+
} else if (c === "`") {
|
|
1930
|
+
templates.push(-1);
|
|
1931
|
+
out += c;
|
|
1932
|
+
i += 1;
|
|
1933
|
+
} else {
|
|
1934
|
+
if (c === "{") depth += 1;
|
|
1935
|
+
else if (c === "}") {
|
|
1936
|
+
depth -= 1;
|
|
1937
|
+
if (templates.length > 0 && templates.at(-1) === depth) templates[templates.length - 1] = -1;
|
|
1938
|
+
}
|
|
1939
|
+
out += c;
|
|
1940
|
+
i += 1;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return {
|
|
1944
|
+
code: out,
|
|
1945
|
+
comments
|
|
1946
|
+
};
|
|
1947
|
+
};
|
|
1948
|
+
/** The text with its comments blanked. */
|
|
1949
|
+
const stripComments = (text) => scan(text).code;
|
|
1950
|
+
/** Every comment in the text, as written. */
|
|
1951
|
+
const jsComments = (text) => scan(text).comments;
|
|
1952
|
+
//#endregion
|
|
1953
|
+
//#region src/checks/viewSource.ts
|
|
1954
|
+
/** Comments the frameworks themselves write into static HTML, and no developer did: Astro's
|
|
1955
|
+
* island and server-island markers, React 19's SSR markers (`<!--$-->`, `<!--/$-->`, …, and the
|
|
1956
|
+
* `<!-- -->` text separator), Vue's SSR fragment and teleport markers. Matched on the trimmed
|
|
1957
|
+
* comment text. A framework upgrade that adds a marker shows up as a refused build; extend the
|
|
1958
|
+
* list here, in one place. */
|
|
1959
|
+
const FRAMEWORK_COMMENTS = /* @__PURE__ */ new Set([
|
|
1960
|
+
"",
|
|
1961
|
+
"$",
|
|
1962
|
+
"/$",
|
|
1963
|
+
"$!",
|
|
1964
|
+
"$?",
|
|
1965
|
+
"&",
|
|
1966
|
+
"/&",
|
|
1967
|
+
"F",
|
|
1968
|
+
"F!",
|
|
1969
|
+
"html",
|
|
1970
|
+
"head",
|
|
1971
|
+
"body",
|
|
1972
|
+
"[",
|
|
1973
|
+
"]",
|
|
1974
|
+
"teleport start",
|
|
1975
|
+
"teleport end"
|
|
1976
|
+
]);
|
|
1977
|
+
const isFrameworkComment = (data) => {
|
|
1978
|
+
const text = data.trim();
|
|
1979
|
+
return FRAMEWORK_COMMENTS.has(text) || text.startsWith("astro:") || text.startsWith("server-island");
|
|
1980
|
+
};
|
|
1981
|
+
/** Licence banners and bundler annotations survive minification on purpose and say nothing. */
|
|
1982
|
+
const LEGAL_BLOCK_COMMENT = /^\/\*\s*[!@#]|@license|@preserve/;
|
|
1983
|
+
const BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1984
|
+
/** A line comment at the start of a line. `//` elsewhere is usually a URL. `//#` and `//!` are
|
|
1985
|
+
* directives (source maps, legal comments), reported or allowed on their own. */
|
|
1986
|
+
const LINE_COMMENT = /^[ \t]*\/\/(?![#!])(.*)$/gm;
|
|
1987
|
+
const SOURCE_MAP_URL = /(?:\/\/|\/\*)# sourceMappingURL=/;
|
|
1988
|
+
/** Directives a handler may carry: a source-map pointer (reported on its own) and a legal comment. */
|
|
1989
|
+
const DIRECTIVE = /^\/\/[#!]/;
|
|
1990
|
+
const excerpt = (text) => {
|
|
1991
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
1992
|
+
return flat.length > 80 ? `${flat.slice(0, 79)}…` : flat;
|
|
1993
|
+
};
|
|
1994
|
+
const blockComments = (text) => (text.match(BLOCK_COMMENT) ?? []).filter((comment) => !LEGAL_BLOCK_COMMENT.test(comment));
|
|
1995
|
+
const lineComments = (text) => [...text.matchAll(LINE_COMMENT)].map((match) => `//${match[1] ?? ""}`);
|
|
1996
|
+
/** What a visitor can read with View Source, and no developer meant for them: comments in the
|
|
1997
|
+
* built pages, in their inline scripts, styles and event handlers, and in the shipped CSS; line comments in the
|
|
1998
|
+
* shipped JS (a minified bundle has none at a line start); source maps. Block comments in shipped
|
|
1999
|
+
* JS are not scanned: the minifier strips them, and `/*` inside a glob string would read as one. */
|
|
2000
|
+
const viewSource = {
|
|
2001
|
+
id: "view-source",
|
|
2002
|
+
title: "Developer notes visible in View Source",
|
|
2003
|
+
severity: "error",
|
|
2004
|
+
begin: (ctx) => {
|
|
2005
|
+
if (!ctx.hasDist) return null;
|
|
2006
|
+
const findings = [];
|
|
2007
|
+
const report = (path, what, text) => findings.push({
|
|
2008
|
+
path,
|
|
2009
|
+
message: `${what}: "${excerpt(text)}"`
|
|
2010
|
+
});
|
|
2011
|
+
const visit = (page) => {
|
|
2012
|
+
for (const comment of page.comments()) if (!isFrameworkComment(comment)) report(page.path, "HTML comment in the page", comment);
|
|
2013
|
+
for (const el of page.document.querySelectorAll("*")) for (const name of el.getAttributeNames()) {
|
|
2014
|
+
if (!name.startsWith("on")) continue;
|
|
2015
|
+
const code = el.getAttribute(name) ?? "";
|
|
2016
|
+
const what = `comment in an inline ${name} handler`;
|
|
2017
|
+
for (const comment of jsComments(code)) if (!DIRECTIVE.test(comment) && !LEGAL_BLOCK_COMMENT.test(comment)) report(page.path, what, comment);
|
|
2018
|
+
}
|
|
2019
|
+
for (const el of page.document.querySelectorAll("script, style")) {
|
|
2020
|
+
const text = el.textContent ?? "";
|
|
2021
|
+
const what = `comment in an inline <${el.tagName.toLowerCase()}>`;
|
|
2022
|
+
for (const comment of blockComments(text)) report(page.path, what, comment);
|
|
2023
|
+
if (el.tagName === "SCRIPT") {
|
|
2024
|
+
if (SOURCE_MAP_URL.test(text)) report(page.path, "source map reference in an inline <script>", text);
|
|
2025
|
+
for (const comment of lineComments(text)) report(page.path, what, comment);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
const finish = () => {
|
|
2030
|
+
for (const file of ctx.files) {
|
|
2031
|
+
if (file.endsWith(".map")) {
|
|
2032
|
+
findings.push({
|
|
2033
|
+
path: file,
|
|
2034
|
+
message: "A source map ships the original source to anyone who asks for it."
|
|
2035
|
+
});
|
|
2036
|
+
continue;
|
|
2037
|
+
}
|
|
2038
|
+
const isJs = /\.m?js$/.test(file);
|
|
2039
|
+
const isCss = file.endsWith(".css");
|
|
2040
|
+
if (!isJs && !isCss) continue;
|
|
2041
|
+
const text = ctx.read(file);
|
|
2042
|
+
if (SOURCE_MAP_URL.test(text)) report(file, "source map reference", "sourceMappingURL");
|
|
2043
|
+
if (isCss) for (const comment of blockComments(text)) report(file, "comment in shipped CSS", comment);
|
|
2044
|
+
if (isJs) for (const comment of lineComments(text)) report(file, "comment in shipped JS", comment);
|
|
2045
|
+
}
|
|
2046
|
+
return findings;
|
|
2047
|
+
};
|
|
2048
|
+
return {
|
|
2049
|
+
visit,
|
|
2050
|
+
finish
|
|
2051
|
+
};
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
//#endregion
|
|
2055
|
+
//#region src/checks/wiring.ts
|
|
2056
|
+
const FN_KEYWORD = /\bfunction\s*\*?\s*$/;
|
|
2057
|
+
const MEMBER_START = /(?:^|[{};,]|\b(?:async|static|get|set|public|private|protected|readonly|abstract|override|declare))\s*$/;
|
|
2058
|
+
const LINE_START = /\n[ \t]*$/;
|
|
2059
|
+
/** After one of these the expression goes on, so a line start does not begin a member. */
|
|
2060
|
+
const CONTINUES = /* @__PURE__ */ new Set("?:=(.,&|+-*/%<>!~^[");
|
|
2061
|
+
const closeParen = (text, open) => {
|
|
2062
|
+
let depth = 0;
|
|
2063
|
+
for (let i = open; i < text.length; i += 1) {
|
|
2064
|
+
const c = text[i];
|
|
2065
|
+
if (c === "'" || c === "\"" || c === "`") {
|
|
2066
|
+
i += 1;
|
|
2067
|
+
while (i < text.length && text[i] !== c) i += text[i] === "\\" ? 2 : 1;
|
|
2068
|
+
} else if (c === "(") depth += 1;
|
|
2069
|
+
else if (c === ")") {
|
|
2070
|
+
depth -= 1;
|
|
2071
|
+
if (depth === 0) return i + 1;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
return null;
|
|
2075
|
+
};
|
|
2076
|
+
/** `NAME(` that opens a definition — `function NAME(`, a method `NAME(…) {`, a signature
|
|
2077
|
+
* `NAME(…): T` where a member starts — rather than a call. A file that defines the function it
|
|
2078
|
+
* must call would otherwise pass with the real call deleted. */
|
|
2079
|
+
const isDefinition = (text, start, paren) => {
|
|
2080
|
+
const before = text.slice(0, start);
|
|
2081
|
+
if (FN_KEYWORD.test(before)) return true;
|
|
2082
|
+
const end = closeParen(text, paren);
|
|
2083
|
+
if (end === null) return false;
|
|
2084
|
+
const after = text.slice(end).trimStart();
|
|
2085
|
+
if (after.startsWith("{")) return true;
|
|
2086
|
+
if (after.startsWith(":")) {
|
|
2087
|
+
if (MEMBER_START.test(before)) return true;
|
|
2088
|
+
const prev = before.trimEnd();
|
|
2089
|
+
if (LINE_START.test(before) && prev !== "" && !CONTINUES.has(prev.at(-1))) return true;
|
|
2090
|
+
}
|
|
2091
|
+
return false;
|
|
2092
|
+
};
|
|
2093
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2094
|
+
/** A real call of `fn` in comment-stripped code: not an import, not prose, not its definition. */
|
|
2095
|
+
const calls = (code, fn) => [...code.matchAll(new RegExp(`\\b${escape(fn)}\\s*\\(`, "g"))].some((m) => !isDefinition(code, m.index, m.index + m[0].length - 1));
|
|
2096
|
+
/** `@bound-by-parent <init> [<init>…]`: the initializers a leaf hands to whoever renders it. The
|
|
2097
|
+
* list may wrap onto a comment's next line; names run until the first token that is not one. */
|
|
2098
|
+
const OPT_OUT = /@bound-by-parent((?:[ \t]*,?[ \t]*(?:\r?\n[ \t]*(?:\*|\/\/))?[ \t]+init[A-Za-z0-9_]*)+)/g;
|
|
2099
|
+
const handedUp = (text) => new Set([...text.matchAll(OPT_OUT)].flatMap((m) => m[1].split(/[^A-Za-z0-9_]+/).filter((token) => token.startsWith("init"))));
|
|
2100
|
+
const COMPONENT_EXTENSIONS = /* @__PURE__ */ new Set([".astro", ".tsx"]);
|
|
2101
|
+
const SCRIPT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2102
|
+
".ts",
|
|
2103
|
+
".js",
|
|
2104
|
+
".mjs",
|
|
2105
|
+
".jsx"
|
|
2106
|
+
]);
|
|
2107
|
+
/** Files whose text is partly markup, which the comment scanner cannot tell from script. */
|
|
2108
|
+
const MARKUP_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
2109
|
+
".astro",
|
|
2110
|
+
".tsx",
|
|
2111
|
+
".jsx",
|
|
2112
|
+
".html",
|
|
2113
|
+
".md",
|
|
2114
|
+
".mdx"
|
|
2115
|
+
]);
|
|
2116
|
+
const readComponents = (ctx) => ctx.sourceFiles(COMPONENT_EXTENSIONS).map((file) => {
|
|
2117
|
+
const raw = ctx.readSource(file);
|
|
2118
|
+
return {
|
|
2119
|
+
file,
|
|
2120
|
+
rel: ctx.rel(file),
|
|
2121
|
+
stem: path.basename(file, path.extname(file)),
|
|
2122
|
+
raw,
|
|
2123
|
+
code: stripComments(raw),
|
|
2124
|
+
up: handedUp(raw)
|
|
2125
|
+
};
|
|
2126
|
+
});
|
|
2127
|
+
/** A project-relative path inside the project, or null. */
|
|
2128
|
+
const inside = (ctx, rel) => {
|
|
2129
|
+
if (path.isAbsolute(rel)) return null;
|
|
2130
|
+
const full = path.resolve(ctx.root, rel);
|
|
2131
|
+
return full.startsWith(`${path.resolve(ctx.root)}${path.sep}`) ? full : null;
|
|
2132
|
+
};
|
|
2133
|
+
const checkKept = (ctx, entry) => {
|
|
2134
|
+
const full = inside(ctx, entry.file);
|
|
2135
|
+
if (!full) return `wiring: "file" must be a path inside the project, got "${entry.file}"`;
|
|
2136
|
+
if (!fs.existsSync(full)) return `${entry.file} is missing; it must contain \`${entry.contains}\`. Guard: ${entry.guard}`;
|
|
2137
|
+
const raw = fs.readFileSync(full, "utf8");
|
|
2138
|
+
const literal = MARKUP_EXTENSIONS.has(path.extname(full)) && (entry.contains.includes("//") || entry.contains.includes("/*"));
|
|
2139
|
+
if (stripComments(raw).includes(entry.contains) || literal && raw.includes(entry.contains)) return null;
|
|
2140
|
+
const where = raw.includes(entry.contains) ? " (only in a comment)" : "";
|
|
2141
|
+
return `${entry.file} no longer contains \`${entry.contains}\`${where}. Guard: ${entry.guard}`;
|
|
2142
|
+
};
|
|
2143
|
+
/** The findings of one binding hook. */
|
|
2144
|
+
const checkHook = (ctx, hook, components, scripts) => {
|
|
2145
|
+
const { init, marker } = hook;
|
|
2146
|
+
if (hook.file !== void 0) {
|
|
2147
|
+
const full = inside(ctx, hook.file);
|
|
2148
|
+
if (!full) return [{ message: `wiring: "file" must be a path inside the project, got "${hook.file}"` }];
|
|
2149
|
+
if (!fs.existsSync(full)) return [{
|
|
2150
|
+
path: hook.file,
|
|
2151
|
+
message: `${hook.file} is missing; the entry binds \`${marker}\` there. Update the entry.`
|
|
2152
|
+
}];
|
|
2153
|
+
const raw = fs.readFileSync(full, "utf8");
|
|
2154
|
+
if (!stripComments(raw).includes(marker)) {
|
|
2155
|
+
const where = raw.includes(marker) ? " (only in a comment)" : "";
|
|
2156
|
+
return [{
|
|
2157
|
+
path: hook.file,
|
|
2158
|
+
message: `The marker \`${marker}\` is not in ${hook.file}${where}: the entry no longer binds. Update it.`
|
|
2159
|
+
}];
|
|
2160
|
+
}
|
|
2161
|
+
if (hook.scope === "section" && !COMPONENT_EXTENSIONS.has(path.extname(full)) && !calls(stripComments(raw), init) && !handedUp(raw).has(init)) return [{
|
|
2162
|
+
path: hook.file,
|
|
2163
|
+
message: `${hook.file} carries \`${marker}\` but never calls ${init}().`
|
|
2164
|
+
}];
|
|
2165
|
+
}
|
|
2166
|
+
const carriers = new Set(components.filter((c) => c.code.includes(marker)));
|
|
2167
|
+
const namedCarrier = hook.file !== void 0 && !COMPONENT_EXTENSIONS.has(path.extname(hook.file));
|
|
2168
|
+
if (carriers.size === 0 && !namedCarrier) return [];
|
|
2169
|
+
const binders = new Set(components.filter((c) => calls(c.code, init)));
|
|
2170
|
+
if (hook.scope === "global") return binders.size > 0 || scripts.some((code) => calls(code, init)) ? [] : [{ message: `${carriers.size || 1} file(s) carry \`${marker}\` (e.g. ${[...carriers][0]?.rel ?? hook.file}) but nothing in src/ calls ${init}(): the markup renders and does nothing.` }];
|
|
2171
|
+
const delegators = new Set([...carriers].filter((c) => c.up.has(init)));
|
|
2172
|
+
for (let grew = true; grew;) {
|
|
2173
|
+
grew = false;
|
|
2174
|
+
const names = [...delegators].map((d) => d.stem);
|
|
2175
|
+
for (const c of components) {
|
|
2176
|
+
if (delegators.has(c) || binders.has(c)) continue;
|
|
2177
|
+
if (!names.some((name) => new RegExp(`<${escape(name)}\\b`).test(c.code))) continue;
|
|
2178
|
+
carriers.add(c);
|
|
2179
|
+
if (c.up.has(init)) {
|
|
2180
|
+
delegators.add(c);
|
|
2181
|
+
grew = true;
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
return [...carriers].filter((c) => !c.up.has(init) && !binders.has(c)).sort((a, b) => a.rel.localeCompare(b.rel)).map((c) => ({
|
|
2186
|
+
path: c.rel,
|
|
2187
|
+
message: `${c.rel} carries \`${marker}\` but never calls ${init}(): the markup renders and does nothing. Call it, or mark the leaf \`@bound-by-parent ${init}\` when its parent owns the call.`
|
|
2188
|
+
}));
|
|
2189
|
+
};
|
|
2190
|
+
/** Markup is inert until a script binds it: every component carrying a configured hook's marker is
|
|
2191
|
+
* bound, and every kept text is still in its file. A type check, the build and a screenshot all
|
|
2192
|
+
* pass over a control whose initializer call was deleted; only this sees it. Comments are
|
|
2193
|
+
* stripped before any match. Configured by `wiring` (the former `scripts/wiring.json`). */
|
|
2194
|
+
const wiring = {
|
|
2195
|
+
id: "wiring",
|
|
2196
|
+
title: "Markup hooks are bound",
|
|
2197
|
+
severity: "error",
|
|
2198
|
+
begin: (ctx) => {
|
|
2199
|
+
if (ctx.options.wiring.length === 0) return null;
|
|
2200
|
+
return { finish: () => {
|
|
2201
|
+
const components = readComponents(ctx);
|
|
2202
|
+
const scripts = ctx.sourceFiles(SCRIPT_EXTENSIONS).map((file) => stripComments(ctx.readSource(file)));
|
|
2203
|
+
const findings = [];
|
|
2204
|
+
for (const entry of ctx.options.wiring) if ("contains" in entry) {
|
|
2205
|
+
const problem = checkKept(ctx, entry);
|
|
2206
|
+
if (problem) findings.push({
|
|
2207
|
+
path: entry.file,
|
|
2208
|
+
message: problem
|
|
2209
|
+
});
|
|
2210
|
+
} else findings.push(...checkHook(ctx, entry, components, scripts));
|
|
2211
|
+
return findings;
|
|
2212
|
+
} };
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
const SCRIPTS_DIR = "src/scripts";
|
|
2216
|
+
const EXPORTED_INIT = /export\s+(?:async\s+)?function\s*\*?\s*(init[A-Za-z0-9_]+)/g;
|
|
2217
|
+
//#endregion
|
|
2218
|
+
//#region src/checks/index.ts
|
|
2219
|
+
/** The site checks, in the order the report shows them: the source first, then the built pages.
|
|
2220
|
+
* The integration runs these inside the site's own `astro build`; the build worker's checks are
|
|
2221
|
+
* the other family (`distChecks/`), and an id here must not reuse one of theirs (a test holds the
|
|
2222
|
+
* rule). Adding a check is one file here, one entry, one test, a README row and a CHANGELOG
|
|
2223
|
+
* entry. */
|
|
2224
|
+
const checks = [
|
|
2225
|
+
htmlComments,
|
|
2226
|
+
syncOnce,
|
|
2227
|
+
optimizeDeps,
|
|
2228
|
+
wiring,
|
|
2229
|
+
{
|
|
2230
|
+
id: "unused-initializers",
|
|
2231
|
+
title: "Exported initializers are called",
|
|
2232
|
+
severity: "warning",
|
|
2233
|
+
begin: (ctx) => {
|
|
2234
|
+
const dir = path.join(ctx.root, SCRIPTS_DIR);
|
|
2235
|
+
if (!fs.existsSync(dir)) return null;
|
|
2236
|
+
return { finish: () => {
|
|
2237
|
+
const scripts = fs.readdirSync(dir).filter((name) => name.endsWith(".ts")).sort().map((name) => {
|
|
2238
|
+
const raw = fs.readFileSync(path.join(dir, name), "utf8");
|
|
2239
|
+
return {
|
|
2240
|
+
rel: `${SCRIPTS_DIR}/${name}`,
|
|
2241
|
+
code: stripComments(raw)
|
|
2242
|
+
};
|
|
2243
|
+
});
|
|
2244
|
+
const components = readComponents(ctx);
|
|
2245
|
+
const modules = ctx.sourceFiles(SCRIPT_EXTENSIONS).map((file) => stripComments(ctx.readSource(file)));
|
|
2246
|
+
const findings = [];
|
|
2247
|
+
for (const script of scripts) for (const [, fn] of script.code.matchAll(EXPORTED_INIT)) if (!(components.some((c) => calls(c.code, fn)) || modules.some((code) => calls(code, fn)))) findings.push({
|
|
2248
|
+
path: script.rel,
|
|
2249
|
+
message: `${fn}() is exported and never called: wire the feature, or delete the leftover.`
|
|
2250
|
+
});
|
|
2251
|
+
return findings;
|
|
2252
|
+
} };
|
|
2253
|
+
}
|
|
2254
|
+
},
|
|
2255
|
+
v9HubFilters,
|
|
2256
|
+
viewSource,
|
|
2257
|
+
donorTerms,
|
|
2258
|
+
consentGate,
|
|
2259
|
+
imageFormats,
|
|
2260
|
+
feedImageFormats,
|
|
2261
|
+
listingNoindex,
|
|
2262
|
+
listingLinks,
|
|
2263
|
+
sitemapNoindex,
|
|
2264
|
+
pageHeads,
|
|
2265
|
+
canonicalLink,
|
|
2266
|
+
openGraph,
|
|
2267
|
+
trailingSlash,
|
|
2268
|
+
v9ProductionHub,
|
|
2269
|
+
pageStructure,
|
|
2270
|
+
loadOrder,
|
|
2271
|
+
bannedCopy,
|
|
2272
|
+
duplicateSentences,
|
|
2273
|
+
quoteSources,
|
|
2274
|
+
rentalFacts
|
|
2275
|
+
];
|
|
2276
|
+
//#endregion
|
|
2277
|
+
//#region src/options.ts
|
|
2278
|
+
const CONFIG_FILE = "site-checks.config.json";
|
|
2279
|
+
/** The vOffice image hosts that answer JPEG unless asked for WebP: imgproxy's `plain` path (v9,
|
|
2280
|
+
* `…jpg@webp`) and `dyn.v-office.com` (`….webp`). The v10 host answers WebP by itself. */
|
|
2281
|
+
const DEFAULT_FEED_IMAGE_PATTERNS = ["\\/_\\/[^\\s]*\\/plain\\/[^\\s@]+\\.(?:jpe?g|png)$", "^https:\\/\\/dyn\\.v-office\\.com\\/image\\/[^\\s]+\\.(?:jpe?g|png)$"];
|
|
2282
|
+
const STRUCTURE_RULES = [
|
|
2283
|
+
"one-h1",
|
|
2284
|
+
"heading-skip",
|
|
2285
|
+
"landmark-main",
|
|
2286
|
+
"img-alt",
|
|
2287
|
+
"control-label",
|
|
2288
|
+
"table-headers",
|
|
2289
|
+
"heading-ratio"
|
|
2290
|
+
];
|
|
2291
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2292
|
+
const isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
2293
|
+
const isListOf = (value, item) => Array.isArray(value) && value.every((entry) => isObject(entry) && item(entry));
|
|
2294
|
+
const isString = (value) => typeof value === "string";
|
|
2295
|
+
const nonEmpty = (value) => isString(value) && value.trim() !== "";
|
|
2296
|
+
/** A pattern that does not compile would fail its check at every build, silently. */
|
|
2297
|
+
const compiles = (source, key, pattern, flags) => {
|
|
2298
|
+
try {
|
|
2299
|
+
new RegExp(pattern, flags);
|
|
2300
|
+
} catch (err) {
|
|
2301
|
+
throw new Error(`[site-checks] ${source}: "${key}" has an invalid regular expression ${JSON.stringify(pattern)}: ${err.message}`);
|
|
2302
|
+
}
|
|
2303
|
+
};
|
|
2304
|
+
/** A `wiring` entry is one of two kinds; one carrying both is an authoring mistake, never a merge. */
|
|
2305
|
+
const isWiringEntry = (entry) => {
|
|
2306
|
+
if ("contains" in entry) return nonEmpty(entry.file) && nonEmpty(entry.contains) && nonEmpty(entry.guard) && !("init" in entry) && !("marker" in entry) && !("scope" in entry);
|
|
2307
|
+
return nonEmpty(entry.init) && nonEmpty(entry.marker) && (entry.scope === "section" || entry.scope === "global") && (entry.file === void 0 || nonEmpty(entry.file));
|
|
2308
|
+
};
|
|
2309
|
+
const stringList = (source, key, value) => {
|
|
2310
|
+
if (!isStringList(value)) throw new Error(`[site-checks] ${source}: "${key}" must be an array of strings`);
|
|
2311
|
+
};
|
|
2312
|
+
const VALIDATORS = {
|
|
2313
|
+
donorTerms: stringList,
|
|
2314
|
+
optimizeDepsIgnore: stringList,
|
|
2315
|
+
imageIgnore: stringList,
|
|
2316
|
+
feedImagePatterns: (source, key, value) => {
|
|
2317
|
+
stringList(source, key, value);
|
|
2318
|
+
for (const pattern of value) compiles(source, key, pattern, "i");
|
|
2319
|
+
},
|
|
2320
|
+
listingPages: stringList,
|
|
2321
|
+
listingClientOnly: (source, key, value) => {
|
|
2322
|
+
if (!isListOf(value, (e) => isString(e.path) && isString(e.reason))) throw new Error(`[site-checks] ${source}: "${key}" must be an array of { path, reason }`);
|
|
2323
|
+
},
|
|
2324
|
+
consentAllowedHosts: stringList,
|
|
2325
|
+
bannedCopy: (source, key, value) => {
|
|
2326
|
+
if (!isListOf(value, (e) => nonEmpty(e.pattern) && nonEmpty(e.why))) throw new Error(`[site-checks] ${source}: "${key}" must be an array of { pattern, why }`);
|
|
2327
|
+
for (const { pattern } of value) compiles(source, key, pattern, "g");
|
|
2328
|
+
},
|
|
2329
|
+
copyExcludePaths: stringList,
|
|
2330
|
+
bannedCopyExcludePaths: stringList,
|
|
2331
|
+
allowDuplicateSentences: stringList,
|
|
2332
|
+
quoteSources: stringList,
|
|
2333
|
+
factCheckAccepted: stringList,
|
|
2334
|
+
wiring: (source, key, value) => {
|
|
2335
|
+
if (!isListOf(value, isWiringEntry)) throw new Error(`[site-checks] ${source}: "${key}" must be an array of { init, marker, scope: "section" | "global", file? } or { file, contains, guard } entries, each of one kind`);
|
|
2336
|
+
},
|
|
2337
|
+
structureIgnore: (source, key, value) => {
|
|
2338
|
+
stringList(source, key, value);
|
|
2339
|
+
const known = new Set(STRUCTURE_RULES);
|
|
2340
|
+
for (const rule of value) if (!known.has(rule)) throw new Error(`[site-checks] ${source}: "${key}" names an unknown rule "${rule}" (known: ${STRUCTURE_RULES.join(", ")})`);
|
|
2341
|
+
},
|
|
2342
|
+
hubFilterOptions: (source, key, value) => {
|
|
2343
|
+
if (!isObject(value)) throw new Error(`[site-checks] ${source}: "${key}" must be an object`);
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
const validate = (source, raw) => {
|
|
2347
|
+
if (!isObject(raw)) throw new Error(`[site-checks] ${source} must be a JSON object`);
|
|
2348
|
+
const known = Object.keys(VALIDATORS);
|
|
2349
|
+
const options = {};
|
|
2350
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
2351
|
+
const check = VALIDATORS[key];
|
|
2352
|
+
if (!check) throw new Error(`[site-checks] ${source}: unknown key "${key}" (known: ${known.join(", ")})`);
|
|
2353
|
+
check(source, key, value);
|
|
2354
|
+
options[key] = value;
|
|
2355
|
+
}
|
|
2356
|
+
return options;
|
|
2357
|
+
};
|
|
2358
|
+
/** The file's keys with the integration's options on top. A file that cannot be parsed throws:
|
|
2359
|
+
* a broken config must not silently disable a check. */
|
|
2360
|
+
function loadOptions(root, overrides = {}) {
|
|
2361
|
+
const file = path.join(root, CONFIG_FILE);
|
|
2362
|
+
let fromFile = {};
|
|
2363
|
+
if (fs.existsSync(file)) {
|
|
2364
|
+
let raw;
|
|
2365
|
+
try {
|
|
2366
|
+
raw = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
2367
|
+
} catch (err) {
|
|
2368
|
+
throw new Error(`[site-checks] ${CONFIG_FILE} is not valid JSON: ${err.message}`);
|
|
2369
|
+
}
|
|
2370
|
+
fromFile = validate(CONFIG_FILE, raw);
|
|
2371
|
+
}
|
|
2372
|
+
const given = validate("siteChecks() options", overrides);
|
|
2373
|
+
const pick = (key, fallback) => given[key] ?? fromFile[key] ?? fallback;
|
|
2374
|
+
return {
|
|
2375
|
+
donorTerms: pick("donorTerms", []),
|
|
2376
|
+
optimizeDepsIgnore: pick("optimizeDepsIgnore", []),
|
|
2377
|
+
imageIgnore: pick("imageIgnore", []),
|
|
2378
|
+
feedImagePatterns: pick("feedImagePatterns", DEFAULT_FEED_IMAGE_PATTERNS),
|
|
2379
|
+
listingPages: pick("listingPages", []),
|
|
2380
|
+
listingClientOnly: pick("listingClientOnly", []),
|
|
2381
|
+
consentAllowedHosts: pick("consentAllowedHosts", []),
|
|
2382
|
+
bannedCopy: pick("bannedCopy", []),
|
|
2383
|
+
copyExcludePaths: pick("copyExcludePaths", []),
|
|
2384
|
+
bannedCopyExcludePaths: pick("bannedCopyExcludePaths", []),
|
|
2385
|
+
allowDuplicateSentences: pick("allowDuplicateSentences", []),
|
|
2386
|
+
quoteSources: pick("quoteSources", []),
|
|
2387
|
+
factCheckAccepted: pick("factCheckAccepted", []),
|
|
2388
|
+
wiring: pick("wiring", []),
|
|
2389
|
+
structureIgnore: pick("structureIgnore", []),
|
|
2390
|
+
hubFilterOptions: pick("hubFilterOptions", {})
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
//#endregion
|
|
2394
|
+
//#region src/runner.ts
|
|
2395
|
+
/** Findings kept per check in the report; the rest is counted in `omitted`. */
|
|
2396
|
+
const MAX_FINDINGS_PER_CHECK = 25;
|
|
2397
|
+
/** The controller's `siteCheckReportSchema` accepts a finding message of at most 2000 characters
|
|
2398
|
+
* and a path of at most 1000, and skips a report it cannot read as a whole: one over-long finding
|
|
2399
|
+
* (a check that quotes a long URL or template expression) must not cost the whole report. */
|
|
2400
|
+
const MAX_MESSAGE_CHARS = 2e3;
|
|
2401
|
+
const MAX_PATH_CHARS = 1e3;
|
|
2402
|
+
const ELLIPSIS = "…";
|
|
2403
|
+
const clip = (text, max) => text.length > max ? text.slice(0, max - 1) + ELLIPSIS : text;
|
|
2404
|
+
const bounded = (finding, title) => {
|
|
2405
|
+
const message = clip(finding.message.trim() || title, MAX_MESSAGE_CHARS);
|
|
2406
|
+
return finding.path === void 0 ? { message } : {
|
|
2407
|
+
message,
|
|
2408
|
+
path: clip(finding.path, MAX_PATH_CHARS)
|
|
2409
|
+
};
|
|
2410
|
+
};
|
|
2411
|
+
const errorMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
2412
|
+
const failed = (check, message) => ({
|
|
2413
|
+
id: check.id,
|
|
2414
|
+
status: "failed",
|
|
2415
|
+
findings: [bounded({ message }, check.title)],
|
|
2416
|
+
omitted: 0
|
|
2417
|
+
});
|
|
2418
|
+
const broken = (check, err) => failed(check, `The check itself failed: ${errorMessage(err)}`);
|
|
2419
|
+
const unreadable = (check, err) => failed(check, `The build output could not be read: ${errorMessage(err)}`);
|
|
2420
|
+
const finish = async (check, run) => {
|
|
2421
|
+
try {
|
|
2422
|
+
const findings = await run.finish();
|
|
2423
|
+
return {
|
|
2424
|
+
id: check.id,
|
|
2425
|
+
status: findings.length === 0 ? "ok" : check.severity,
|
|
2426
|
+
findings: findings.slice(0, 25).map((f) => bounded(f, check.title)),
|
|
2427
|
+
omitted: Math.max(0, findings.length - 25)
|
|
2428
|
+
};
|
|
2429
|
+
} catch (err) {
|
|
2430
|
+
return broken(check, err);
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
/** Runs every check of `list` over the context `load` returns. Never throws: a check that throws
|
|
2434
|
+
* is a `failed` result, a context that cannot be loaded fails every check the same way. The HTML
|
|
2435
|
+
* pages are parsed one at a time and shown to every check before the next one is read. */
|
|
2436
|
+
const runChecks = async (load, list) => {
|
|
2437
|
+
const started = Date.now();
|
|
2438
|
+
const ranAt = new Date(started).toISOString();
|
|
2439
|
+
let ctx;
|
|
2440
|
+
try {
|
|
2441
|
+
ctx = load();
|
|
2442
|
+
} catch (err) {
|
|
2443
|
+
return {
|
|
2444
|
+
ranAt,
|
|
2445
|
+
durationMs: Date.now() - started,
|
|
2446
|
+
results: list.map((check) => unreadable(check, err))
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
const results = /* @__PURE__ */ new Map();
|
|
2450
|
+
const runs = /* @__PURE__ */ new Map();
|
|
2451
|
+
for (const check of list) try {
|
|
2452
|
+
const run = check.begin(ctx);
|
|
2453
|
+
if (run) runs.set(check, run);
|
|
2454
|
+
else results.set(check, {
|
|
2455
|
+
id: check.id,
|
|
2456
|
+
status: "skipped",
|
|
2457
|
+
findings: [],
|
|
2458
|
+
omitted: 0
|
|
2459
|
+
});
|
|
2460
|
+
} catch (err) {
|
|
2461
|
+
results.set(check, broken(check, err));
|
|
2462
|
+
}
|
|
2463
|
+
for (const file of ctx.files) {
|
|
2464
|
+
if (!file.endsWith(".html")) continue;
|
|
2465
|
+
const visiting = [...runs].filter(([, run]) => run.visit);
|
|
2466
|
+
if (visiting.length === 0) break;
|
|
2467
|
+
let page;
|
|
2468
|
+
try {
|
|
2469
|
+
page = readPage(ctx, file);
|
|
2470
|
+
} catch (err) {
|
|
2471
|
+
for (const [check] of visiting) {
|
|
2472
|
+
runs.delete(check);
|
|
2473
|
+
results.set(check, unreadable(check, err));
|
|
2474
|
+
}
|
|
2475
|
+
break;
|
|
2476
|
+
}
|
|
2477
|
+
for (const [check, run] of visiting) try {
|
|
2478
|
+
run.visit?.(page);
|
|
2479
|
+
} catch (err) {
|
|
2480
|
+
runs.delete(check);
|
|
2481
|
+
results.set(check, broken(check, err));
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
for (const [check, run] of runs) results.set(check, await finish(check, run));
|
|
2485
|
+
return {
|
|
2486
|
+
ranAt,
|
|
2487
|
+
durationMs: Date.now() - started,
|
|
2488
|
+
results: list.map((check) => results.get(check))
|
|
2489
|
+
};
|
|
2490
|
+
};
|
|
2491
|
+
/** Runs every site check over the project and its build. */
|
|
2492
|
+
const runSiteChecks = (input, list = checks) => runChecks(() => loadContext({
|
|
2493
|
+
root: input.root,
|
|
2494
|
+
srcDir: input.srcDir ?? `${input.root}/src`,
|
|
2495
|
+
publicDir: input.publicDir ?? `${input.root}/public`,
|
|
2496
|
+
distDir: input.distDir,
|
|
2497
|
+
config: {
|
|
2498
|
+
site: input.config?.site,
|
|
2499
|
+
optimizeDepsInclude: input.config?.optimizeDepsInclude ?? [],
|
|
2500
|
+
trailingSlash: input.config?.trailingSlash
|
|
2501
|
+
},
|
|
2502
|
+
options: loadOptions(input.root, input.options)
|
|
2503
|
+
}), list);
|
|
2504
|
+
/** Results with status `error`: the only ones that refuse a build. */
|
|
2505
|
+
const blockingResults = (report) => report.results.filter((r) => r.status === "error");
|
|
2506
|
+
//#endregion
|
|
2507
|
+
//#region src/report.ts
|
|
2508
|
+
/** The report's file name under `dist/`. The build worker reads it after `astro build`, merges it
|
|
2509
|
+
* with its own checks and never uploads it (it names source paths and configured terms). */
|
|
2510
|
+
const SITE_CHECKS_FILE = "site-checks.json";
|
|
2511
|
+
const writeSiteChecksReport = (distDir, report) => {
|
|
2512
|
+
fs.mkdirSync(distDir, { recursive: true });
|
|
2513
|
+
fs.writeFileSync(path.join(distDir, SITE_CHECKS_FILE), JSON.stringify(report, null, 2) + "\n");
|
|
2514
|
+
};
|
|
2515
|
+
const count = (result) => result.findings.length + result.omitted;
|
|
2516
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
2517
|
+
const line = (finding) => finding.path ? `${finding.path}: ${finding.message}` : finding.message;
|
|
2518
|
+
/** One line per check that found something or could not run, for the build log. */
|
|
2519
|
+
const summaryLines = (report) => report.results.filter((r) => r.status !== "ok" && r.status !== "skipped").map((r) => `[site-checks] ${r.id}: ${r.status}, ${plural(count(r), "finding")}`);
|
|
2520
|
+
/** The error `astro build` ends with when a check refuses: every failing check, its first findings,
|
|
2521
|
+
* and where the whole report is. */
|
|
2522
|
+
const refusalMessage = (report) => {
|
|
2523
|
+
const blocking = blockingResults(report);
|
|
2524
|
+
const lines = [`[site-checks] build refused: ${plural(blocking.length, "check")} with errors`];
|
|
2525
|
+
for (const result of blocking) {
|
|
2526
|
+
const shown = result.findings.slice(0, 3);
|
|
2527
|
+
const more = count(result) - shown.length;
|
|
2528
|
+
lines.push(` - ${result.id} (${plural(count(result), "finding")})`);
|
|
2529
|
+
for (const finding of shown) lines.push(` ${line(finding)}`);
|
|
2530
|
+
if (more > 0) lines.push(` (+${more} more)`);
|
|
2531
|
+
}
|
|
2532
|
+
lines.push(` Report: dist/${SITE_CHECKS_FILE}`);
|
|
2533
|
+
return lines.join("\n");
|
|
2534
|
+
};
|
|
2535
|
+
/** One line naming what refused the build, for the studio: the failing checks and their counts. */
|
|
2536
|
+
const summarizeBlocking = (report) => "Checks refused the build: " + blockingResults(report).map((r) => `${r.id} (${plural(count(r), "finding")})`).join(", ");
|
|
2537
|
+
//#endregion
|
|
2538
|
+
export { referencedUrls as _, writeSiteChecksReport as a, MAX_PATH_CHARS as c, runSiteChecks as d, CONFIG_FILE as f, loadDistContext as g, isSameSiteReference as h, summaryLines as i, blockingResults as l, checks as m, refusalMessage as n, MAX_FINDINGS_PER_CHECK as o, loadOptions as p, summarizeBlocking as r, MAX_MESSAGE_CHARS as s, SITE_CHECKS_FILE as t, runChecks as u, resolveReference as v, xmlText as y };
|