@v-office/site-checks 0.4.2 → 0.5.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 +92 -56
- package/dist/bin.mjs +1 -1
- package/dist/{cli-AmQJK-Qj.mjs → cli-ChBTZhc7.mjs} +1994 -730
- package/dist/index.d.mts +22 -2
- package/dist/index.mjs +1 -1
- package/instructions/CHANGELOG.md +1 -0
- package/instructions/MIGRATION.md +1 -0
- package/instructions/versions/0.5.0/CHANGELOG.md +114 -0
- package/instructions/versions/0.5.0/MIGRATION.md +74 -0
- package/package.json +1 -1
|
@@ -55,60 +55,121 @@ const regexEnd = (text, start) => {
|
|
|
55
55
|
}
|
|
56
56
|
return start + 1;
|
|
57
57
|
};
|
|
58
|
-
/**
|
|
59
|
-
|
|
58
|
+
/** A tag's head: `<` and its name with any type arguments (`<Panel<string>`, `<Table<Row<Id>>`), or
|
|
59
|
+
* the `<` of a fragment `<>`. Consumed whole, so a type argument's `>` does not end the tag. */
|
|
60
|
+
const TAG_HEAD = /^<(?:(?=>)|[A-Za-z][\w.:-]*(?:<(?:[^<>]|<[^<>]*>)*>)?(?=[\s/>]))/;
|
|
61
|
+
/** A generic in a `.tsx` file (`<T,>`, `<T extends X>`): code, never a tag. */
|
|
62
|
+
const GENERIC = /^<[A-Za-z][\w.]*\s*(?:,|extends\b)/;
|
|
63
|
+
/** The length of the tag head at `at`, or 0 where none starts. */
|
|
64
|
+
const tagHead = (text, at) => {
|
|
65
|
+
const ahead = text.slice(at, at + 200);
|
|
66
|
+
return GENERIC.test(ahead) ? 0 : TAG_HEAD.exec(ahead)?.[0].length ?? 0;
|
|
67
|
+
};
|
|
68
|
+
/** Every comment in the text, in order, with its position. Everything else is code, as written.
|
|
69
|
+
* With `jsx`, JSX is followed as the TSX parser does: an element's children are text across any
|
|
70
|
+
* number of lines (`https://…` in them is no comment), its `{…}` are code, and an attribute's
|
|
71
|
+
* quoted value is a string. */
|
|
72
|
+
const findComments = (text, { jsx = false } = {}) => {
|
|
60
73
|
const comments = [];
|
|
61
74
|
let i = 0;
|
|
62
75
|
const n = text.length;
|
|
63
|
-
const
|
|
76
|
+
const frames = [];
|
|
64
77
|
let depth = 0;
|
|
78
|
+
/** A comment starting at `i`: recorded, and its end returned; else -1. */
|
|
79
|
+
const comment = () => {
|
|
80
|
+
if (text[i] !== "/") return -1;
|
|
81
|
+
let end;
|
|
82
|
+
if (text[i + 1] === "/") {
|
|
83
|
+
LINE_END.lastIndex = i;
|
|
84
|
+
end = LINE_END.exec(text)?.index ?? n;
|
|
85
|
+
} else if (text[i + 1] === "*") {
|
|
86
|
+
const close = text.indexOf("*/", i + 2);
|
|
87
|
+
end = close === -1 ? n : close + 2;
|
|
88
|
+
} else return -1;
|
|
89
|
+
comments.push({
|
|
90
|
+
start: i,
|
|
91
|
+
end,
|
|
92
|
+
text: text.slice(i, end)
|
|
93
|
+
});
|
|
94
|
+
return end;
|
|
95
|
+
};
|
|
96
|
+
/** A `{` (or `${`) of the innermost frame: code until its matching `}`. */
|
|
97
|
+
const openCode = (frame, width) => {
|
|
98
|
+
frame.code = depth;
|
|
99
|
+
depth += 1;
|
|
100
|
+
i += width;
|
|
101
|
+
};
|
|
65
102
|
while (i < n) {
|
|
66
103
|
const c = text[i];
|
|
67
|
-
|
|
104
|
+
const frame = frames.at(-1);
|
|
105
|
+
if (frame?.code === -1 && frame.kind === "template") {
|
|
68
106
|
if (c === "\\") i += 2;
|
|
69
107
|
else if (c === "`") {
|
|
70
|
-
|
|
108
|
+
frames.pop();
|
|
71
109
|
i += 1;
|
|
72
|
-
} else if (c === "$" && text[i + 1] === "{")
|
|
73
|
-
|
|
74
|
-
|
|
110
|
+
} else if (c === "$" && text[i + 1] === "{") openCode(frame, 2);
|
|
111
|
+
else i += 1;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (frame?.code === -1 && frame.kind === "children") {
|
|
115
|
+
if (c === "{") openCode(frame, 1);
|
|
116
|
+
else if (c === "<") {
|
|
117
|
+
const closing = text[i + 1] === "/";
|
|
118
|
+
frames.push({
|
|
119
|
+
kind: closing ? "closing" : "tag",
|
|
120
|
+
code: -1
|
|
121
|
+
});
|
|
122
|
+
i += closing ? 2 : Math.max(1, tagHead(text, i));
|
|
123
|
+
} else i += 1;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (frame?.code === -1) {
|
|
127
|
+
const end = comment();
|
|
128
|
+
if (end !== -1) i = end;
|
|
129
|
+
else if (c === "\"" || c === "'") {
|
|
130
|
+
const close = text.indexOf(c, i + 1);
|
|
131
|
+
i = close === -1 ? n : close + 1;
|
|
132
|
+
} else if (c === "{") openCode(frame, 1);
|
|
133
|
+
else if (c === "/" && text[i + 1] === ">") {
|
|
134
|
+
frames.pop();
|
|
75
135
|
i += 2;
|
|
136
|
+
} else if (c === ">") {
|
|
137
|
+
frames.pop();
|
|
138
|
+
if (frame.kind === "tag") frames.push({
|
|
139
|
+
kind: "children",
|
|
140
|
+
code: -1
|
|
141
|
+
});
|
|
142
|
+
else if (frames.at(-1)?.kind === "children") frames.pop();
|
|
143
|
+
i += 1;
|
|
76
144
|
} else i += 1;
|
|
77
145
|
continue;
|
|
78
146
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
comments.push({
|
|
84
|
-
start: i,
|
|
85
|
-
end,
|
|
86
|
-
text: text.slice(i, end)
|
|
87
|
-
});
|
|
88
|
-
i = end;
|
|
89
|
-
} else if (c === "/" && text[i + 1] === "*") {
|
|
90
|
-
const close = text.indexOf("*/", i + 2);
|
|
91
|
-
const end = close === -1 ? n : close + 2;
|
|
92
|
-
comments.push({
|
|
93
|
-
start: i,
|
|
94
|
-
end,
|
|
95
|
-
text: text.slice(i, end)
|
|
96
|
-
});
|
|
97
|
-
i = end;
|
|
98
|
-
} else if (c === "/" && startsRegex(text, i, comments)) i = regexEnd(text, i);
|
|
147
|
+
const end = comment();
|
|
148
|
+
if (end !== -1) i = end;
|
|
149
|
+
else if (c === "\\") i += 2;
|
|
150
|
+
else if (c === "/" && startsRegex(text, i, comments)) i = regexEnd(text, i);
|
|
99
151
|
else if (c === "'" || c === "\"") {
|
|
100
152
|
let j = i + 1;
|
|
101
153
|
while (j < n && text[j] !== c && text[j] !== "\n") j += text[j] === "\\" ? 2 : 1;
|
|
102
154
|
if (j < n && text[j] === c) j += 1;
|
|
103
155
|
i = j;
|
|
104
156
|
} else if (c === "`") {
|
|
105
|
-
|
|
157
|
+
frames.push({
|
|
158
|
+
kind: "template",
|
|
159
|
+
code: -1
|
|
160
|
+
});
|
|
106
161
|
i += 1;
|
|
162
|
+
} else if (jsx && c === "<" && tagHead(text, i) > 0 && startsRegex(text, i, comments)) {
|
|
163
|
+
frames.push({
|
|
164
|
+
kind: "tag",
|
|
165
|
+
code: -1
|
|
166
|
+
});
|
|
167
|
+
i += tagHead(text, i);
|
|
107
168
|
} else {
|
|
108
169
|
if (c === "{") depth += 1;
|
|
109
170
|
else if (c === "}") {
|
|
110
171
|
depth -= 1;
|
|
111
|
-
if (
|
|
172
|
+
if (frame?.code === depth) frame.code = -1;
|
|
112
173
|
}
|
|
113
174
|
i += 1;
|
|
114
175
|
}
|
|
@@ -117,17 +178,17 @@ const findComments = (text) => {
|
|
|
117
178
|
};
|
|
118
179
|
/** The text with its comments blanked: a line comment becomes a space, a block comment a space
|
|
119
180
|
* and its newlines. */
|
|
120
|
-
const stripComments = (text) => {
|
|
181
|
+
const stripComments = (text, options = {}) => {
|
|
121
182
|
let out = "";
|
|
122
183
|
let from = 0;
|
|
123
|
-
for (const { start, end, text: comment } of findComments(text)) {
|
|
184
|
+
for (const { start, end, text: comment } of findComments(text, options)) {
|
|
124
185
|
out += `${text.slice(from, start)} ${"\n".repeat((comment.match(/\n/g) ?? []).length)}`;
|
|
125
186
|
from = end;
|
|
126
187
|
}
|
|
127
188
|
return out + text.slice(from);
|
|
128
189
|
};
|
|
129
190
|
/** Every comment in the text, as written. */
|
|
130
|
-
const jsComments = (text) => findComments(text).map((c) => c.text);
|
|
191
|
+
const jsComments = (text, options = {}) => findComments(text, options).map((c) => c.text);
|
|
131
192
|
//#endregion
|
|
132
193
|
//#region src/astroConfig.ts
|
|
133
194
|
/** The Astro config files, in the order Astro itself looks for them. */
|
|
@@ -206,6 +267,42 @@ const readAstroConfig = (root) => {
|
|
|
206
267
|
};
|
|
207
268
|
};
|
|
208
269
|
//#endregion
|
|
270
|
+
//#region src/sourceComments.ts
|
|
271
|
+
/** Files of code only, read by the string-aware JavaScript lexer: no text runs between their
|
|
272
|
+
* tokens, so a `//` outside a string always opens a comment. */
|
|
273
|
+
const CODE = /* @__PURE__ */ new Set([
|
|
274
|
+
".ts",
|
|
275
|
+
".js",
|
|
276
|
+
".mjs",
|
|
277
|
+
".cjs",
|
|
278
|
+
".mts",
|
|
279
|
+
".cts"
|
|
280
|
+
]);
|
|
281
|
+
/** Files where JSX markup runs as text between the code: there `//` is text („https://…",
|
|
282
|
+
* „Strand // mehr"), while a quoted attribute value (`accept="image/*"`) is a string. The lexer
|
|
283
|
+
* follows the elements (`stripComments(…, { jsx: true })`). */
|
|
284
|
+
const JSX = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
285
|
+
const blank = (text) => text.replace(/[^\n]/g, " ");
|
|
286
|
+
const htmlComments$1 = (text) => text.replace(/<!--[\s\S]*?-->/g, blank);
|
|
287
|
+
const inScripts = (text) => text.replace(/(<script\b[^>]*>)([\s\S]*?)(<\/script\s*>)/gi, (_, open, code, close) => open + stripComments(code) + close);
|
|
288
|
+
/** A source file with its comments blanked, line breaks kept so a line number still points at
|
|
289
|
+
* its line, and nothing of what renders blanked with them:
|
|
290
|
+
* - code (`.ts`, `.js`, …): every comment, strings kept whole;
|
|
291
|
+
* - JSX (`.tsx`, `.jsx`): every comment, strings and attribute values kept whole, never a `//`
|
|
292
|
+
* in the markup's text;
|
|
293
|
+
* - Astro: its frontmatter and `<script>` blocks as code, the `{/* … *\/}` and `<!-- … -->` of its
|
|
294
|
+
* markup;
|
|
295
|
+
* - HTML: its `<script>` blocks as code and its `<!-- … -->`; MDX and Markdown: `{/* … *\/}` and
|
|
296
|
+
* `<!-- … -->`. JSON and YAML hold none. */
|
|
297
|
+
const blankSourceComments = (raw, extension) => {
|
|
298
|
+
if (CODE.has(extension)) return stripComments(raw);
|
|
299
|
+
if (JSX.has(extension)) return stripComments(htmlComments$1(raw), { jsx: true });
|
|
300
|
+
if (extension === ".astro") return htmlComments$1(inScripts(raw.replace(/^---\r?\n[\s\S]*?\r?\n---/, (frontmatter) => stripComments(frontmatter))).replace(/\{\s*\/\*[\s\S]*?\*\/\s*\}/g, blank));
|
|
301
|
+
if (extension === ".html") return htmlComments$1(inScripts(raw));
|
|
302
|
+
if (extension === ".mdx" || extension === ".md") return htmlComments$1(raw.replace(/\{\s*\/\*[\s\S]*?\*\/\s*\}/g, blank));
|
|
303
|
+
return raw;
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
209
306
|
//#region src/checks/consentGate.ts
|
|
210
307
|
/** The consent kit's files in a site: its presence under `src/lib/consent/` is what makes the
|
|
211
308
|
* check apply; the vendors the site enables and the fleet registry's review of them. */
|
|
@@ -222,6 +319,53 @@ const hostOf = (url) => {
|
|
|
222
319
|
return;
|
|
223
320
|
}
|
|
224
321
|
};
|
|
322
|
+
const LEAK_FIX = "Frame it with ConsentEmbed, or register the vendor so the kit injects it after consent; list a consent-free host in consentAllowedHosts.";
|
|
323
|
+
/** The project's sources by their project-relative path, or `null` without the consent kit. */
|
|
324
|
+
const kitSources = (ctx) => {
|
|
325
|
+
const sources = ctx.sourceFiles(/* @__PURE__ */ new Set([".ts", ".json"]));
|
|
326
|
+
const byRel = new Map(sources.map((file) => [ctx.rel(file), file]));
|
|
327
|
+
return [...byRel.keys()].some((rel) => rel.startsWith(KIT_DIR)) ? byRel : null;
|
|
328
|
+
};
|
|
329
|
+
/** Each vendor the site enables, against the fleet registry's review. What cannot be read is a
|
|
330
|
+
* finding, never a pass: a list the check cannot read, or a registry that does not parse, would
|
|
331
|
+
* otherwise approve every vendor in it. */
|
|
332
|
+
const vendorFindings = (ctx, byRel) => {
|
|
333
|
+
const enabledFile = byRel.get(ENABLED_FILE);
|
|
334
|
+
const registryFile = byRel.get(REGISTRY_FILE);
|
|
335
|
+
if (!enabledFile || !registryFile) return [];
|
|
336
|
+
const enabled = stripComments(ctx.readSource(enabledFile)).match(/ENABLED_VENDOR_IDS\b[^=]*=\s*\[([^\]]*)\]/)?.[1];
|
|
337
|
+
const rest = enabled?.replace(/(["'`])[^"'`]*\1/g, "").replace(/[\s,]/g, "");
|
|
338
|
+
if (enabled === void 0 || rest) return [{
|
|
339
|
+
path: ENABLED_FILE,
|
|
340
|
+
message: "ENABLED_VENDOR_IDS is not an array literal of quoted ids, so the enabled vendors could not be checked against the consent registry. Write it as ENABLED_VENDOR_IDS = [\"…\", …]."
|
|
341
|
+
}];
|
|
342
|
+
const ids = [...enabled.matchAll(/["'`]([^"'`]+)["'`]/g)].map((m) => m[1]);
|
|
343
|
+
let registry;
|
|
344
|
+
try {
|
|
345
|
+
registry = JSON.parse(ctx.readSource(registryFile));
|
|
346
|
+
} catch (err) {
|
|
347
|
+
return [{
|
|
348
|
+
path: REGISTRY_FILE,
|
|
349
|
+
message: `The consent registry snapshot is not valid JSON (${err.message}), so the enabled vendors could not be checked. Restore it from the registry.`
|
|
350
|
+
}];
|
|
351
|
+
}
|
|
352
|
+
const vendors = registry?.vendors;
|
|
353
|
+
if (!Array.isArray(vendors)) return [{
|
|
354
|
+
path: REGISTRY_FILE,
|
|
355
|
+
message: "The consent registry snapshot has no vendors array, so the enabled vendors could not be checked. Restore it from the registry."
|
|
356
|
+
}];
|
|
357
|
+
const status = new Map(vendors.map((v) => [v?.id, v?.reviewStatus]));
|
|
358
|
+
const findings = [];
|
|
359
|
+
for (const id of ids) if (!status.has(id)) findings.push({
|
|
360
|
+
path: ENABLED_FILE,
|
|
361
|
+
message: `The enabled vendor "${id}" is not in the consent registry.`
|
|
362
|
+
});
|
|
363
|
+
else if (status.get(id) !== "approved") findings.push({
|
|
364
|
+
path: ENABLED_FILE,
|
|
365
|
+
message: `The enabled vendor "${id}" is "${String(status.get(id))}" in the consent registry, not approved.`
|
|
366
|
+
});
|
|
367
|
+
return findings;
|
|
368
|
+
};
|
|
225
369
|
/** No third-party script or iframe loads outside the consent layer (the kit injects a vendor's
|
|
226
370
|
* script after consent, so one in the HTML loads before it), and no vendor the site enables is
|
|
227
371
|
* still unapproved in the fleet's consent registry. Skipped in a project without the kit. The
|
|
@@ -233,9 +377,8 @@ const consentGate = {
|
|
|
233
377
|
severity: "error",
|
|
234
378
|
stage: "dist",
|
|
235
379
|
begin: (ctx) => {
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
if (![...byRel.keys()].some((rel) => rel.startsWith(KIT_DIR))) return null;
|
|
380
|
+
const byRel = kitSources(ctx);
|
|
381
|
+
if (!byRel) return null;
|
|
239
382
|
const siteHost = ctx.config.site ? hostOf(ctx.config.site) : void 0;
|
|
240
383
|
const allowed = new Set(ctx.options.consentAllowedHosts);
|
|
241
384
|
const findings = [];
|
|
@@ -251,32 +394,69 @@ const consentGate = {
|
|
|
251
394
|
if (el.closest(EMBED_TEMPLATE)) continue;
|
|
252
395
|
findings.push({
|
|
253
396
|
path: page.path,
|
|
254
|
-
message: `A third-party <${el.tagName.toLowerCase()}> from ${host} loads before consent.
|
|
397
|
+
message: `A third-party <${el.tagName.toLowerCase()}> from ${host} loads before consent. ${LEAK_FIX}`
|
|
255
398
|
});
|
|
256
399
|
}
|
|
257
400
|
},
|
|
258
|
-
finish: () =>
|
|
259
|
-
const enabledFile = byRel.get(ENABLED_FILE);
|
|
260
|
-
const registryFile = byRel.get(REGISTRY_FILE);
|
|
261
|
-
if (!enabledFile || !registryFile) return findings;
|
|
262
|
-
const enabled = ctx.readSource(enabledFile).match(/ENABLED_VENDOR_IDS\b[^=]*=\s*\[([^\]]*)\]/);
|
|
263
|
-
if (!enabled) return findings;
|
|
264
|
-
const ids = [...enabled[1].matchAll(/["'`]([^"'`]+)["'`]/g)].map((m) => m[1]);
|
|
265
|
-
const registry = JSON.parse(ctx.readSource(registryFile));
|
|
266
|
-
const status = new Map((registry.vendors ?? []).map((v) => [v.id, v.reviewStatus]));
|
|
267
|
-
for (const id of ids) if (!status.has(id)) findings.push({
|
|
268
|
-
path: ENABLED_FILE,
|
|
269
|
-
message: `The enabled vendor "${id}" is not in the consent registry.`
|
|
270
|
-
});
|
|
271
|
-
else if (status.get(id) !== "approved") findings.push({
|
|
272
|
-
path: ENABLED_FILE,
|
|
273
|
-
message: `The enabled vendor "${id}" is "${status.get(id)}" in the consent registry, not approved.`
|
|
274
|
-
});
|
|
275
|
-
return findings;
|
|
276
|
-
}
|
|
401
|
+
finish: () => [...findings, ...vendorFindings(ctx, byRel)]
|
|
277
402
|
};
|
|
278
403
|
}
|
|
279
404
|
};
|
|
405
|
+
/** The site's own markup, where an island rendered only in the browser (`client:only`) writes the
|
|
406
|
+
* tags the built HTML never shows. */
|
|
407
|
+
const MARKUP = /* @__PURE__ */ new Set([
|
|
408
|
+
".astro",
|
|
409
|
+
".tsx",
|
|
410
|
+
".jsx",
|
|
411
|
+
".html",
|
|
412
|
+
".mdx"
|
|
413
|
+
]);
|
|
414
|
+
/** The consent layer: the kit's components (ConsentEmbed's template frame, the gated loaders) and
|
|
415
|
+
* its library inject vendors after consent. */
|
|
416
|
+
const CONSENT_LAYER = ["src/components/consent/", KIT_DIR];
|
|
417
|
+
/** ConsentEmbed's click-to-load frame written out in a page: loaded after consent. */
|
|
418
|
+
const EMBED_TEMPLATE_SOURCE = /<template\b[^>]*\bdata-embed-content\b[^>]*>[\s\S]*?<\/template\s*>/gi;
|
|
419
|
+
/** A `<script>` or `<iframe>` whose `src` is an absolute or protocol-relative URL: quoted, or a
|
|
420
|
+
* string in a JSX expression. The tag may span lines. */
|
|
421
|
+
const VENDOR_TAG = /<(script|iframe)\b[^>]*?\ssrc\s*=\s*\{?\s*(["'`])\s*((?:https?:)?\/\/[^"'`\s>]+)/gi;
|
|
422
|
+
/** No third-party `<script src>` or `<iframe src>` in the site's own markup outside the consent
|
|
423
|
+
* layer: the dist stage sees only what the built HTML holds, and a component rendered in the
|
|
424
|
+
* browser (a `client:only` island, a video player in TSX) loads its vendor all the same. A tag in
|
|
425
|
+
* a comment renders nothing and is not read. The site's own host and `consentAllowedHosts` are
|
|
426
|
+
* allowed. Skipped without the kit, and without a known site host (a computed `site`, no
|
|
427
|
+
* `--site`): the site's own absolute URLs would read as third-party, as the dist half waits too. */
|
|
428
|
+
const consentGateSource = {
|
|
429
|
+
id: "consent-gate-source",
|
|
430
|
+
title: "Third-party resources in the site's markup wait for consent",
|
|
431
|
+
severity: "error",
|
|
432
|
+
stage: "src",
|
|
433
|
+
begin: (ctx) => {
|
|
434
|
+
const siteHost = ctx.config.site ? hostOf(ctx.config.site) : void 0;
|
|
435
|
+
if (!kitSources(ctx) || !siteHost) return null;
|
|
436
|
+
const allowed = new Set(ctx.options.consentAllowedHosts);
|
|
437
|
+
return { finish: () => {
|
|
438
|
+
const findings = [];
|
|
439
|
+
for (const file of ctx.sourceFiles(MARKUP)) {
|
|
440
|
+
const rel = ctx.rel(file);
|
|
441
|
+
if (CONSENT_LAYER.some((dir) => rel.startsWith(dir))) continue;
|
|
442
|
+
const blank = (block) => block.replace(/[^\n]/g, " ");
|
|
443
|
+
const text = blankSourceComments(ctx.readSource(file), path.extname(file).toLowerCase()).replace(EMBED_TEMPLATE_SOURCE, blank);
|
|
444
|
+
for (const match of text.matchAll(VENDOR_TAG)) {
|
|
445
|
+
const url = match[3];
|
|
446
|
+
const absolute = url.startsWith("//") ? `https:${url}` : url;
|
|
447
|
+
const host = hostOf(absolute) ?? absolute.replace(/^https?:\/\//i, "").split("/")[0];
|
|
448
|
+
if (host === siteHost || allowed.has(host)) continue;
|
|
449
|
+
const line = text.slice(0, match.index).split("\n").length;
|
|
450
|
+
findings.push({
|
|
451
|
+
path: rel,
|
|
452
|
+
message: `A third-party <${match[1].toLowerCase()}> from ${host} (line ${line}) loads before consent. ${LEAK_FIX}`
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return findings;
|
|
457
|
+
} };
|
|
458
|
+
}
|
|
459
|
+
};
|
|
280
460
|
//#endregion
|
|
281
461
|
//#region src/context.ts
|
|
282
462
|
const SKIPPED_TEXT_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -289,13 +469,15 @@ const collectFiles = (dir, base = dir) => fs.readdirSync(dir, { withFileTypes: t
|
|
|
289
469
|
const full = path.join(dir, entry.name);
|
|
290
470
|
return entry.isDirectory() ? collectFiles(full, base) : [path.relative(base, full).split(path.sep).join("/")];
|
|
291
471
|
});
|
|
472
|
+
/** The files under `dir`, `node_modules` left out: those with one of the extensions, or every
|
|
473
|
+
* file without any. */
|
|
292
474
|
function* filesUnder(dir, extensions) {
|
|
293
475
|
if (!fs.existsSync(dir)) return;
|
|
294
476
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
295
477
|
const full = path.join(dir, entry.name);
|
|
296
478
|
if (entry.isDirectory()) {
|
|
297
479
|
if (entry.name !== "node_modules") yield* filesUnder(full, extensions);
|
|
298
|
-
} else if (extensions.has(path.extname(entry.name).toLowerCase())) yield full;
|
|
480
|
+
} else if (!extensions || extensions.has(path.extname(entry.name).toLowerCase())) yield full;
|
|
299
481
|
}
|
|
300
482
|
}
|
|
301
483
|
/** `about-us/index.html` → `/about-us/`, `imprint.html` → `/imprint`, `index.html` → `/`. */
|
|
@@ -434,12 +616,23 @@ const readPage = (ctx, file) => {
|
|
|
434
616
|
comments: () => {
|
|
435
617
|
if (comments === void 0) {
|
|
436
618
|
comments = [];
|
|
437
|
-
|
|
619
|
+
commentsOf(document, comments);
|
|
438
620
|
}
|
|
439
621
|
return comments;
|
|
440
622
|
}
|
|
441
623
|
};
|
|
442
624
|
};
|
|
625
|
+
/** A status page (`/404`, `/500`, or one under a locale prefix, `/en/404/`): served for an error,
|
|
626
|
+
* never a page a search engine should list. */
|
|
627
|
+
const STATUS_PAGE = /(?:^|\/)(?:404|500)\/?$/;
|
|
628
|
+
/** A page a search engine may index and someone reads: not noindex, not a redirect stub, not a
|
|
629
|
+
* status page. The launch signal of every check that waits for the launch: before it, the
|
|
630
|
+
* preview's blanket robots meta makes every page noindex, while the 404 page often has none. */
|
|
631
|
+
const isIndexable = (page) => !page.redirect && !page.noindex && !STATUS_PAGE.test(page.url);
|
|
632
|
+
/** A rental's page: the rental blocks' fact row (`data-rental-stats`), or a site's own chip row
|
|
633
|
+
* (`data-rental-facts`) beside the owner's description. A listing's cards carry chip rows too, but
|
|
634
|
+
* no description, so they never make the listing a rental page. */
|
|
635
|
+
const isRentalPage = (document) => !!document.querySelector("[data-rental-stats]") || !!document.querySelector("[data-rental-facts]") && !!document.querySelector("[data-rental-description]");
|
|
443
636
|
/** Elements that start a new line of text: their text never runs into the text beside them. */
|
|
444
637
|
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(" "));
|
|
445
638
|
/** An element's readable text, whitespace collapsed: a space at every block boundary, so
|
|
@@ -551,9 +744,9 @@ const assertKnownChecks = (exclude, ids) => {
|
|
|
551
744
|
* entry covers the path and everything below it, with or without a locale prefix: `/impressum`
|
|
552
745
|
* also covers `/de/impressum`. */
|
|
553
746
|
const excluded = (page, paths) => page.redirect || page.path === "404.html" || paths.some((entry) => coversUrl(entry, page.url));
|
|
554
|
-
const excerpt$
|
|
747
|
+
const excerpt$3 = (text, max = 90) => text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
555
748
|
/** Quotes and whitespace removed, lower-cased: two renderings of one sentence compare equal. */
|
|
556
|
-
const normalize$
|
|
749
|
+
const normalize$2 = (text) => text.toLowerCase().replace(/[„“”"‚’'«»]/g, "").replace(/\s+/g, " ").trim();
|
|
557
750
|
const SKIPPED = /* @__PURE__ */ new Set([
|
|
558
751
|
"SCRIPT",
|
|
559
752
|
"STYLE",
|
|
@@ -612,19 +805,20 @@ const sentencesOf = (blocks) => blocks.flatMap((block) => {
|
|
|
612
805
|
const MIN_SENTENCE = 25;
|
|
613
806
|
/** Wordings a recorded customer correction bans, found in the rendered text of a page. A warning:
|
|
614
807
|
* the rendered text includes the feed's descriptions, and an owner's new wording must not stop the
|
|
615
|
-
* nightly builds.
|
|
808
|
+
* nightly builds. A ban scoped `"in": "src"` is the site's own text only: `banned-copy-src` reads
|
|
809
|
+
* it in `src/`, this check never. */
|
|
616
810
|
const bannedCopy = {
|
|
617
811
|
id: "banned-copy",
|
|
618
812
|
title: "Wordings banned by a recorded correction",
|
|
619
813
|
severity: "warning",
|
|
620
814
|
stage: "dist",
|
|
621
815
|
begin: (ctx) => {
|
|
622
|
-
|
|
623
|
-
const skip = [...ctx.options.copyExcludePaths, ...ctx.options.bannedCopyExcludePaths];
|
|
624
|
-
const bans = ctx.options.bannedCopy.map((ban) => ({
|
|
816
|
+
const bans = ctx.options.bannedCopy.filter((ban) => ban.in !== "src").map((ban) => ({
|
|
625
817
|
...ban,
|
|
626
818
|
re: new RegExp(ban.pattern, "g")
|
|
627
819
|
}));
|
|
820
|
+
if (!ctx.hasDist || bans.length === 0) return null;
|
|
821
|
+
const skip = [...ctx.options.copyExcludePaths, ...ctx.options.bannedCopyExcludePaths];
|
|
628
822
|
const findings = [];
|
|
629
823
|
return {
|
|
630
824
|
visit: (page) => {
|
|
@@ -632,7 +826,7 @@ const bannedCopy = {
|
|
|
632
826
|
const text = blockText(page.document.body);
|
|
633
827
|
for (const ban of bans) for (const match of text.matchAll(ban.re)) if (match[0]) findings.push({
|
|
634
828
|
path: page.path,
|
|
635
|
-
message: `"${excerpt$
|
|
829
|
+
message: `"${excerpt$3(match[0], 70)}" is a banned wording: ${ban.why}`
|
|
636
830
|
});
|
|
637
831
|
},
|
|
638
832
|
finish: () => findings
|
|
@@ -641,8 +835,9 @@ const bannedCopy = {
|
|
|
641
835
|
};
|
|
642
836
|
/** The same sentence rendered twice on one page: a copy accident a reader sees at once. Within one
|
|
643
837
|
* page only; across pages a shared section and an accident look the same. Waits while every page
|
|
644
|
-
* is noindex (a site before launch repeats placeholder copy by design)
|
|
645
|
-
*
|
|
838
|
+
* is noindex (a site before launch repeats placeholder copy by design); the 404 page, which often
|
|
839
|
+
* carries no robots meta on a preview, does not wake it. A warning: the feed's descriptions are on
|
|
840
|
+
* the page too. */
|
|
646
841
|
const duplicateSentences = {
|
|
647
842
|
id: "duplicate-sentences",
|
|
648
843
|
title: "A sentence printed twice on one page",
|
|
@@ -650,22 +845,22 @@ const duplicateSentences = {
|
|
|
650
845
|
stage: "dist",
|
|
651
846
|
begin: (ctx) => {
|
|
652
847
|
if (!ctx.hasDist) return null;
|
|
653
|
-
const allowed = new Set(ctx.options.allowDuplicateSentences.map(normalize$
|
|
848
|
+
const allowed = new Set(ctx.options.allowDuplicateSentences.map(normalize$2));
|
|
654
849
|
const findings = [];
|
|
655
850
|
let indexable = 0;
|
|
656
851
|
return {
|
|
657
852
|
visit: (page) => {
|
|
658
|
-
if (
|
|
853
|
+
if (isIndexable(page)) indexable += 1;
|
|
659
854
|
if (excluded(page, ctx.options.copyExcludePaths)) return;
|
|
660
855
|
const seen = /* @__PURE__ */ new Map();
|
|
661
856
|
for (const sentence of sentencesOf(proseBlocks(page))) {
|
|
662
857
|
if (sentence.length < MIN_SENTENCE) continue;
|
|
663
|
-
const key = normalize$
|
|
858
|
+
const key = normalize$2(sentence);
|
|
664
859
|
const count = (seen.get(key) ?? 0) + 1;
|
|
665
860
|
seen.set(key, count);
|
|
666
861
|
if (count === 2 && !allowed.has(key)) findings.push({
|
|
667
862
|
path: page.path,
|
|
668
|
-
message: `The same sentence is rendered twice on the page: "${excerpt$
|
|
863
|
+
message: `The same sentence is rendered twice on the page: "${excerpt$3(sentence)}"`
|
|
669
864
|
});
|
|
670
865
|
}
|
|
671
866
|
},
|
|
@@ -693,7 +888,8 @@ const readSources = (root, rel) => {
|
|
|
693
888
|
/** Every `<blockquote>` quotes, word for word, a source the site recorded (`quoteSources`): a quote
|
|
694
889
|
* matching none was paraphrased or made up. The attribution (`cite`, `footer`, `figcaption`) is
|
|
695
890
|
* not part of the quote. A configured source that is missing is a finding, not a skip: the step
|
|
696
|
-
* that writes it stopped and the check would verify nothing.
|
|
891
|
+
* that writes it stopped and the check would verify nothing. With no source there at all, that is
|
|
892
|
+
* the finding: every quote reported besides would say the same thing once per quote. */
|
|
697
893
|
const quoteSources = {
|
|
698
894
|
id: "quote-sources",
|
|
699
895
|
title: "Quotes match their sources",
|
|
@@ -703,26 +899,30 @@ const quoteSources = {
|
|
|
703
899
|
if (!ctx.hasDist || ctx.options.quoteSources.length === 0) return null;
|
|
704
900
|
const findings = [];
|
|
705
901
|
const corpusParts = [];
|
|
902
|
+
let missing = 0;
|
|
706
903
|
for (const rel of ctx.options.quoteSources) {
|
|
707
904
|
const parts = readSources(ctx.root, rel);
|
|
708
|
-
if (parts === null)
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
905
|
+
if (parts === null) {
|
|
906
|
+
missing += 1;
|
|
907
|
+
findings.push({
|
|
908
|
+
path: rel,
|
|
909
|
+
message: `The quote source ${rel} is missing: the step that writes it did not run, so no quote was verified against it.`
|
|
910
|
+
});
|
|
911
|
+
} else corpusParts.push(...parts);
|
|
713
912
|
}
|
|
714
|
-
const corpus = normalize$
|
|
913
|
+
const corpus = normalize$2(corpusParts.join(" "));
|
|
715
914
|
const where = ctx.options.quoteSources.join(", ");
|
|
915
|
+
const allMissing = missing === ctx.options.quoteSources.length;
|
|
716
916
|
return {
|
|
717
917
|
visit: (page) => {
|
|
718
|
-
if (excluded(page, ctx.options.copyExcludePaths)) return;
|
|
918
|
+
if (allMissing || excluded(page, ctx.options.copyExcludePaths)) return;
|
|
719
919
|
for (const quote of page.document.querySelectorAll("blockquote")) {
|
|
720
920
|
const copy = quote.cloneNode(true);
|
|
721
921
|
for (const attribution of copy.querySelectorAll("cite, footer, figcaption")) attribution.remove();
|
|
722
922
|
const text = blockText(copy);
|
|
723
|
-
if (text.length >= MIN_QUOTE && !corpus.includes(normalize$
|
|
923
|
+
if (text.length >= MIN_QUOTE && !corpus.includes(normalize$2(text))) findings.push({
|
|
724
924
|
path: page.path,
|
|
725
|
-
message: `A <blockquote> is not word for word in ${where}: "${excerpt$
|
|
925
|
+
message: `A <blockquote> is not word for word in ${where}: "${excerpt$3(text)}"`
|
|
726
926
|
});
|
|
727
927
|
}
|
|
728
928
|
},
|
|
@@ -734,7 +934,8 @@ const quoteSources = {
|
|
|
734
934
|
//#region src/checks/donorTerms.ts
|
|
735
935
|
/** More than this and the point is made; the runner keeps 25 anyway. */
|
|
736
936
|
const MAX_RAW_FINDINGS = 100;
|
|
737
|
-
const
|
|
937
|
+
const collapse$2 = (text) => text.normalize("NFC").replace(/\s+/g, " ");
|
|
938
|
+
const normalize$1 = (text) => collapse$2(text).toLowerCase();
|
|
738
939
|
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
739
940
|
const WORD = /[\p{L}\p{N}]/u;
|
|
740
941
|
/** A term as a whole word: where it starts or ends with a letter or digit, the text next to it must
|
|
@@ -745,49 +946,72 @@ const wholeWord = (term) => {
|
|
|
745
946
|
const chars = [...term];
|
|
746
947
|
return new RegExp(`${WORD.test(chars[0]) ? "(?<![\\p{L}\\p{N}])" : ""}${escape(term)}${WORD.test(chars.at(-1)) ? "(?![\\p{L}\\p{N}])" : ""}`, "u");
|
|
747
948
|
};
|
|
748
|
-
const excerpt$
|
|
949
|
+
const excerpt$2 = (haystack, at, length) => {
|
|
749
950
|
const start = Math.max(0, at - 30);
|
|
750
951
|
const end = Math.min(haystack.length, at + length + 30);
|
|
751
952
|
return `${start > 0 ? "…" : ""}${haystack.slice(start, end)}${end < haystack.length ? "…" : ""}`;
|
|
752
953
|
};
|
|
954
|
+
const matchersOf = (options) => [...new Set(options.donorTerms.map(normalize$1).map((t) => t.trim()).filter(Boolean))].map((term) => ({
|
|
955
|
+
label: `donor term "${term}"`,
|
|
956
|
+
caseless: true,
|
|
957
|
+
re: wholeWord(term)
|
|
958
|
+
})).concat([...new Set(options.donorPatterns)].map((pattern) => ({
|
|
959
|
+
label: `donor pattern /${pattern}/`,
|
|
960
|
+
caseless: false,
|
|
961
|
+
re: new RegExp(pattern, "u")
|
|
962
|
+
})));
|
|
963
|
+
/** The findings of one check and the scan that fills them: one finding per matcher and place, from
|
|
964
|
+
* the first of the texts that contains it. Returns the labels it found, so a later scan of the
|
|
965
|
+
* same place can leave them out. */
|
|
966
|
+
const finder = (ctx, id, matchers) => {
|
|
967
|
+
const exclusions = ctx.options.exclude[id];
|
|
968
|
+
const excluded = Array.isArray(exclusions) ? exclusions : [];
|
|
969
|
+
const findings = [];
|
|
970
|
+
const scan = (texts, at, where, skip) => {
|
|
971
|
+
const found = /* @__PURE__ */ new Set();
|
|
972
|
+
let lower;
|
|
973
|
+
let cased;
|
|
974
|
+
for (const { label, caseless, re } of matchers) {
|
|
975
|
+
if (findings.length >= MAX_RAW_FINDINGS) break;
|
|
976
|
+
if (skip?.has(label)) continue;
|
|
977
|
+
const haystacks = caseless ? lower ??= texts.map(normalize$1) : cased ??= texts.map(collapse$2);
|
|
978
|
+
for (const haystack of haystacks) {
|
|
979
|
+
const match = re.exec(haystack);
|
|
980
|
+
if (!match) continue;
|
|
981
|
+
found.add(label);
|
|
982
|
+
const finding = {
|
|
983
|
+
path: at,
|
|
984
|
+
message: `${label} in ${where}: "${excerpt$2(haystack, match.index, match[0].length)}"`
|
|
985
|
+
};
|
|
986
|
+
if (!isExcluded(excluded, finding)) findings.push(finding);
|
|
987
|
+
break;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
return found;
|
|
991
|
+
};
|
|
992
|
+
return {
|
|
993
|
+
findings,
|
|
994
|
+
scan
|
|
995
|
+
};
|
|
996
|
+
};
|
|
753
997
|
/** Every site starts from a template ("donor") site, and nothing of it may ship: its brand, people,
|
|
754
|
-
* places, phone, email, domain, asset names. The site lists
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
* text, the title, the inline scripts and styles
|
|
758
|
-
* attributes of every built page, in the built file
|
|
759
|
-
* island's copy lives.
|
|
998
|
+
* places, phone, email, domain, asset names. The site lists them in `site-checks.config.json`:
|
|
999
|
+
* `donorTerms` match as whole words, case-insensitively with whitespace collapsed;
|
|
1000
|
+
* `donorPatterns` are regular expressions matched as written. Without either the check skips,
|
|
1001
|
+
* which the report shows. Matched in the visible text, the title, the inline scripts and styles
|
|
1002
|
+
* (JSON-LD shows in search results) and the attributes of every built page, in the built file
|
|
1003
|
+
* names and in the shipped JS and CSS, where an island's copy lives. A warning: the built pages
|
|
1004
|
+
* carry the PMS feed's text, which may name a place the template site named too. The site's own
|
|
1005
|
+
* source is `donor-terms-source`, an error. */
|
|
760
1006
|
const donorTerms = {
|
|
761
1007
|
id: "donor-terms",
|
|
762
1008
|
title: "Terms of the template site in the built output",
|
|
763
|
-
severity: "
|
|
1009
|
+
severity: "warning",
|
|
764
1010
|
stage: "dist",
|
|
765
1011
|
begin: (ctx) => {
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
}));
|
|
770
|
-
if (terms.length === 0 || !ctx.hasDist) return null;
|
|
771
|
-
const exclusions = ctx.options.exclude["donor-terms"];
|
|
772
|
-
const excluded = Array.isArray(exclusions) ? exclusions : [];
|
|
773
|
-
const findings = [];
|
|
774
|
-
/** One finding per term and place: the first text of `texts` that contains it. */
|
|
775
|
-
const scan = (texts, path, where) => {
|
|
776
|
-
const haystacks = texts.map(normalize$2);
|
|
777
|
-
for (const { term, re } of terms) {
|
|
778
|
-
if (findings.length >= MAX_RAW_FINDINGS) return;
|
|
779
|
-
for (const haystack of haystacks) {
|
|
780
|
-
const match = re.exec(haystack);
|
|
781
|
-
if (!match) continue;
|
|
782
|
-
const finding = {
|
|
783
|
-
path,
|
|
784
|
-
message: `donor term "${term}" in ${where}: "${excerpt$1(haystack, match.index, term.length)}"`
|
|
785
|
-
};
|
|
786
|
-
if (!isExcluded(excluded, finding)) findings.push(finding);
|
|
787
|
-
break;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
};
|
|
1012
|
+
const matchers = matchersOf(ctx.options);
|
|
1013
|
+
if (matchers.length === 0 || !ctx.hasDist) return null;
|
|
1014
|
+
const { findings, scan } = finder(ctx, "donor-terms", matchers);
|
|
791
1015
|
return {
|
|
792
1016
|
visit: (page) => {
|
|
793
1017
|
scan([blockText(page.document.body ?? page.document.documentElement)], page.path, "the visible text");
|
|
@@ -804,19 +1028,83 @@ const donorTerms = {
|
|
|
804
1028
|
};
|
|
805
1029
|
}
|
|
806
1030
|
};
|
|
1031
|
+
/** The text files of `src/` read whole: code, styles, content, data. */
|
|
1032
|
+
const SOURCE_TEXT = new Set(".astro .ts .tsx .mts .cts .js .jsx .mjs .cjs .vue .svelte .css .scss .sass .less .md .mdx .markdoc .json .yaml .yml .toml .html .svg .txt .xml .webmanifest".split(" "));
|
|
1033
|
+
/** The files of `public/` the site writes as text (`llms.txt`, a manifest, data, an SVG): its code
|
|
1034
|
+
* and styles there are libraries it ships as they come, not the site's to word. */
|
|
1035
|
+
const PUBLIC_TEXT = new Set(".txt .json .webmanifest .xml .svg .html .md".split(" "));
|
|
1036
|
+
/** Where a line can open a comment that wraps onto the next. */
|
|
1037
|
+
const COMMENTED = new Set(".astro .ts .tsx .mts .cts .js .jsx .mjs .cjs .vue .svelte .css .scss .sass .less".split(" "));
|
|
1038
|
+
/** A line whose first characters open or continue a comment: `//`, `/*`, `{/*`, ` * `. */
|
|
1039
|
+
const COMMENT_LINE = /^\s*(?:\/\/|\/\*|\{\/\*|\*)/;
|
|
1040
|
+
/** A comment line's prose: the closer first, so a lone ` *\/` does not leave a `/` behind. */
|
|
1041
|
+
const commentText = (line) => line.trim().replace(/\*\/\}?\s*$/, "").replace(/^(?:\{\/\*+|\/\*+|\/\/+|\*+)/, "").trim();
|
|
1042
|
+
/** Each pair of adjacent comment lines joined both ways a wrap can cut a term: with a space (a
|
|
1043
|
+
* term wrapped at its space) and without (a domain wrapped mid-token). A line that holds no prose
|
|
1044
|
+
* (a JSDoc blank line) ends the pair. The tight join can invent a word nobody wrote; a finding
|
|
1045
|
+
* says where, so that stays inspectable. */
|
|
1046
|
+
const commentSeams = (text) => {
|
|
1047
|
+
const seams = [];
|
|
1048
|
+
let previous;
|
|
1049
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1050
|
+
const prose = COMMENT_LINE.test(line) ? commentText(line) : "";
|
|
1051
|
+
if (prose && previous) seams.push(`${previous} ${prose}`, `${previous}${prose}`);
|
|
1052
|
+
previous = prose || void 0;
|
|
1053
|
+
}
|
|
1054
|
+
return seams;
|
|
1055
|
+
};
|
|
1056
|
+
/** Every file under `dir`, at any depth, `node_modules` left out. */
|
|
1057
|
+
const allFiles = (dir) => fs.existsSync(dir) ? fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
1058
|
+
const full = path.join(dir, entry.name);
|
|
1059
|
+
if (entry.isDirectory()) return entry.name === "node_modules" ? [] : allFiles(full);
|
|
1060
|
+
return entry.isFile() ? [full] : [];
|
|
1061
|
+
}) : [];
|
|
1062
|
+
/** The donor's terms and patterns in what the site itself writes, before the build: every text file
|
|
1063
|
+
* under `src/` (code, comments, content, data) and the text and data files of `public/` (`llms.txt`,
|
|
1064
|
+
* a manifest, an SVG; not the scripts and styles it ships as they come), the Astro config and
|
|
1065
|
+
* `package.json`, with a term rejoined where a comment wraps it over two lines; and the
|
|
1066
|
+
* names of the files under `src/` and `public/` (a donor's logo left behind). An error: no PMS
|
|
1067
|
+
* data is in these files. The blueprint process docs (CUSTOMER.md, DESIGN.md, …) are not read. */
|
|
1068
|
+
const donorTermsSource = {
|
|
1069
|
+
id: "donor-terms-source",
|
|
1070
|
+
title: "Terms of the template site in the site's own source",
|
|
1071
|
+
severity: "error",
|
|
1072
|
+
stage: "src",
|
|
1073
|
+
begin: (ctx) => {
|
|
1074
|
+
const matchers = matchersOf(ctx.options);
|
|
1075
|
+
if (matchers.length === 0) return null;
|
|
1076
|
+
const { findings, scan } = finder(ctx, "donor-terms-source", matchers);
|
|
1077
|
+
return { finish: () => {
|
|
1078
|
+
const texts = [
|
|
1079
|
+
...ctx.sourceFiles(SOURCE_TEXT),
|
|
1080
|
+
...[...CONFIG_FILES, "package.json"].map((name) => path.join(ctx.root, name)),
|
|
1081
|
+
...filesUnder(ctx.publicDir, PUBLIC_TEXT)
|
|
1082
|
+
].filter((file) => fs.existsSync(file));
|
|
1083
|
+
for (const file of texts) {
|
|
1084
|
+
const text = ctx.readSource(file);
|
|
1085
|
+
const at = ctx.rel(file);
|
|
1086
|
+
const found = scan([text], at, "the source");
|
|
1087
|
+
if (COMMENTED.has(path.extname(file).toLowerCase())) scan(commentSeams(text), at, "a comment wrapped over two lines", found);
|
|
1088
|
+
}
|
|
1089
|
+
for (const file of [...allFiles(ctx.srcDir), ...allFiles(ctx.publicDir)].sort()) {
|
|
1090
|
+
const at = ctx.rel(file);
|
|
1091
|
+
scan([at], at, "a file name");
|
|
1092
|
+
}
|
|
1093
|
+
return findings;
|
|
1094
|
+
} };
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
807
1097
|
//#endregion
|
|
808
1098
|
//#region src/checks/htmlComments.ts
|
|
1099
|
+
/** Files that hold no text: an image or font can carry the bytes `<!--` by chance, and reading
|
|
1100
|
+
* every photo under `src/assets/` costs time for nothing. */
|
|
1101
|
+
const BINARY_EXTENSIONS = new Set(".png .jpg .jpeg .gif .webp .avif .ico .bmp .tif .tiff .woff .woff2 .ttf .otf .eot .mp4 .webm .mov .mp3 .pdf .zip".split(" "));
|
|
1102
|
+
const MESSAGE = "An HTML comment ships to the built page, readable with View Source. Use {/* … */} in .astro and JSX markup, // in frontmatter and scripts, and remove it from Markdown; a note in a string the page renders (set:html) goes beside the code, outside the string.";
|
|
809
1103
|
/** Astro passes an HTML comment in a template straight into the built page, where a visitor reads
|
|
810
|
-
* it with View Source
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
".jsx",
|
|
815
|
-
".md",
|
|
816
|
-
".mdx",
|
|
817
|
-
".html"
|
|
818
|
-
]);
|
|
819
|
-
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.";
|
|
1104
|
+
* it with View Source; Markdown, an SVG and a string a page renders with `set:html` carry one
|
|
1105
|
+
* there too. Every text file under `src/` is read, as the commit hook's
|
|
1106
|
+
* `git grep -F '<!--' -- src/` did: a script comment that only talks about `<!--` is reported
|
|
1107
|
+
* too, and is reworded or excluded. */
|
|
820
1108
|
const htmlComments = {
|
|
821
1109
|
id: "html-comments",
|
|
822
1110
|
title: "HTML comments in the source",
|
|
@@ -824,7 +1112,9 @@ const htmlComments = {
|
|
|
824
1112
|
stage: "src",
|
|
825
1113
|
begin: (ctx) => ({ finish: () => {
|
|
826
1114
|
const findings = [];
|
|
827
|
-
|
|
1115
|
+
const files = [...filesUnder(ctx.srcDir)].sort();
|
|
1116
|
+
for (const file of files) {
|
|
1117
|
+
if (BINARY_EXTENSIONS.has(path.extname(file).toLowerCase())) continue;
|
|
828
1118
|
const text = ctx.readSource(file);
|
|
829
1119
|
let index = text.indexOf("<!--");
|
|
830
1120
|
while (index !== -1) {
|
|
@@ -853,6 +1143,45 @@ const RASTER = /* @__PURE__ */ new Set([
|
|
|
853
1143
|
* An AVIF beside them serves nobody; a file named otherwise goes in `imageIgnore`. */
|
|
854
1144
|
const ICON = /^(?:apple-touch-icon|favicon|icon-|android-chrome-|mstile-|web-app-manifest-)/;
|
|
855
1145
|
const SHARE = /^(?:og[-_]|social-|twitter-|share-)|-(?:og|social)\./;
|
|
1146
|
+
const MANIFEST_IMAGE = /["'`]([^"'`?#]*\.(?:png|jpe?g|webp))(?:[?#][^"'`]*)?["'`]/gi;
|
|
1147
|
+
/** An Astro endpoint that writes the manifest (`src/pages/site.webmanifest.ts`). */
|
|
1148
|
+
const MANIFEST_ENDPOINT = /(?:\.webmanifest|manifest\.json)\.(?:[cm]?[jt]s)$/;
|
|
1149
|
+
/** The images the site's web manifests name (`*.webmanifest` anywhere under `public/`,
|
|
1150
|
+
* `public/manifest.json`, or the endpoint under `src/pages/` that writes one), as project-relative
|
|
1151
|
+
* paths: app icons and screenshots, which AVIF is no format for. Each name is resolved as the
|
|
1152
|
+
* browser does, from the site root or from the manifest's own folder, so an icon keeps its
|
|
1153
|
+
* exemption whatever its name, and an unrelated image of the same name has none. An absolute URL
|
|
1154
|
+
* names a file of this build only on the site's own origin: an icon on another host exempts
|
|
1155
|
+
* nothing here, and without a known site origin no absolute URL does. */
|
|
1156
|
+
const manifestImages = (publicDir, srcDir, rel, site) => {
|
|
1157
|
+
let origin;
|
|
1158
|
+
try {
|
|
1159
|
+
origin = site ? new URL(site).origin : void 0;
|
|
1160
|
+
} catch {
|
|
1161
|
+
origin = void 0;
|
|
1162
|
+
}
|
|
1163
|
+
const pagesDir = path.join(srcDir, "pages");
|
|
1164
|
+
const manifests = [...filesUnder(publicDir, /* @__PURE__ */ new Set([".webmanifest"])), ...[path.join(publicDir, "manifest.json")].filter((file) => fs.existsSync(file))].map((file) => ({
|
|
1165
|
+
file,
|
|
1166
|
+
folder: path.relative(publicDir, path.dirname(file))
|
|
1167
|
+
}));
|
|
1168
|
+
for (const file of filesUnder(pagesDir)) if (MANIFEST_ENDPOINT.test(file)) manifests.push({
|
|
1169
|
+
file,
|
|
1170
|
+
folder: path.relative(pagesDir, path.dirname(file))
|
|
1171
|
+
});
|
|
1172
|
+
const images = /* @__PURE__ */ new Set();
|
|
1173
|
+
for (const { file, folder } of manifests) for (const m of fs.readFileSync(file, "utf8").matchAll(MANIFEST_IMAGE)) {
|
|
1174
|
+
let url = m[1];
|
|
1175
|
+
if (/^(?:https?:)?\/\//i.test(url)) {
|
|
1176
|
+
const absolute = new URL(url, "https://unknown.invalid");
|
|
1177
|
+
if (!origin || absolute.origin !== origin) continue;
|
|
1178
|
+
url = absolute.pathname;
|
|
1179
|
+
}
|
|
1180
|
+
const inPublic = url.startsWith("/") ? url.slice(1) : path.posix.join(folder.split(path.sep).join("/"), url);
|
|
1181
|
+
images.add(rel(path.join(publicDir, path.posix.normalize(inPublic))));
|
|
1182
|
+
}
|
|
1183
|
+
return images;
|
|
1184
|
+
};
|
|
856
1185
|
/** The URLs an element references for an image: `src`, `poster`, every `srcset` candidate. */
|
|
857
1186
|
const imageUrls = (el) => {
|
|
858
1187
|
const urls = [];
|
|
@@ -876,12 +1205,13 @@ const imageFormats = {
|
|
|
876
1205
|
stage: "src",
|
|
877
1206
|
begin: (ctx) => {
|
|
878
1207
|
const ignored = new Set(ctx.options.imageIgnore);
|
|
1208
|
+
const manifest = manifestImages(ctx.publicDir, ctx.srcDir, ctx.rel, ctx.config.site);
|
|
879
1209
|
return { finish: () => {
|
|
880
1210
|
const findings = [];
|
|
881
1211
|
for (const file of filesUnder(ctx.publicDir, RASTER)) {
|
|
882
1212
|
const rel = ctx.rel(file);
|
|
883
1213
|
const name = path.basename(file);
|
|
884
|
-
if (ignored.has(rel) || ICON.test(name) || SHARE.test(name)) continue;
|
|
1214
|
+
if (ignored.has(rel) || manifest.has(rel) || ICON.test(name) || SHARE.test(name)) continue;
|
|
885
1215
|
const stem = file.slice(0, -path.extname(file).length);
|
|
886
1216
|
if (fs.existsSync(`${stem}.avif`)) continue;
|
|
887
1217
|
findings.push({
|
|
@@ -893,9 +1223,15 @@ const imageFormats = {
|
|
|
893
1223
|
} };
|
|
894
1224
|
}
|
|
895
1225
|
};
|
|
1226
|
+
/** An absolute URL inside text: an attribute value (island props, `style`, `data-*`), inline JSON
|
|
1227
|
+
* or CSS. It ends at a quote, a space, a comma (a `srcset`), a `)` (CSS `url()`), `&` (`"`) or a backslash. */
|
|
1228
|
+
const TEXT_URL = /https?:\/\/[^\s"'`<>(),&\\]+/g;
|
|
896
1229
|
/** A feed photo from the vOffice image hosts requested as JPEG or PNG where the host would serve
|
|
897
|
-
* WebP.
|
|
898
|
-
*
|
|
1230
|
+
* WebP. Read wherever a page can carry a photo URL: `src`, `srcset` and `poster`, every other
|
|
1231
|
+
* attribute (an island's props: v9 search listings render their photos there, `style`), inline
|
|
1232
|
+
* scripts (JSON) and styles (`background-image`). A warning: the photos come from the PMS feed, so
|
|
1233
|
+
* a page shows them, and the finding, only once the feed has them; that must not stop the nightly
|
|
1234
|
+
* builds that update prices. */
|
|
899
1235
|
const feedImageFormats = {
|
|
900
1236
|
id: "feed-image-formats",
|
|
901
1237
|
title: "Feed photo formats",
|
|
@@ -907,9 +1243,13 @@ const feedImageFormats = {
|
|
|
907
1243
|
const findings = [];
|
|
908
1244
|
return {
|
|
909
1245
|
visit: (page) => {
|
|
910
|
-
|
|
1246
|
+
const urls = /* @__PURE__ */ new Set();
|
|
1247
|
+
for (const el of page.document.querySelectorAll("img, source, video")) for (const url of imageUrls(el)) urls.add(url);
|
|
1248
|
+
const texts = [...page.attributeValues(), ...[...page.document.querySelectorAll("script, style")].map((el) => el.textContent ?? "")];
|
|
1249
|
+
for (const text of texts) for (const [url] of text.matchAll(TEXT_URL)) urls.add(url);
|
|
1250
|
+
for (const url of urls) if (patterns.some((pattern) => pattern.test(url))) findings.push({
|
|
911
1251
|
path: page.path,
|
|
912
|
-
message: `A feed photo is requested as JPEG or PNG: ${url}. Pass it through webpUrl() so the host serves WebP.`
|
|
1252
|
+
message: `A feed photo is requested as JPEG or PNG: ${url}. Pass it through webpUrl() so the host serves WebP, or end an imgproxy URL in .webp.`
|
|
913
1253
|
});
|
|
914
1254
|
},
|
|
915
1255
|
finish: () => findings
|
|
@@ -917,6 +1257,71 @@ const feedImageFormats = {
|
|
|
917
1257
|
}
|
|
918
1258
|
};
|
|
919
1259
|
//#endregion
|
|
1260
|
+
//#region src/sitemaps.ts
|
|
1261
|
+
/** A URL path as the sitemap checks compare it: query and fragment dropped, escapes decoded, no
|
|
1262
|
+
* trailing slash but the root's. The slash is a project-wide setting (`trailingSlash`), not a
|
|
1263
|
+
* statement about the page. */
|
|
1264
|
+
const normalize = (urlPath) => {
|
|
1265
|
+
let p = urlPath.split(/[?#]/, 1)[0] ?? "";
|
|
1266
|
+
try {
|
|
1267
|
+
p = decodeURIComponent(p);
|
|
1268
|
+
} catch {}
|
|
1269
|
+
return p.length > 1 ? p.replace(/\/+$/, "") : p;
|
|
1270
|
+
};
|
|
1271
|
+
/** `https://www.example.de/a/` and `/a/` → `/a`. */
|
|
1272
|
+
const toPath = (loc) => {
|
|
1273
|
+
const value = loc.trim();
|
|
1274
|
+
try {
|
|
1275
|
+
return normalize(new URL(value).pathname);
|
|
1276
|
+
} catch {
|
|
1277
|
+
return normalize(value);
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
const locs = (xml) => [...xml.matchAll(/<loc>\s*([^<]+?)\s*<\/loc>/g)].map((m) => xmlText(m[1]));
|
|
1281
|
+
/** One read per build: the checks of a stage share its file list, and three of them ask. */
|
|
1282
|
+
const read = /* @__PURE__ */ new WeakMap();
|
|
1283
|
+
/** Every page the build's sitemaps list: each `sitemap*.xml` at the root of the build (an index, a
|
|
1284
|
+
* stray hand-written one, the `/sitemap.xml` alias), and every sitemap an index names, once each,
|
|
1285
|
+
* so a cycle ends. `missing` holds the sitemaps an index names that the build lacks. */
|
|
1286
|
+
const readSitemaps = (ctx) => {
|
|
1287
|
+
let sitemaps = read.get(ctx.files);
|
|
1288
|
+
if (!sitemaps) read.set(ctx.files, sitemaps = walkSitemaps(ctx));
|
|
1289
|
+
return sitemaps;
|
|
1290
|
+
};
|
|
1291
|
+
const walkSitemaps = (ctx) => {
|
|
1292
|
+
const entries = [];
|
|
1293
|
+
const missing = [];
|
|
1294
|
+
const sitemaps = new Map(ctx.files.filter((f) => /^sitemap[^/]*\.xml$/.test(f)).map((file) => [file, ""]));
|
|
1295
|
+
for (const [sitemap, index] of sitemaps) {
|
|
1296
|
+
if (!ctx.has(sitemap)) {
|
|
1297
|
+
missing.push({
|
|
1298
|
+
path: index,
|
|
1299
|
+
message: `The sitemap index names ${sitemap}, which is not in the build.`
|
|
1300
|
+
});
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
const xml = ctx.read(sitemap);
|
|
1304
|
+
if (/<sitemapindex\b/i.test(xml)) {
|
|
1305
|
+
for (const loc of locs(xml)) {
|
|
1306
|
+
const child = toPath(loc).replace(/^\//, "");
|
|
1307
|
+
if (!sitemaps.has(child)) sitemaps.set(child, sitemap);
|
|
1308
|
+
}
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
for (const loc of locs(xml)) entries.push({
|
|
1312
|
+
sitemap,
|
|
1313
|
+
loc,
|
|
1314
|
+
path: toPath(loc)
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
return {
|
|
1318
|
+
entries,
|
|
1319
|
+
missing
|
|
1320
|
+
};
|
|
1321
|
+
};
|
|
1322
|
+
/** The paths (`normalize`d) the build's sitemaps list; empty without a sitemap. */
|
|
1323
|
+
const sitemapPaths = (ctx) => new Set(readSitemaps(ctx).entries.map((entry) => entry.path));
|
|
1324
|
+
//#endregion
|
|
920
1325
|
//#region src/checks/launchHead.ts
|
|
921
1326
|
/** Hosts a site is previewed on before it has its own domain: a `site` there is not a launch. */
|
|
922
1327
|
const PREVIEW_HOST = /(?:^|\.)(?:cloudfront\.net|vercel\.app|netlify\.app|pages\.dev|github\.io)$|^(?:localhost|127\.0\.0\.1)$|\.local$/i;
|
|
@@ -929,58 +1334,104 @@ const productionSite = (ctx) => {
|
|
|
929
1334
|
return;
|
|
930
1335
|
}
|
|
931
1336
|
};
|
|
1337
|
+
/** Runs `finish` once the site is launched: a production `site` in the Astro config and some
|
|
1338
|
+
* indexable page in the build. `null` (skipped) without a production `site` or a build; `[]`
|
|
1339
|
+
* while every page is noindex. */
|
|
1340
|
+
const whenLaunched = (ctx, finish) => {
|
|
1341
|
+
if (!ctx.hasDist || !productionSite(ctx)) return null;
|
|
1342
|
+
let launched = false;
|
|
1343
|
+
return {
|
|
1344
|
+
visit: (page) => {
|
|
1345
|
+
if (isIndexable(page)) launched = true;
|
|
1346
|
+
},
|
|
1347
|
+
finish: () => launched ? finish() : []
|
|
1348
|
+
};
|
|
1349
|
+
};
|
|
932
1350
|
const isAbsolute = (url) => !!url && /^https?:\/\/[^/]/i.test(url.trim());
|
|
933
|
-
/** A page the launch head applies to: indexable, read by someone, not the 404 page. */
|
|
934
|
-
const indexable = (page) => !page.redirect && !page.noindex && page.path !== "404.html";
|
|
935
1351
|
/** A check over the launched site's indexable pages: it waits while the site is a preview (no
|
|
936
1352
|
* production `site` in the Astro config) or every page is noindex (the preview's blanket robots
|
|
937
|
-
* meta), and starts with the build that lifts it.
|
|
938
|
-
|
|
1353
|
+
* meta), and starts with the build that lifts it. `start` sets the check up once and returns what
|
|
1354
|
+
* it reports of each indexable page. */
|
|
1355
|
+
const launchCheck = (base, start) => ({
|
|
939
1356
|
...base,
|
|
940
1357
|
begin: (ctx) => {
|
|
941
1358
|
const site = productionSite(ctx);
|
|
942
1359
|
if (!ctx.hasDist || !site) return null;
|
|
1360
|
+
const inspect = start(ctx, site);
|
|
943
1361
|
const findings = [];
|
|
944
1362
|
let launched = false;
|
|
945
1363
|
return {
|
|
946
1364
|
visit: (page) => {
|
|
947
|
-
if (!
|
|
1365
|
+
if (!isIndexable(page)) return;
|
|
948
1366
|
launched = true;
|
|
949
|
-
findings.push(...inspect(page
|
|
1367
|
+
findings.push(...inspect(page));
|
|
950
1368
|
},
|
|
951
1369
|
finish: () => launched ? findings : []
|
|
952
1370
|
};
|
|
953
1371
|
}
|
|
954
1372
|
});
|
|
955
|
-
|
|
956
|
-
|
|
1373
|
+
const canonicalOf = (page) => page.document.querySelector("link[rel=\"canonical\"]")?.getAttribute("href")?.trim();
|
|
1374
|
+
/** Every indexable page of the launched site names its canonical URL, absolute, on the site's own
|
|
1375
|
+
* origin, without a query, in the URL form `trailingSlash` serves: without one, a search engine
|
|
1376
|
+
* picks among `/x`, `/x/` and `/x?ref=…`, and one on a preview host hands the index to that host.
|
|
1377
|
+
* A page the sitemap lists names itself: the sitemap offers the URL, so a canonical naming another
|
|
1378
|
+
* page disowns it. A page the sitemap leaves out may point at the page it duplicates. */
|
|
957
1379
|
const canonicalLink = launchCheck({
|
|
958
1380
|
id: "canonical-link",
|
|
959
1381
|
title: "Indexable pages name their canonical URL",
|
|
960
1382
|
severity: "error",
|
|
961
1383
|
stage: "dist"
|
|
962
|
-
}, (
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1384
|
+
}, (ctx, site) => {
|
|
1385
|
+
const origin = new URL(site).origin;
|
|
1386
|
+
const listed = sitemapPaths(ctx);
|
|
1387
|
+
const slash = ctx.config.trailingSlash;
|
|
1388
|
+
return (page) => {
|
|
1389
|
+
const href = canonicalOf(page);
|
|
1390
|
+
const finding = (message) => [{
|
|
1391
|
+
path: page.path,
|
|
1392
|
+
message
|
|
1393
|
+
}];
|
|
1394
|
+
if (!isAbsolute(href)) return finding(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.");
|
|
1395
|
+
let url;
|
|
1396
|
+
try {
|
|
1397
|
+
url = new URL(href);
|
|
1398
|
+
} catch {
|
|
1399
|
+
return finding(`The canonical URL "${href}" is not a URL a crawler can read.`);
|
|
1400
|
+
}
|
|
1401
|
+
if (url.origin !== origin) return finding(`The canonical URL "${href}" is on ${url.origin}, not on the site's ${origin}: build it from the Astro \`site\`.`);
|
|
1402
|
+
if (url.search || url.hash) return finding(`The canonical URL "${href}" carries a query or fragment: name the page's own URL without one.`);
|
|
1403
|
+
const own = normalize(page.url);
|
|
1404
|
+
if (listed.has(own) && normalize(url.pathname) !== own) return finding(`The canonical URL "${href}" names another page than ${own}, which the sitemap lists: the page disowns the URL the sitemap offers. Build the canonical from the page's own path.`);
|
|
1405
|
+
const root = url.pathname === "/";
|
|
1406
|
+
if (!root && slash === "never" && url.pathname.endsWith("/")) return finding(`The canonical URL "${href}" ends with a slash, and trailingSlash is "never": that URL redirects. Drop the slash.`);
|
|
1407
|
+
if (!root && slash === "always" && !url.pathname.endsWith("/")) return finding(`The canonical URL "${href}" has no trailing slash, and trailingSlash is "always": that URL redirects. Add the slash.`);
|
|
1408
|
+
return [];
|
|
1409
|
+
};
|
|
969
1410
|
});
|
|
970
|
-
/** Every indexable page of the launched site carries `og:url` and `og:image`, absolute
|
|
971
|
-
*
|
|
1411
|
+
/** Every indexable page of the launched site carries `og:url` and `og:image`, absolute, and its
|
|
1412
|
+
* `og:url` is its canonical URL: a shared link renders bare without them, and an `og:url` that is
|
|
1413
|
+
* not the canonical one moves the share to another URL than search lists. A warning: a rental
|
|
1414
|
+
* page's image is the feed's first photo. */
|
|
972
1415
|
const openGraph = launchCheck({
|
|
973
1416
|
id: "open-graph",
|
|
974
1417
|
title: "Indexable pages carry a share preview",
|
|
975
1418
|
severity: "warning",
|
|
976
1419
|
stage: "dist"
|
|
977
|
-
}, (page) => {
|
|
978
|
-
const meta = (name) => page.document.querySelector(`meta[property="${name}"], meta[name="${name}"]`)?.getAttribute("content");
|
|
1420
|
+
}, () => (page) => {
|
|
1421
|
+
const meta = (name) => page.document.querySelector(`meta[property="${name}"], meta[name="${name}"]`)?.getAttribute("content")?.trim();
|
|
1422
|
+
const findings = [];
|
|
979
1423
|
const missing = ["og:url", "og:image"].filter((name) => !isAbsolute(meta(name)));
|
|
980
|
-
|
|
1424
|
+
if (missing.length > 0) findings.push({
|
|
981
1425
|
path: page.path,
|
|
982
1426
|
message: `No absolute ${missing.join(" and ")}: a shared link renders without its preview.`
|
|
983
|
-
}
|
|
1427
|
+
});
|
|
1428
|
+
const ogUrl = meta("og:url");
|
|
1429
|
+
const canonical = canonicalOf(page);
|
|
1430
|
+
if (ogUrl && canonical && ogUrl !== canonical) findings.push({
|
|
1431
|
+
path: page.path,
|
|
1432
|
+
message: `og:url "${ogUrl}" is not the canonical URL "${canonical}": a share points at another URL than search lists. Use one value for both.`
|
|
1433
|
+
});
|
|
1434
|
+
return findings;
|
|
984
1435
|
});
|
|
985
1436
|
/** The launched site declares `trailingSlash: "never"`: one URL form everywhere means one CDN rule
|
|
986
1437
|
* set (`/x/` → 301 `/x`) and one redirect-map convention. Unset, the CDN decides per request and
|
|
@@ -991,14 +1442,103 @@ const trailingSlash = {
|
|
|
991
1442
|
title: "The site declares trailingSlash \"never\"",
|
|
992
1443
|
severity: "warning",
|
|
993
1444
|
stage: "dist",
|
|
1445
|
+
begin: (ctx) => ctx.config.trailingSlash === void 0 ? null : whenLaunched(ctx, () => ctx.config.trailingSlash === "never" ? [] : [{ message: `trailingSlash is "${ctx.config.trailingSlash}" in the Astro config: set it to "never" and write internal links without a trailing slash.` }])
|
|
1446
|
+
};
|
|
1447
|
+
//#endregion
|
|
1448
|
+
//#region src/checks/jsonLd.ts
|
|
1449
|
+
const blocksOf = (page) => [...page.document.querySelectorAll("script")].filter((s) => s.getAttribute("type")?.trim().toLowerCase() === "application/ld+json").map((s) => s.textContent ?? "");
|
|
1450
|
+
/** The blocks of a page that parse; the others are `json-ld`'s findings. */
|
|
1451
|
+
const parsedBlocks = (page) => blocksOf(page).flatMap((block) => {
|
|
1452
|
+
try {
|
|
1453
|
+
return [JSON.parse(block)];
|
|
1454
|
+
} catch {
|
|
1455
|
+
return [];
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
/** Every node of a parsed JSON-LD value, `@graph` and nesting included. */
|
|
1459
|
+
const nodesOf = (value, into = []) => {
|
|
1460
|
+
if (Array.isArray(value)) for (const item of value) nodesOf(item, into);
|
|
1461
|
+
else if (typeof value === "object" && value !== null) {
|
|
1462
|
+
const node = value;
|
|
1463
|
+
into.push(node);
|
|
1464
|
+
for (const child of Object.values(node)) nodesOf(child, into);
|
|
1465
|
+
}
|
|
1466
|
+
return into;
|
|
1467
|
+
};
|
|
1468
|
+
/** A schema.org type as JSON-LD may write it: compact (`VacationRental`), prefixed
|
|
1469
|
+
* (`schema:VacationRental`) or as its IRI (`https://schema.org/VacationRental`). */
|
|
1470
|
+
const SCHEMA_PREFIX = /^(?:https?:\/\/schema\.org\/|schema:)/;
|
|
1471
|
+
const hasType = (node, type) => [node["@type"]].flat().some((t) => typeof t === "string" && t.replace(SCHEMA_PREFIX, "") === type);
|
|
1472
|
+
/** Every JSON-LD block of every page parses: a reader drops a block it cannot parse whole, and
|
|
1473
|
+
* says nothing. A JSON-LD block is the site's code (`JSON.stringify` of an object never fails to
|
|
1474
|
+
* parse), so it refuses the build. */
|
|
1475
|
+
const jsonLd = {
|
|
1476
|
+
id: "json-ld",
|
|
1477
|
+
title: "JSON-LD blocks parse",
|
|
1478
|
+
severity: "error",
|
|
1479
|
+
stage: "dist",
|
|
1480
|
+
begin: (ctx) => {
|
|
1481
|
+
if (!ctx.hasDist) return null;
|
|
1482
|
+
const findings = [];
|
|
1483
|
+
return {
|
|
1484
|
+
visit: (page) => {
|
|
1485
|
+
for (const block of blocksOf(page)) try {
|
|
1486
|
+
JSON.parse(block);
|
|
1487
|
+
} catch (err) {
|
|
1488
|
+
findings.push({
|
|
1489
|
+
path: page.path,
|
|
1490
|
+
message: `A JSON-LD block does not parse (${err.message}): every reader drops it. Build it from an object with JSON.stringify, never by joining strings.`
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
},
|
|
1494
|
+
finish: () => findings
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
/** Every indexable rental page of the launched site carries `VacationRental` JSON-LD: search
|
|
1499
|
+
* engines and assistants read a rental's facts from it. The page is the site's (the rental blocks'
|
|
1500
|
+
* `data-rental-stats` marker); the markup is the site's code. A site launching without it on
|
|
1501
|
+
* purpose excludes `rental-markup`, with the reason. */
|
|
1502
|
+
const rentalMarkup = launchCheck({
|
|
1503
|
+
id: "rental-markup",
|
|
1504
|
+
title: "Rental pages carry VacationRental markup",
|
|
1505
|
+
severity: "error",
|
|
1506
|
+
stage: "dist"
|
|
1507
|
+
}, () => (page) => {
|
|
1508
|
+
if (!isRentalPage(page.document)) return [];
|
|
1509
|
+
return parsedBlocks(page).flatMap((block) => nodesOf(block)).some((node) => hasType(node, "VacationRental")) ? [] : [{
|
|
1510
|
+
path: page.path,
|
|
1511
|
+
message: "A rental page without VacationRental JSON-LD: search engines and assistants find none of its facts. Render the rental's VacationRental block from the feed's values."
|
|
1512
|
+
}];
|
|
1513
|
+
});
|
|
1514
|
+
/** Every item of a `BreadcrumbList` on the site's own origin points at a page of the build. A
|
|
1515
|
+
* warning: the trail of a rental page follows the feed. */
|
|
1516
|
+
const breadcrumbs = {
|
|
1517
|
+
id: "breadcrumbs",
|
|
1518
|
+
title: "Breadcrumb items point at built pages",
|
|
1519
|
+
severity: "warning",
|
|
1520
|
+
stage: "dist",
|
|
994
1521
|
begin: (ctx) => {
|
|
995
|
-
if (!ctx.hasDist
|
|
996
|
-
|
|
1522
|
+
if (!ctx.hasDist) return null;
|
|
1523
|
+
const origin = ctx.config.site ? new URL(ctx.config.site).origin : void 0;
|
|
1524
|
+
const findings = [];
|
|
997
1525
|
return {
|
|
998
1526
|
visit: (page) => {
|
|
999
|
-
|
|
1527
|
+
const lists = parsedBlocks(page).flatMap((block) => nodesOf(block)).filter((node) => hasType(node, "BreadcrumbList"));
|
|
1528
|
+
for (const list of lists) {
|
|
1529
|
+
const items = Array.isArray(list.itemListElement) ? list.itemListElement : [];
|
|
1530
|
+
for (const element of items) {
|
|
1531
|
+
const item = element?.item;
|
|
1532
|
+
const url = typeof item === "string" ? item : item?.["@id"];
|
|
1533
|
+
if (typeof url !== "string" || !isSameSiteReference(url, origin)) continue;
|
|
1534
|
+
if (!ctx.serves(resolveReference(page, url))) findings.push({
|
|
1535
|
+
path: page.path,
|
|
1536
|
+
message: `A breadcrumb item points at ${url}, which no page of the build serves.`
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1000
1540
|
},
|
|
1001
|
-
finish: () =>
|
|
1541
|
+
finish: () => findings
|
|
1002
1542
|
};
|
|
1003
1543
|
}
|
|
1004
1544
|
};
|
|
@@ -1010,39 +1550,45 @@ const trailingSlash = {
|
|
|
1010
1550
|
const LIST_CONTAINER = "[data-prerendered-results]";
|
|
1011
1551
|
/** The live search island; a page that mounts it lists rentals, container or not. */
|
|
1012
1552
|
const LIST_ISLAND = "SearchResults";
|
|
1013
|
-
/**
|
|
1014
|
-
*
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
|
|
1553
|
+
/** The favourites grid is the search island over the visitor's saved list, empty in the build and
|
|
1554
|
+
* rightly noindex: the kits' `window.__favoritesMode = true`, website-components' root
|
|
1555
|
+
* `data-search-scope="favorites"` when rendered on the server, its `scope={{ favorites: true }}`
|
|
1556
|
+
* prop (Astro serializes it `"favorites":[0,true]`) when client-only. */
|
|
1557
|
+
const FAVOURITES_FLAG = /__favoritesMode\s*=\s*true/;
|
|
1558
|
+
const FAVOURITES_SCOPE = "[data-search-scope=\"favorites\"]";
|
|
1559
|
+
const FAVOURITES_PROP = /"favorites":\[0,true\]/;
|
|
1560
|
+
const isFavourites = (page, islands) => !!page.document.querySelector(FAVOURITES_SCOPE) || islands.some((island) => FAVOURITES_PROP.test(island.getAttribute("props") ?? "")) || [...page.document.querySelectorAll("script:not([src])")].some((script) => FAVOURITES_FLAG.test(script.textContent ?? ""));
|
|
1561
|
+
/** The page as a listing, when it is one: its markup marks it, or `listingPages` names it; never a
|
|
1562
|
+
* rental page or the favourites grid. Links are those of the list's own markup: the container,
|
|
1563
|
+
* else what the island rendered on the server (a client-only island renders nothing). A page known
|
|
1564
|
+
* only from `listingPages` has neither, and its header, navigation and footer links are not a
|
|
1565
|
+
* list either. */
|
|
1566
|
+
const asListing = (configured, page) => {
|
|
1567
|
+
if (page.redirect || isRentalPage(page.document)) return null;
|
|
1025
1568
|
const container = page.document.querySelector(LIST_CONTAINER);
|
|
1026
1569
|
const islands = [...page.document.querySelectorAll("astro-island")].filter((el) => (el.getAttribute("component-url") ?? "").includes(LIST_ISLAND));
|
|
1027
|
-
const url = normalize
|
|
1570
|
+
const url = normalize(page.url);
|
|
1028
1571
|
if (!container && islands.length === 0 && !configured.has(url)) return null;
|
|
1572
|
+
if (isFavourites(page, islands)) return null;
|
|
1029
1573
|
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"));
|
|
1030
1574
|
const links = /* @__PURE__ */ new Set();
|
|
1031
1575
|
for (const a of anchors) {
|
|
1032
1576
|
const href = a.getAttribute("href") ?? "";
|
|
1033
1577
|
if (/^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("#")) continue;
|
|
1034
|
-
|
|
1035
|
-
if (target !== url && ctx.serves(target)) links.add(target);
|
|
1578
|
+
links.add(normalize(new URL(href, `http://site.invalid${page.base}`).pathname));
|
|
1036
1579
|
}
|
|
1037
1580
|
return {
|
|
1038
1581
|
path: page.path,
|
|
1039
1582
|
url,
|
|
1040
|
-
links
|
|
1583
|
+
links
|
|
1041
1584
|
};
|
|
1042
1585
|
};
|
|
1586
|
+
/** `listingClientOnly`'s paths: a listing whose list is the rentals free in a window is exempt
|
|
1587
|
+
* from both rules, as `scripts/listing-links.allow` exempted it. */
|
|
1588
|
+
const clientOnlyOf = (ctx) => new Set(ctx.options.listingClientOnly.map((c) => normalize(c.path)));
|
|
1043
1589
|
/** Every page that lists rentals is indexable: a hidden listing hides its rentals with it. The
|
|
1044
|
-
* site's own noindex routes decide this, not the feed, so it refuses the build. Skipped while
|
|
1045
|
-
*
|
|
1590
|
+
* site's own noindex routes decide this, not the feed, so it refuses the build. Skipped while no
|
|
1591
|
+
* page is indexable (a site before launch; its 404 page and redirect stubs do not count). */
|
|
1046
1592
|
const listingNoindex = {
|
|
1047
1593
|
id: "listing-noindex",
|
|
1048
1594
|
title: "Rental listings are indexable",
|
|
@@ -1050,26 +1596,28 @@ const listingNoindex = {
|
|
|
1050
1596
|
stage: "dist",
|
|
1051
1597
|
begin: (ctx) => {
|
|
1052
1598
|
if (!ctx.hasDist) return null;
|
|
1053
|
-
const configured = new Set(ctx.options.listingPages.map(normalize
|
|
1599
|
+
const configured = new Set(ctx.options.listingPages.map(normalize));
|
|
1600
|
+
const clientOnly = clientOnlyOf(ctx);
|
|
1054
1601
|
const hidden = [];
|
|
1055
|
-
let
|
|
1602
|
+
let launched = false;
|
|
1056
1603
|
return {
|
|
1057
1604
|
visit: (page) => {
|
|
1058
|
-
if (page
|
|
1059
|
-
if (!page.noindex)
|
|
1060
|
-
|
|
1605
|
+
if (isIndexable(page)) launched = true;
|
|
1606
|
+
if (!page.noindex) return;
|
|
1607
|
+
const listing = asListing(configured, page);
|
|
1608
|
+
if (listing && !clientOnly.has(listing.url)) hidden.push(listing.path);
|
|
1061
1609
|
},
|
|
1062
|
-
finish: () =>
|
|
1610
|
+
finish: () => launched ? hidden.map((path) => ({
|
|
1063
1611
|
path,
|
|
1064
1612
|
message: "A page that lists rentals is noindex; the rentals it lists are hidden with it. Take it out of the noindex routes."
|
|
1065
|
-
}))
|
|
1613
|
+
})) : []
|
|
1066
1614
|
};
|
|
1067
1615
|
}
|
|
1068
1616
|
};
|
|
1069
|
-
/** Every page that lists rentals carries links to
|
|
1070
|
-
* JavaScript otherwise sees an empty list. A warning: the links come from the PMS feed,
|
|
1071
|
-
* empty or booked-out feed must not stop the nightly builds that update prices.
|
|
1072
|
-
*
|
|
1617
|
+
/** Every page that lists rentals carries links to rental pages in its built HTML; a crawler
|
|
1618
|
+
* without JavaScript otherwise sees an empty list. A warning: the links come from the PMS feed,
|
|
1619
|
+
* and an empty or booked-out feed must not stop the nightly builds that update prices. Skipped
|
|
1620
|
+
* while the build has no rental page (a starter with an empty feed). */
|
|
1073
1621
|
const listingLinks = {
|
|
1074
1622
|
id: "listing-links",
|
|
1075
1623
|
title: "Rental listings reach crawlers",
|
|
@@ -1077,21 +1625,21 @@ const listingLinks = {
|
|
|
1077
1625
|
stage: "dist",
|
|
1078
1626
|
begin: (ctx) => {
|
|
1079
1627
|
if (!ctx.hasDist) return null;
|
|
1080
|
-
const configured = new Set(ctx.options.listingPages.map(normalize
|
|
1081
|
-
const clientOnly =
|
|
1628
|
+
const configured = new Set(ctx.options.listingPages.map(normalize));
|
|
1629
|
+
const clientOnly = clientOnlyOf(ctx);
|
|
1082
1630
|
const listings = [];
|
|
1083
|
-
|
|
1631
|
+
const rentals = /* @__PURE__ */ new Set();
|
|
1084
1632
|
return {
|
|
1085
1633
|
visit: (page) => {
|
|
1086
1634
|
if (page.redirect) return;
|
|
1087
|
-
|
|
1088
|
-
const listing = asListing(
|
|
1089
|
-
if (listing) listings.push(listing);
|
|
1635
|
+
if (isRentalPage(page.document)) rentals.add(normalize(page.url));
|
|
1636
|
+
const listing = asListing(configured, page);
|
|
1637
|
+
if (listing && !clientOnly.has(listing.url)) listings.push(listing);
|
|
1090
1638
|
},
|
|
1091
1639
|
finish: () => {
|
|
1092
1640
|
const findings = [];
|
|
1093
|
-
if (
|
|
1094
|
-
for (const listing of listings) if (listing.links
|
|
1641
|
+
if (rentals.size === 0) return findings;
|
|
1642
|
+
for (const listing of listings) if (![...listing.links].some((link) => rentals.has(link))) findings.push({
|
|
1095
1643
|
path: listing.path,
|
|
1096
1644
|
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."
|
|
1097
1645
|
});
|
|
@@ -1142,12 +1690,36 @@ const STATIC_IMPORT = /(?:^|[;\n}])\s*(?:import|export)\s*(?:[\w$*{},\s]*?from\s
|
|
|
1142
1690
|
const INLINE_IMPORT = /(?:import|from)\s*["'](\/[^"']+\.js)["']/g;
|
|
1143
1691
|
/** Nothing under these is fetched at start: template content, a closed dialog, a hidden subtree. */
|
|
1144
1692
|
const INERT = "template, dialog, [hidden]";
|
|
1145
|
-
|
|
1693
|
+
/** A swipe strip, under any variant (`md:overflow-x-auto`). */
|
|
1694
|
+
const STRIP_CLASS = /\b(?:snap-x|overflow-x-(?:auto|scroll))\b/;
|
|
1695
|
+
/** What hides a stacked slide while it still lies in the viewport, so `loading="lazy"` fetches it:
|
|
1696
|
+
* the class, or a breakpoint's (`md:opacity-0` hides it there, fetched all the same); never a state
|
|
1697
|
+
* variant, which is visible until hovered or focused (`group-hover:opacity-0`). */
|
|
1698
|
+
const SHUT_CLASS = /(?:^|\s)(?:(?:sm|md|lg|xl|2xl|max-[a-z0-9]+):)*(?:invisible|opacity-0)(?=\s|$)/;
|
|
1699
|
+
/** An icon is no slide: a decorative SVG under `aria-hidden` sits in a hero's badges and links. */
|
|
1700
|
+
const ICON_URL = /\.svg(?:[?#]|$)/i;
|
|
1146
1701
|
const few = (pages) => {
|
|
1147
1702
|
const list = [...pages];
|
|
1148
1703
|
return list.slice(0, 3).join(", ") + (list.length > 3 ? ` (+${list.length - 3} more)` : "");
|
|
1149
1704
|
};
|
|
1150
1705
|
const add = (map, key, page) => map.set(key, (map.get(key) ?? /* @__PURE__ */ new Set()).add(page));
|
|
1706
|
+
/** A same-site URL as a file of the build; null for another host. */
|
|
1707
|
+
const toFile = (url) => url?.startsWith("/") ? (url.split(/[?#]/, 1)[0] ?? "").replace(/^\/+/, "") : null;
|
|
1708
|
+
/** A URL a browser fetches, not a `data:` stand-in. */
|
|
1709
|
+
const live = (url) => url && /^(?!data:)\S/.test(url) ? url : null;
|
|
1710
|
+
const firstCandidate = (srcset) => srcset?.trim().split(/[\s,]/, 1)[0];
|
|
1711
|
+
/** The file a current browser takes for an `<img>` in a `<picture>`: the first `<source>`'s. */
|
|
1712
|
+
const sourceUrl = (img) => firstCandidate(img.closest("picture")?.querySelector("source[srcset]")?.getAttribute("srcset"));
|
|
1713
|
+
/** An ancestor of `img`, up to and including `block`, hides it: out of the accessibility tree,
|
|
1714
|
+
* inert, shut by a class, or not rendered (`hidden`, a closed `<dialog>`; an eager image there is
|
|
1715
|
+
* fetched all the same). */
|
|
1716
|
+
const hiddenWithin = (img, block) => {
|
|
1717
|
+
for (let el = img.parentElement; el; el = el.parentElement) {
|
|
1718
|
+
if (el.getAttribute("aria-hidden") === "true" || el.hasAttribute("inert") || el.hasAttribute("hidden") || el.tagName === "DIALOG" && !el.hasAttribute("open") || SHUT_CLASS.test(el.getAttribute("class") ?? "")) return true;
|
|
1719
|
+
if (el === block) return false;
|
|
1720
|
+
}
|
|
1721
|
+
return false;
|
|
1722
|
+
};
|
|
1151
1723
|
/** What a built page fetches at start on a slow phone, where each of these costs seconds before
|
|
1152
1724
|
* the largest picture paints and no other check sees it:
|
|
1153
1725
|
* - an on-demand library (a map engine, a chart library) in the start-up code: module scripts and
|
|
@@ -1155,9 +1727,9 @@ const add = (map, key, page) => map.set(key, (map.get(key) ?? /* @__PURE__ */ ne
|
|
|
1155
1727
|
* statically;
|
|
1156
1728
|
* - on a page with two or more card swipe strips, a photo after a strip's first carrying a URL
|
|
1157
1729
|
* (native lazy loading reaches sideways on slow links);
|
|
1158
|
-
* - a
|
|
1159
|
-
*
|
|
1160
|
-
* A warning: each is a cost, not a fault. */
|
|
1730
|
+
* - a `font-display: swap` face without a `size-adjust` stand-in behind it, which reflows the line
|
|
1731
|
+
* (a preloaded one at first paint; one not preloaded, likely below the fold, named apart).
|
|
1732
|
+
* A warning: each is a cost, not a fault. The first-paint photo rules are `first-paint-photos`. */
|
|
1161
1733
|
const loadOrder = {
|
|
1162
1734
|
id: "load-order",
|
|
1163
1735
|
title: "What pages load at start",
|
|
@@ -1182,12 +1754,11 @@ const loadOrder = {
|
|
|
1182
1754
|
}
|
|
1183
1755
|
return known;
|
|
1184
1756
|
};
|
|
1185
|
-
const toFile = (url) => url?.startsWith("/") ? (url.split(/[?#]/, 1)[0] ?? "").replace(/^\/+/, "") : null;
|
|
1186
1757
|
const libraries = /* @__PURE__ */ new Map();
|
|
1187
1758
|
const large = /* @__PURE__ */ new Map();
|
|
1188
1759
|
const strips = /* @__PURE__ */ new Map();
|
|
1189
|
-
const oneSize = /* @__PURE__ */ new Map();
|
|
1190
1760
|
const faces = /* @__PURE__ */ new Map();
|
|
1761
|
+
const lateFaces = /* @__PURE__ */ new Map();
|
|
1191
1762
|
const startup = (page) => {
|
|
1192
1763
|
const roots = /* @__PURE__ */ new Set();
|
|
1193
1764
|
for (const script of page.document.querySelectorAll("script[type=\"module\"]")) {
|
|
@@ -1224,34 +1795,14 @@ const loadOrder = {
|
|
|
1224
1795
|
let count = 0;
|
|
1225
1796
|
for (const strip of page.document.querySelectorAll("[class]")) {
|
|
1226
1797
|
if (!STRIP_CLASS.test(strip.getAttribute("class") ?? "") || strip.closest(INERT)) continue;
|
|
1227
|
-
const
|
|
1228
|
-
if (
|
|
1798
|
+
const fetched = [...strip.querySelectorAll("img")].filter((img) => !img.closest(INERT)).slice(1).filter((img) => live(img.getAttribute("src")) ?? live(img.getAttribute("srcset")));
|
|
1799
|
+
if (fetched.length > 0) {
|
|
1229
1800
|
count += 1;
|
|
1230
|
-
extra +=
|
|
1801
|
+
extra += fetched.length;
|
|
1231
1802
|
}
|
|
1232
1803
|
}
|
|
1233
1804
|
if (count >= 2) strips.set(page.path, extra);
|
|
1234
1805
|
};
|
|
1235
|
-
const sizeKb = (url) => {
|
|
1236
|
-
const file = toFile(url);
|
|
1237
|
-
if (!file || !ctx.has(file)) return null;
|
|
1238
|
-
return fs.statSync(path.join(ctx.distDir, decodeURI(file))).size / 1024;
|
|
1239
|
-
};
|
|
1240
|
-
const widths = (el) => [el, ...el.querySelectorAll("[srcset]")].some((node) => ((node.getAttribute("srcset") ?? "").match(/\s\d+w\b/g) ?? []).length >= 2);
|
|
1241
|
-
const oneSizePhotos = (page) => {
|
|
1242
|
-
const note = (url) => {
|
|
1243
|
-
const kb = sizeKb(url);
|
|
1244
|
-
if (kb !== null && kb >= ONE_SIZE_KB) add(oneSize, `${url} (${Math.round(kb)} KB)`, page.path);
|
|
1245
|
-
};
|
|
1246
|
-
for (const link of page.document.querySelectorAll("link[rel=\"preload\"][as=\"image\"]")) if (!link.hasAttribute("imagesrcset")) note(link.getAttribute("href"));
|
|
1247
|
-
for (const img of page.document.querySelectorAll("img")) {
|
|
1248
|
-
if (img.closest(INERT) || img.getAttribute("loading") === "lazy") continue;
|
|
1249
|
-
const picture = img.closest("picture");
|
|
1250
|
-
if (widths(picture ?? img)) continue;
|
|
1251
|
-
const first = picture?.querySelector("source[srcset]")?.getAttribute("srcset")?.trim().split(/[\s,]/, 1)[0];
|
|
1252
|
-
note(first ?? img.getAttribute("src"));
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
1806
|
const sheets = /* @__PURE__ */ new Map();
|
|
1256
1807
|
const sheet = (file) => {
|
|
1257
1808
|
if (!sheets.has(file)) sheets.set(file, ctx.has(file) ? ctx.read(file) : "");
|
|
@@ -1283,8 +1834,8 @@ const loadOrder = {
|
|
|
1283
1834
|
const adjusted = new Set(declared.filter((f) => f.adjusted).map((f) => f.family));
|
|
1284
1835
|
const stacks = [...css.replace(/@font-face\s*\{[^}]*\}/g, "").matchAll(/font-family:\s*([^;}]+)/g)].map((m) => m[1].split(",").map((s) => s.trim().replace(/^["']|["']$/g, "")));
|
|
1285
1836
|
const preloaded = new Set([...page.document.querySelectorAll("link[rel=\"preload\"][href]")].map((l) => resolve(l.getAttribute("href"), page.base)));
|
|
1286
|
-
for (const face of declared) if (face.swap && !face.adjusted
|
|
1287
|
-
if (stacks.filter((stack) => stack[0] === face.family).some((stack) => !adjusted.has(stack[1] ?? ""))) add(faces, face.family, page.path);
|
|
1837
|
+
for (const face of declared) if (face.swap && !face.adjusted) {
|
|
1838
|
+
if (stacks.filter((stack) => stack[0] === face.family).some((stack) => !adjusted.has(stack[1] ?? ""))) add(face.file && preloaded.has(face.file) ? faces : lateFaces, face.family, page.path);
|
|
1288
1839
|
}
|
|
1289
1840
|
};
|
|
1290
1841
|
return {
|
|
@@ -1292,7 +1843,6 @@ const loadOrder = {
|
|
|
1292
1843
|
if (page.redirect) return;
|
|
1293
1844
|
startup(page);
|
|
1294
1845
|
swipeStrips(page);
|
|
1295
|
-
oneSizePhotos(page);
|
|
1296
1846
|
swappedFaces(page);
|
|
1297
1847
|
},
|
|
1298
1848
|
finish: () => {
|
|
@@ -1303,108 +1853,402 @@ const loadOrder = {
|
|
|
1303
1853
|
path: page,
|
|
1304
1854
|
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.`
|
|
1305
1855
|
});
|
|
1306
|
-
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.` });
|
|
1307
1856
|
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.` });
|
|
1857
|
+
for (const [family, pages] of lateFaces) if (!faces.has(family)) findings.push({ message: `The face "${family}" swaps in without a width-matched stand-in (size-adjust) behind it, on ${few(pages)}; not preloaded, so likely below the fold. A local() stand-in with size-adjust right after it in the stack keeps the line from moving.` });
|
|
1308
1858
|
return findings;
|
|
1309
1859
|
}
|
|
1310
1860
|
};
|
|
1311
1861
|
}
|
|
1312
1862
|
};
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
*
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
};
|
|
1326
|
-
/** `https://www.example.de/a/` and `/a/` → `/a`. */
|
|
1327
|
-
const toPath = (loc) => {
|
|
1328
|
-
const value = loc.trim();
|
|
1329
|
-
try {
|
|
1330
|
-
return normalize(new URL(value).pathname);
|
|
1331
|
-
} catch {
|
|
1332
|
-
return normalize(value);
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
const locs = (xml) => [...xml.matchAll(/<loc>\s*([^<]+?)\s*<\/loc>/g)].map((m) => xmlText(m[1]));
|
|
1336
|
-
/** The URL lists the build publishes agree with the pages it built: no sitemap entry whose own page
|
|
1337
|
-
* says noindex or is not in the build, no `llms.txt` link to a page that is not there. Skipped when
|
|
1338
|
-
* the build publishes neither. While every page is noindex (a site before launch, under its blanket
|
|
1339
|
-
* robots meta), a sitemap listing them is not refused: that disagreement ends with the launch. */
|
|
1340
|
-
const sitemapNoindex = {
|
|
1341
|
-
id: "sitemap-noindex",
|
|
1342
|
-
title: "Published URL lists match the built pages",
|
|
1863
|
+
/** The photos of the first paint, the site's own markup in both rules, so they refuse the build:
|
|
1864
|
+
* - a first-paint photo (not lazy) or an image preload from 100 KB up in one size only, without a
|
|
1865
|
+
* width `srcset` (`imagesrcset` on the preload). Only a file of the build is measured, a photo
|
|
1866
|
+
* the site serves itself; the feed's photos come from the PMS hosts and are never weighed;
|
|
1867
|
+
* - in the block (innermost `<header>`/`<section>`) holding the `fetchpriority="high"` photo, a
|
|
1868
|
+
* hidden slide carrying a URL: an image under `aria-hidden="true"`, `inert`, `invisible` or
|
|
1869
|
+
* `opacity-0`. Stacked slides lie in the viewport, so `loading="lazy"` fetches them at once,
|
|
1870
|
+
* beside the first one; the hidden marking is what tells a slideshow from a gallery.
|
|
1871
|
+
* Nothing under `<template>`, `<dialog>` or `hidden` counts: it is not fetched. */
|
|
1872
|
+
const firstPaintPhotos = {
|
|
1873
|
+
id: "first-paint-photos",
|
|
1874
|
+
title: "First-paint photos",
|
|
1343
1875
|
severity: "error",
|
|
1344
1876
|
stage: "dist",
|
|
1345
1877
|
begin: (ctx) => {
|
|
1346
1878
|
if (!ctx.hasDist) return null;
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1879
|
+
const oneSize = /* @__PURE__ */ new Map();
|
|
1880
|
+
const slides = /* @__PURE__ */ new Map();
|
|
1881
|
+
const sizeKb = (url) => {
|
|
1882
|
+
const file = toFile(url);
|
|
1883
|
+
if (!file || !ctx.has(file)) return null;
|
|
1884
|
+
return fs.statSync(path.join(ctx.distDir, decodeURI(file))).size / 1024;
|
|
1885
|
+
};
|
|
1886
|
+
const widths = (el) => [el, ...el.querySelectorAll("[srcset]")].some((node) => ((node.getAttribute("srcset") ?? "").match(/\s\d+w\b/g) ?? []).length >= 2);
|
|
1887
|
+
const oneSizePhotos = (page) => {
|
|
1888
|
+
const note = (url) => {
|
|
1889
|
+
const kb = sizeKb(url);
|
|
1890
|
+
if (kb !== null && kb >= ONE_SIZE_KB) add(oneSize, `${url} (${Math.round(kb)} KB)`, page.path);
|
|
1891
|
+
};
|
|
1892
|
+
for (const link of page.document.querySelectorAll("link[rel=\"preload\"][as=\"image\"]")) if (!link.hasAttribute("imagesrcset")) note(link.getAttribute("href"));
|
|
1893
|
+
for (const img of page.document.querySelectorAll("img")) {
|
|
1894
|
+
if (img.closest(INERT) || img.getAttribute("loading") === "lazy") continue;
|
|
1895
|
+
const picture = img.closest("picture");
|
|
1896
|
+
if (widths(picture ?? img)) continue;
|
|
1897
|
+
note(sourceUrl(img) ?? img.getAttribute("src"));
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
const hiddenSlides = (page) => {
|
|
1901
|
+
const lcp = [...page.document.querySelectorAll("img[fetchpriority=\"high\"]")].find((img) => !img.closest(INERT));
|
|
1902
|
+
const block = lcp?.closest("header, section");
|
|
1903
|
+
if (!lcp || !block) return;
|
|
1904
|
+
for (const img of block.querySelectorAll("img")) {
|
|
1905
|
+
if (img === lcp || img.closest("template")) continue;
|
|
1906
|
+
if (img.closest(INERT) && img.getAttribute("loading") === "lazy") continue;
|
|
1907
|
+
if (!hiddenWithin(img, block)) continue;
|
|
1908
|
+
const url = live(sourceUrl(img)) ?? live(img.getAttribute("src")) ?? live(firstCandidate(img.getAttribute("srcset")));
|
|
1909
|
+
if (url && !ICON_URL.test(url)) add(slides, url, page.path);
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
return {
|
|
1913
|
+
visit: (page) => {
|
|
1914
|
+
if (page.redirect) return;
|
|
1915
|
+
oneSizePhotos(page);
|
|
1916
|
+
hiddenSlides(page);
|
|
1917
|
+
},
|
|
1918
|
+
finish: () => {
|
|
1358
1919
|
const findings = [];
|
|
1359
|
-
const
|
|
1360
|
-
for (const [
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1920
|
+
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.` });
|
|
1921
|
+
for (const [url, pages] of slides) findings.push({ message: `${url} sits in a hidden slide beside the first-paint photo and loads at start, on ${few(pages)}. Ship hidden slides without src/srcset (data-src, data-srcset) and hand each its URL after the page has loaded; loading="lazy" fetches stacked slides at once.` });
|
|
1922
|
+
return findings;
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
//#endregion
|
|
1928
|
+
//#region src/checks/orphanPages.ts
|
|
1929
|
+
/** Every indexable page but the home page is linked from another page of the build, in its HTML: a
|
|
1930
|
+
* page only the sitemap reaches reads as unimportant to a crawler. Links an island renders in the
|
|
1931
|
+
* browser do not count, which is the point: a crawler that runs no JavaScript sees none of them. A
|
|
1932
|
+
* warning: rental pages are linked from listings the feed fills. */
|
|
1933
|
+
const orphanPages = {
|
|
1934
|
+
id: "orphan-pages",
|
|
1935
|
+
title: "Indexable pages are linked from another page",
|
|
1936
|
+
severity: "warning",
|
|
1937
|
+
stage: "dist",
|
|
1938
|
+
begin: (ctx) => {
|
|
1939
|
+
if (!ctx.hasDist) return null;
|
|
1940
|
+
const origin = ctx.config.site ? new URL(ctx.config.site).origin : void 0;
|
|
1941
|
+
const linked = /* @__PURE__ */ new Set();
|
|
1942
|
+
const pages = [];
|
|
1943
|
+
return {
|
|
1944
|
+
visit: (page) => {
|
|
1945
|
+
const own = normalize(page.url);
|
|
1946
|
+
for (const a of page.document.querySelectorAll("a[href]")) {
|
|
1947
|
+
const href = a.getAttribute("href") ?? "";
|
|
1948
|
+
if (!isSameSiteReference(href, origin)) continue;
|
|
1949
|
+
const target = normalize(resolveReference(page, href));
|
|
1950
|
+
if (target !== own) linked.add(target);
|
|
1387
1951
|
}
|
|
1388
|
-
if (
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1952
|
+
if (isIndexable(page) && own !== "/") pages.push({
|
|
1953
|
+
path: page.path,
|
|
1954
|
+
url: own
|
|
1955
|
+
});
|
|
1956
|
+
},
|
|
1957
|
+
finish: () => pages.filter((p) => !linked.has(p.url)).map((p) => ({
|
|
1958
|
+
path: p.path,
|
|
1959
|
+
message: `No other page links to ${p.url} in its HTML: link it from a page a crawler reaches (navigation, a listing, the footer).`
|
|
1960
|
+
}))
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
//#endregion
|
|
1965
|
+
//#region src/siteTexts.ts
|
|
1966
|
+
const CODE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1967
|
+
".ts",
|
|
1968
|
+
".tsx",
|
|
1969
|
+
".jsx",
|
|
1970
|
+
".astro",
|
|
1971
|
+
".mjs",
|
|
1972
|
+
".js"
|
|
1973
|
+
]);
|
|
1974
|
+
const OWN_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
1975
|
+
".astro",
|
|
1976
|
+
".ts",
|
|
1977
|
+
".tsx",
|
|
1978
|
+
".jsx",
|
|
1979
|
+
".js",
|
|
1980
|
+
".mjs",
|
|
1981
|
+
".md",
|
|
1982
|
+
".mdx",
|
|
1983
|
+
".html",
|
|
1984
|
+
".json",
|
|
1985
|
+
".yml",
|
|
1986
|
+
".yaml"
|
|
1987
|
+
]);
|
|
1988
|
+
const filesOf = (ctx, extensions) => ctx.sourceFiles(extensions).filter((file) => !file.endsWith(".d.ts"));
|
|
1989
|
+
const lineAt = (text, index) => text.slice(0, index).split("\n").length;
|
|
1990
|
+
/** The code of the value that starts at `start`: up to the comma or closing bracket at its own
|
|
1991
|
+
* depth, quotes respected. */
|
|
1992
|
+
const valueAt = (src, start) => {
|
|
1993
|
+
let depth = 0;
|
|
1994
|
+
let quote = null;
|
|
1995
|
+
for (let j = start; j < src.length; j += 1) {
|
|
1996
|
+
const c = src[j];
|
|
1997
|
+
if (quote) {
|
|
1998
|
+
if (c === "\\") j += 1;
|
|
1999
|
+
else if (c === quote) quote = null;
|
|
2000
|
+
continue;
|
|
2001
|
+
}
|
|
2002
|
+
if (c === "\"" || c === "'" || c === "`") quote = c;
|
|
2003
|
+
else if ("([{".includes(c)) depth += 1;
|
|
2004
|
+
else if (")]}".includes(c)) {
|
|
2005
|
+
if (depth === 0) return src.slice(start, j);
|
|
2006
|
+
depth -= 1;
|
|
2007
|
+
} else if (c === "," && depth === 0) return src.slice(start, j);
|
|
2008
|
+
}
|
|
2009
|
+
return src.slice(start);
|
|
2010
|
+
};
|
|
2011
|
+
const LITERAL = /"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)'|`((?:[^`\\]|\\.)*)`/g;
|
|
2012
|
+
const ESCAPES = {
|
|
2013
|
+
n: "\n",
|
|
2014
|
+
r: "\r",
|
|
2015
|
+
t: " ",
|
|
2016
|
+
b: "\b",
|
|
2017
|
+
f: "\f",
|
|
2018
|
+
v: "\v",
|
|
2019
|
+
0: "\0"
|
|
2020
|
+
};
|
|
2021
|
+
const ESCAPE = /\\(u\{[0-9a-fA-F]+\}|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|\r?\n|[\s\S])/g;
|
|
2022
|
+
/** One escape's text (after its backslash): `n` a line break, `u00e4` „ä", a line continuation
|
|
2023
|
+
* nothing. Decoded, never run. */
|
|
2024
|
+
const unescapeOne = (e) => {
|
|
2025
|
+
if (e.startsWith("u") && e.length > 1) return String.fromCodePoint(parseInt(e.startsWith("u{") ? e.slice(2, -1) : e.slice(1), 16));
|
|
2026
|
+
if (/^x[0-9a-fA-F]{2}$/.test(e)) return String.fromCharCode(parseInt(e.slice(1), 16));
|
|
2027
|
+
if (e === "\n" || e === "\r\n") return "";
|
|
2028
|
+
return ESCAPES[e] ?? e;
|
|
2029
|
+
};
|
|
2030
|
+
/** A literal's text as it renders: its escapes decoded (`"Hallo\nSie"` is two lines, and „Sie"
|
|
2031
|
+
* starts the second). */
|
|
2032
|
+
const decode = (raw) => raw.replace(ESCAPE, (_, e) => unescapeOne(e));
|
|
2033
|
+
/** The same, keeping every character's place: each escape becomes its text, padded with the
|
|
2034
|
+
* dropped `\u0000` and keeping its own line break, so a source line still maps to its text. */
|
|
2035
|
+
const decodeInPlace = (raw) => raw.replace(ESCAPE, (seq, e) => {
|
|
2036
|
+
const text = unescapeOne(e).replace(/\s/g, " ");
|
|
2037
|
+
return text + seq.slice(text.length).replace(/[^\n]/g, "\0");
|
|
2038
|
+
});
|
|
2039
|
+
/** Every string literal in the value of a `"<lang>-XX":` key in the site's code: language-kit's
|
|
2040
|
+
* `defineTexts`, `Localized<…>` data. The value is a string, an arrow returning a template, or an
|
|
2041
|
+
* object or array of them. Comments are blanked first (newlines kept, so lines still count): a
|
|
2042
|
+
* wording left in one renders nowhere. */
|
|
2043
|
+
const localizedTexts = (ctx, lang) => {
|
|
2044
|
+
const key = new RegExp(`["']${lang}-[A-Z]{2}["']\\s*:\\s*`, "g");
|
|
2045
|
+
const out = [];
|
|
2046
|
+
for (const file of filesOf(ctx, CODE_EXTENSIONS)) {
|
|
2047
|
+
const src = blankSourceComments(ctx.readSource(file), path.extname(file).toLowerCase());
|
|
2048
|
+
for (const m of src.matchAll(key)) {
|
|
2049
|
+
const start = m.index + m[0].length;
|
|
2050
|
+
const value = valueAt(src, start);
|
|
2051
|
+
for (const lit of value.matchAll(LITERAL)) {
|
|
2052
|
+
const before = value.slice(0, lit.index).trimEnd();
|
|
2053
|
+
const after = value.slice(lit.index + lit[0].length);
|
|
2054
|
+
if (/[{,]$/.test(before) && /^\s*:/.test(after)) continue;
|
|
2055
|
+
out.push({
|
|
2056
|
+
path: `${ctx.rel(file)}:${lineAt(src, start + lit.index)}`,
|
|
2057
|
+
text: decode((lit[1] ?? lit[2] ?? lit[3] ?? "").replace(/\$\{[^}]*\}/g, " "))
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
return out;
|
|
2063
|
+
};
|
|
2064
|
+
/** Files whose strings escape: code, and JSON and YAML data (`"pure\nErholung"`). */
|
|
2065
|
+
const ESCAPING = /* @__PURE__ */ new Set([
|
|
2066
|
+
".ts",
|
|
2067
|
+
".tsx",
|
|
2068
|
+
".jsx",
|
|
2069
|
+
".js",
|
|
2070
|
+
".mjs",
|
|
2071
|
+
".json",
|
|
2072
|
+
".yml",
|
|
2073
|
+
".yaml"
|
|
2074
|
+
]);
|
|
2075
|
+
/** Tags inside a line of text: their words run on (`Ferien<em>wohnung</em>` reads „Ferienwohnung").
|
|
2076
|
+
* Any other tag separates words. */
|
|
2077
|
+
const INLINE_TAGS = new Set("a abbr b bdi bdo cite code data dfn em i kbd mark q s samp small span strong sub sup time u var wbr".split(" "));
|
|
2078
|
+
/** Attributes and props that carry no words a visitor reads. Every other one's value is text: a
|
|
2079
|
+
* `title`, `alt`, `placeholder`, `aria-label`, a component's `heading="…"`. */
|
|
2080
|
+
const TECHNICAL_ATTRIBUTE = /^(?:class|className|style|id|key|ref|href|src|srcset|sizes|type|rel|for|htmlFor|name|role|lang|dir|width|height|loading|decoding|fetchpriority|target|method|action|slot|tabindex|xmlns|viewBox|d|fill|stroke|data-.*|aria-(?!label$).*|on[a-z].*|client:.*|is:.*|set:.*|transition:.*)$/i;
|
|
2081
|
+
/** `name="…"`, `name='…'`, `name={"…"}`: the value's place in the tag (group 2, 3 or 5). */
|
|
2082
|
+
const ATTRIBUTE = /([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|\{\s*(["'`])((?:(?!\4)[^\\]|\\.)*)\4\s*\})/dg;
|
|
2083
|
+
/** A tag as prose: the values of its text-bearing attributes, where they stand, and nothing else.
|
|
2084
|
+
* An inline tag that holds none runs its words on (`Ferien<em>wohnung</em>`); any other tag, or one
|
|
2085
|
+
* that does, separates them. Line breaks are kept. */
|
|
2086
|
+
const flattenTag = (tag, name) => {
|
|
2087
|
+
const keep = Array.from({ length: tag.length }, () => false);
|
|
2088
|
+
for (const m of tag.matchAll(ATTRIBUTE)) {
|
|
2089
|
+
if (TECHNICAL_ATTRIBUTE.test(m[1])) continue;
|
|
2090
|
+
const span = m.indices?.[2] ?? m.indices?.[3] ?? m.indices?.[5];
|
|
2091
|
+
if (span) keep.fill(true, span[0], span[1]);
|
|
2092
|
+
}
|
|
2093
|
+
const filler = INLINE_TAGS.has(name.toLowerCase()) && !keep.includes(true) ? "\0" : " ";
|
|
2094
|
+
return tag.split("").map((c, i) => c === "\n" || keep[i] ? c : filler).join("");
|
|
2095
|
+
};
|
|
2096
|
+
const flatten = (raw, extension) => {
|
|
2097
|
+
const blank = (m) => m.replace(/[^\n]/g, " ");
|
|
2098
|
+
const blanked = blankSourceComments(raw, extension);
|
|
2099
|
+
const s = (ESCAPING.has(extension) ? decodeInPlace(blanked) : blanked).replace(/<!--[\s\S]*?-->/g, blank).replace(/<\/?>/g, blank).replace(/<\/?([A-Za-z][\w.:-]*)[^>]*>/g, (tag, name) => flattenTag(tag, name)).replace(/­|/g, (m) => "\0".repeat(m.length)).replace(/ /g, " ");
|
|
2100
|
+
let text = "";
|
|
2101
|
+
let line = 1;
|
|
2102
|
+
const lines = [];
|
|
2103
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
2104
|
+
const c = s[i];
|
|
2105
|
+
if (c === "\n") line += 1;
|
|
2106
|
+
if (c === "\0") continue;
|
|
2107
|
+
if (/\s/.test(c)) {
|
|
2108
|
+
if (text.endsWith(" ")) continue;
|
|
2109
|
+
text += " ";
|
|
2110
|
+
} else text += c;
|
|
2111
|
+
lines.push(line);
|
|
2112
|
+
}
|
|
2113
|
+
return {
|
|
2114
|
+
text,
|
|
2115
|
+
lines
|
|
2116
|
+
};
|
|
2117
|
+
};
|
|
2118
|
+
/** Every text file under `src/` (components, pages, data, Markdown, JSON, YAML), flattened. */
|
|
2119
|
+
const flatSources = (ctx) => filesOf(ctx, OWN_EXTENSIONS).map((file) => ({
|
|
2120
|
+
rel: ctx.rel(file),
|
|
2121
|
+
...flatten(ctx.readSource(file), path.extname(file).toLowerCase())
|
|
2122
|
+
}));
|
|
2123
|
+
//#endregion
|
|
2124
|
+
//#region src/checks/ownCopy.ts
|
|
2125
|
+
/** The copy checks over the site's own words in `src/` (`siteTexts.ts`), never the built pages,
|
|
2126
|
+
* which also print the PMS feed's text: what they find is the site's to fix, so they are errors. */
|
|
2127
|
+
const excerpt$1 = (text, max) => {
|
|
2128
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
2129
|
+
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
2130
|
+
};
|
|
2131
|
+
/** The German words a translation carries over, with the English for them. */
|
|
2132
|
+
const GERMANISMS = [
|
|
2133
|
+
[/—/, "an em dash"],
|
|
2134
|
+
[/\bImprint\b/, "Imprint (write Legal notice)"],
|
|
2135
|
+
[/\bGTC\b/, "GTC (write Terms and conditions)"],
|
|
2136
|
+
[/\bfinal cleaning\b/i, "final cleaning (write Cleaning fee)"],
|
|
2137
|
+
[/\bvacation (?:apartment|house|flat)s?\b/i, "vacation apartment/house (write Apartment, House, vacation rental)"],
|
|
2138
|
+
[/\bpictures?\b/i, "pictures (write Photos)"],
|
|
2139
|
+
[/\baccommodations\b/i, "accommodations (write stays or properties)"]
|
|
2140
|
+
];
|
|
2141
|
+
/** Every `"en-XX"` text the site writes: no em dash, none of the Germanisms above. */
|
|
2142
|
+
const copyEnglish = {
|
|
2143
|
+
id: "copy-english",
|
|
2144
|
+
title: "The site's English texts read as English",
|
|
2145
|
+
severity: "error",
|
|
2146
|
+
stage: "src",
|
|
2147
|
+
begin: (ctx) => ({ finish: () => {
|
|
2148
|
+
const findings = [];
|
|
2149
|
+
for (const { path, text } of localizedTexts(ctx, "en")) {
|
|
2150
|
+
if (!/[A-Za-z]/.test(text)) continue;
|
|
2151
|
+
for (const [re, what] of GERMANISMS) if (re.test(text)) findings.push({
|
|
2152
|
+
path,
|
|
2153
|
+
message: `An English text uses ${what}: "${excerpt$1(text, 90)}"`
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
return findings;
|
|
2157
|
+
} })
|
|
2158
|
+
};
|
|
2159
|
+
const DU_PRONOUN = "[Dd]u|[Dd]ich|[Dd]ir|[Dd]ein|[Dd]eine[mnrs]?|[Dd]eins|[Ee]uch|[Ee]uer|[Ee]uere[mnrs]?|[Ee]ure[mnrs]?";
|
|
2160
|
+
const SIE_PRONOUN = "Sie|Ihnen|Ihr|Ihre[mnrs]?";
|
|
2161
|
+
/** du commands, lower case and capitalised: a verb's -e form or bare stem is only ever a du
|
|
2162
|
+
* command or the first person, which „ich" marks, so they are safe on Sie text. One that clashes
|
|
2163
|
+
* with a noun or adjective is in `DU_COMMANDS_LOWER`; one that clashes everywhere is left out:
|
|
2164
|
+
* achte (ordinal), sichere (adjective), teil (the particle of „nehmen … teil"). A command this
|
|
2165
|
+
* misses goes into the list. */
|
|
2166
|
+
const DU_COMMANDS = [
|
|
2167
|
+
"schreib schreibe wähl wähle gib prüf prüfe versuch versuche lass lasse ändere änder setz setze zoom zoome verschieb verschiebe probier probiere sieh schau schaue meld melde rufe frag nimm hinterlass hinterlasse erzähl erzähle vergleiche entdeck entdecke stöber stöbere nutz nutze klicke tippe komm geh lies bleib gönn gönne spar spare mach mache leg lege füll lad lade hol hole merk merke find finde such reservier reserviere pack packe bring bringe genieß genieße starte schick schicke sende öffne zeig zeige wechsle trag trage kontaktier kontaktiere schließ schließe scroll scrolle",
|
|
2168
|
+
"bestätige bestätig akzeptiere akzeptier aktiviere aktivier deaktiviere registriere registrier logg logge abonniere abonnier informiere informier fordere fordre beschreib beschreibe nenn nenne ergänze ergänz korrigiere korrigier füg füge entferne entfern lösche lösch kopiere kopier speichere filtere sortiere sortier storniere stornier bezahl bezahle zahle beachte stell denk denke warte halte zieh ziehe drück drücke wisch wische schalt schalte hör höre sag antworte vergiss hilf wirf triff sprich iss bewirb empfiehl",
|
|
2169
|
+
"erleb erlebe erkunde erfahr erfahre verbring verbringe tauch tauche atme spür spüre lausch lausche wander wandere radel radle schwimm schwimme spazier spaziere fahr fahre folg lern lerne guck gucke gestalte bewerte vertrau vertraue trau traue überzeug überzeuge miet vermiete feiere koche lehn profitier profitiere"
|
|
2170
|
+
].flatMap((group) => group.split(" "));
|
|
2171
|
+
/** du commands that are also a noun or adjective (Teile, Plane, Besuch, Fülle): lower case
|
|
2172
|
+
* anywhere, capitalised only at the start of a clause before „jetzt", „uns" and the like. */
|
|
2173
|
+
const DU_COMMANDS_LOWER = ["ruf klick tipp teile buch buche plan plane stelle fülle speicher zahl miete besuch besuche frage antwort sage lauf spiel spiele koch grill feier folge lehne wart"].flatMap((group) => group.split(" "));
|
|
2174
|
+
const cap = (w) => w[0].toUpperCase() + w.slice(1);
|
|
2175
|
+
/** Whole words only: a letter, digit or code punctuation beside the word (`/de/dir/`, `dir=ltr`)
|
|
2176
|
+
* makes it part of something else. */
|
|
2177
|
+
const word = (alt) => new RegExp(`(?<![\\p{L}\\p{N}_/.$@#=:\\[-])(?:${alt})(?![\\p{L}\\p{N}_/=@(\\[-])`, "gu");
|
|
2178
|
+
/** A polite command carries „Sie"; „ich" marks the first person („Gerne erzähle ich"). */
|
|
2179
|
+
const NOT_POLITE = "(?!\\s+(?:Sie|ich)(?![\\p{L}]))";
|
|
2180
|
+
/** A clause starts the text, follows . ! ? : ; or an opening quote, or follows „Bitte". */
|
|
2181
|
+
const CLAUSE = "(?<=(?:^|[.!?:;]\\s+|[„\"(]\\s*|[Bb]itte\\s+))";
|
|
2182
|
+
const CLASH_FOLLOW = "(?=\\s+(?:jetzt|gleich|direkt|sofort|online|einfach|hier|uns|mir|mal)(?![\\p{L}]))";
|
|
2183
|
+
const COMMANDS = [word(`(?:${[...DU_COMMANDS.flatMap((w) => [w, cap(w)]), ...DU_COMMANDS_LOWER].join("|")})${NOT_POLITE}`), word(`${CLAUSE}(?:${DU_COMMANDS_LOWER.map(cap).join("|")})${CLASH_FOLLOW}`)];
|
|
2184
|
+
/** The distinct words the patterns find, less the guest's own question („Wie ändere ich …"). */
|
|
2185
|
+
const hits = (patterns, text) => [...new Set(patterns.flatMap((re) => [...text.matchAll(re)].map((m) => m[0])))].filter((hit) => !new RegExp(`(?:^|\\s)ich\\s+${hit}(?![\\p{L}])`, "u").test(text));
|
|
2186
|
+
const collapse$1 = (text) => text.replace(/\s+/g, " ").trim();
|
|
2187
|
+
/** Every `"de-XX"` text the site writes uses the site's one form of address (`address`): no
|
|
2188
|
+
* pronoun of the other form, and on a Sie site no du command without a pronoun („Schreib uns.",
|
|
2189
|
+
* „Bitte wähle ein Land."). A polite command always carries „Sie", so a du site needs no verb
|
|
2190
|
+
* list. The feed's and the kit's texts are not the site's words and are not read. Waits for
|
|
2191
|
+
* `address`. */
|
|
2192
|
+
const copyAddress = {
|
|
2193
|
+
id: "copy-address",
|
|
2194
|
+
title: "The site's German texts use its one form of address",
|
|
2195
|
+
severity: "error",
|
|
2196
|
+
stage: "src",
|
|
2197
|
+
begin: (ctx) => {
|
|
2198
|
+
const { address } = ctx.options;
|
|
2199
|
+
if (!address) return null;
|
|
2200
|
+
const allowed = new Set(ctx.options.addressAllow.map(collapse$1));
|
|
2201
|
+
const pronoun = [word(address === "du" ? SIE_PRONOUN : DU_PRONOUN)];
|
|
2202
|
+
const commands = address === "du" ? [] : COMMANDS;
|
|
2203
|
+
return { finish: () => {
|
|
2204
|
+
const findings = [];
|
|
2205
|
+
for (const { path, text } of localizedTexts(ctx, "de")) {
|
|
2206
|
+
if (!/\p{L}{2}/u.test(text) || allowed.has(collapse$1(text))) continue;
|
|
2207
|
+
const pronouns = hits(pronoun, text);
|
|
2208
|
+
const verbs = hits(commands, text);
|
|
2209
|
+
if (pronouns.length === 0 && verbs.length === 0) continue;
|
|
2210
|
+
const what = [pronouns.length > 0 ? `pronoun ${pronouns.join(", ")}` : "", verbs.length > 0 ? `du command ${verbs.join(", ")}` : ""].filter(Boolean).join(" and ");
|
|
2211
|
+
findings.push({
|
|
2212
|
+
path,
|
|
2213
|
+
message: `A German text uses ${what}, but this site says ${address}: "${excerpt$1(text, 110)}"`
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
return findings;
|
|
2217
|
+
} };
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
/** The `bannedCopy` wordings scoped `"in": "src"`, found in the site's own text: every file under
|
|
2221
|
+
* `src/` with comments and tags blanked. What the feed renders never reaches it, so no page has to
|
|
2222
|
+
* be unchecked for the feed's sake. A file or folder named after a `copyExcludePaths` or
|
|
2223
|
+
* `bannedCopyExcludePaths` entry is skipped like its page (`src/pages/agb.astro` for `/agb`,
|
|
2224
|
+
* `src/data/faq.ts` for `/faq`), and so is every prefix in the ban's own `srcExclude`. */
|
|
2225
|
+
const bannedCopySrc = {
|
|
2226
|
+
id: "banned-copy-src",
|
|
2227
|
+
title: "Wordings banned by a recorded correction, in the site's own text",
|
|
2228
|
+
severity: "error",
|
|
2229
|
+
stage: "src",
|
|
2230
|
+
begin: (ctx) => {
|
|
2231
|
+
const bans = ctx.options.bannedCopy.filter((ban) => ban.in === "src");
|
|
2232
|
+
if (bans.length === 0) return null;
|
|
2233
|
+
const routeNames = [...ctx.options.copyExcludePaths, ...ctx.options.bannedCopyExcludePaths].map((entry) => entry.replace(/\/+$/, "").split("/").pop() ?? "").filter(Boolean);
|
|
2234
|
+
return { finish: () => {
|
|
2235
|
+
const findings = [];
|
|
2236
|
+
const sources = flatSources(ctx).filter(({ rel }) => {
|
|
2237
|
+
const parts = rel.replace(/\.[^/.]+$/, "").split("/");
|
|
2238
|
+
return !routeNames.some((name) => parts.includes(name));
|
|
2239
|
+
});
|
|
2240
|
+
for (const { pattern, why, srcExclude = [] } of bans) {
|
|
2241
|
+
const re = new RegExp(pattern, "g");
|
|
2242
|
+
for (const { rel, text, lines } of sources) {
|
|
2243
|
+
if (srcExclude.some((prefix) => rel.startsWith(prefix))) continue;
|
|
2244
|
+
for (const match of text.matchAll(re)) if (match[0]) findings.push({
|
|
2245
|
+
path: `${rel}:${lines[match.index] ?? 1}`,
|
|
2246
|
+
message: `"${excerpt$1(match[0], 70)}" is a banned wording in the site's own text: ${why}`
|
|
1403
2247
|
});
|
|
1404
2248
|
}
|
|
1405
|
-
return findings;
|
|
1406
2249
|
}
|
|
1407
|
-
|
|
2250
|
+
return findings;
|
|
2251
|
+
} };
|
|
1408
2252
|
}
|
|
1409
2253
|
};
|
|
1410
2254
|
//#endregion
|
|
@@ -1413,10 +2257,11 @@ const MAX_TITLE = 60;
|
|
|
1413
2257
|
const MAX_DESCRIPTION = 160;
|
|
1414
2258
|
/** The head of every indexable page as a search result shows it: a title over 60 or a description
|
|
1415
2259
|
* over 160 characters is cut, an empty description is replaced by whatever the crawler picks, and a
|
|
1416
|
-
* title or description another page repeats makes the two compete
|
|
1417
|
-
*
|
|
1418
|
-
*
|
|
1419
|
-
*
|
|
2260
|
+
* title or description another page repeats makes the two compete, and a title naming the site
|
|
2261
|
+
* (`og:site_name`) twice spends its width on the brand. Language versions of one page that name
|
|
2262
|
+
* each other as `<link rel="alternate" hreflang>` do not compete: a search engine shows the one in
|
|
2263
|
+
* the searcher's language. A missing title or description is the build worker's `page-metadata`
|
|
2264
|
+
* finding, not repeated here. A warning: the page works. */
|
|
1420
2265
|
const pageHeads = {
|
|
1421
2266
|
id: "page-heads",
|
|
1422
2267
|
title: "Titles and descriptions of indexable pages",
|
|
@@ -1435,7 +2280,7 @@ const pageHeads = {
|
|
|
1435
2280
|
const remember = (map, value, path) => map.set(value, [...map.get(value) ?? [], path]);
|
|
1436
2281
|
return {
|
|
1437
2282
|
visit: (page) => {
|
|
1438
|
-
if (page
|
|
2283
|
+
if (!isIndexable(page)) return;
|
|
1439
2284
|
const own = normalize(page.url);
|
|
1440
2285
|
urls.set(page.path, own);
|
|
1441
2286
|
const named = /* @__PURE__ */ new Set();
|
|
@@ -1451,6 +2296,11 @@ const pageHeads = {
|
|
|
1451
2296
|
message: `The title has ${title.length} characters; search results cut it after ${MAX_TITLE}.`
|
|
1452
2297
|
});
|
|
1453
2298
|
remember(titles, title, page.path);
|
|
2299
|
+
const siteName = page.document.querySelector("meta[property=\"og:site_name\"], meta[name=\"og:site_name\"]")?.getAttribute("content")?.trim().toLowerCase();
|
|
2300
|
+
if (siteName && title.toLowerCase().split(siteName).length > 2) findings.push({
|
|
2301
|
+
path: page.path,
|
|
2302
|
+
message: `The title "${title}" names the site twice; name it once, at the end.`
|
|
2303
|
+
});
|
|
1454
2304
|
}
|
|
1455
2305
|
if (description !== void 0) {
|
|
1456
2306
|
if (description === "") findings.push({
|
|
@@ -1516,19 +2366,32 @@ const SELF_NAMING = /* @__PURE__ */ new Set([
|
|
|
1516
2366
|
const RATIO_FLOOR = 10;
|
|
1517
2367
|
const RATIO_TIMES = 3;
|
|
1518
2368
|
const inDocument = (page, selector) => [...page.document.querySelectorAll(selector)].filter((el) => !el.closest(OUTSIDE));
|
|
2369
|
+
/** A PMS document rendered by RichText (descriptions, property texts, legal documents): its
|
|
2370
|
+
* headings keep the document's own relative depth, so a skip between two of them is the owner's
|
|
2371
|
+
* text, which a nightly build can bring; the step into the block is still the site's. */
|
|
2372
|
+
const PMS_TEXT = "[data-part=\"rich-text\"]";
|
|
2373
|
+
const headings = (page) => inDocument(page, "h1, h2, h3, h4, h5, h6").map((h) => ({
|
|
2374
|
+
level: Number(h.tagName[1]),
|
|
2375
|
+
block: h.closest(PMS_TEXT)
|
|
2376
|
+
}));
|
|
2377
|
+
/** Out of the accessibility tree and out of the tab order: a widget's hidden form mirror (Base
|
|
2378
|
+
* UI's select and checkbox render `aria-hidden` and `tabindex="-1"` on it), which nobody reaches.
|
|
2379
|
+
* `aria-hidden` alone hides a control from a screen reader that the keyboard still lands on. */
|
|
2380
|
+
const unreachable = (control) => control.getAttribute("tabindex")?.trim() === "-1" && !!control.closest("[aria-hidden=\"true\"]");
|
|
1519
2381
|
/** Each rule's fault on one page, keyed by rule id, as a printable detail. */
|
|
1520
2382
|
const structureFaults = (page) => {
|
|
1521
2383
|
const faults = /* @__PURE__ */ new Map();
|
|
1522
|
-
const levels =
|
|
1523
|
-
const h1 = levels.filter((level) => level === 1).length;
|
|
2384
|
+
const levels = headings(page);
|
|
2385
|
+
const h1 = levels.filter(({ level }) => level === 1).length;
|
|
1524
2386
|
if (h1 !== 1) faults.set("one-h1", h1 === 0 ? "no <h1>: a page names itself once" : `${h1} <h1>: a page names itself once`);
|
|
1525
|
-
for (let i = 1; i < levels.length; i += 1)
|
|
1526
|
-
|
|
1527
|
-
|
|
2387
|
+
for (let i = 1; i < levels.length; i += 1) {
|
|
2388
|
+
const [before, heading] = [levels[i - 1], levels[i]];
|
|
2389
|
+
if (heading.block && heading.block === before.block) continue;
|
|
2390
|
+
if (heading.level > before.level + 1) {
|
|
2391
|
+
faults.set("heading-skip", `<h${before.level}> is followed by <h${heading.level}>`);
|
|
2392
|
+
break;
|
|
2393
|
+
}
|
|
1528
2394
|
}
|
|
1529
|
-
const h2 = levels.filter((level) => level === 2).length;
|
|
1530
|
-
const h3 = levels.filter((level) => level === 3).length;
|
|
1531
|
-
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`);
|
|
1532
2395
|
if (inDocument(page, "main").length === 0) faults.set("landmark-main", "no <main> landmark");
|
|
1533
2396
|
const noAlt = inDocument(page, "img").filter((img) => !img.hasAttribute("alt"));
|
|
1534
2397
|
if (noAlt.length > 0) faults.set("img-alt", `${noAlt.length} <img> without alt, e.g. ${noAlt[0].getAttribute("src") ?? "(no src)"}`);
|
|
@@ -1536,7 +2399,7 @@ const structureFaults = (page) => {
|
|
|
1536
2399
|
const unlabelled = inDocument(page, "input, select, textarea").filter((control) => {
|
|
1537
2400
|
const type = (control.getAttribute("type") ?? "text").toLowerCase();
|
|
1538
2401
|
if (control.tagName === "INPUT" && SELF_NAMING.has(type)) return false;
|
|
1539
|
-
if (control
|
|
2402
|
+
if (unreachable(control)) return false;
|
|
1540
2403
|
if ([
|
|
1541
2404
|
"aria-label",
|
|
1542
2405
|
"aria-labelledby",
|
|
@@ -1560,10 +2423,11 @@ const structureFaults = (page) => {
|
|
|
1560
2423
|
};
|
|
1561
2424
|
/** The built pages' own structure, which a screen reader navigates by and nothing else reads: one
|
|
1562
2425
|
* `<h1>`, no skipped heading level, a `<main>` landmark, `alt` on every image, a label on every
|
|
1563
|
-
* control, a caption (or `aria-label`/`aria-labelledby`) and scoped headers on every table
|
|
1564
|
-
*
|
|
1565
|
-
*
|
|
1566
|
-
*
|
|
2426
|
+
* control, a caption (or `aria-label`/`aria-labelledby`) and scoped headers on every table.
|
|
2427
|
+
* Contrast, focus order and keyboard traps are not decidable from static markup. A warning on
|
|
2428
|
+
* every build, previews included: a site under construction sees its faults from the first build,
|
|
2429
|
+
* and no push waits on them; the fix is in the site's components. A site declines a rule in
|
|
2430
|
+
* `structureIgnore`. */
|
|
1567
2431
|
const pageStructure = {
|
|
1568
2432
|
id: "page-structure",
|
|
1569
2433
|
title: "Page outline, landmarks, alt text, labels and tables",
|
|
@@ -1585,13 +2449,329 @@ const pageStructure = {
|
|
|
1585
2449
|
};
|
|
1586
2450
|
}
|
|
1587
2451
|
};
|
|
2452
|
+
/** Many `<h3>` under few `<h2>`: usually card titles marked up as headings, which bury the
|
|
2453
|
+
* outline. A warning, apart from `page-structure`: a long index can look the same and be right.
|
|
2454
|
+
* `structureIgnore: ["heading-ratio"]` declines it, as it did when the rule was part of
|
|
2455
|
+
* `page-structure`. */
|
|
2456
|
+
const headingRatio = {
|
|
2457
|
+
id: "heading-ratio",
|
|
2458
|
+
title: "Small headings do not swamp the outline",
|
|
2459
|
+
severity: "warning",
|
|
2460
|
+
stage: "dist",
|
|
2461
|
+
begin: (ctx) => {
|
|
2462
|
+
if (!ctx.hasDist || ctx.options.structureIgnore.includes("heading-ratio")) return null;
|
|
2463
|
+
const findings = [];
|
|
2464
|
+
return {
|
|
2465
|
+
visit: (page) => {
|
|
2466
|
+
if (page.redirect) return;
|
|
2467
|
+
const levels = headings(page);
|
|
2468
|
+
const h2 = levels.filter(({ level }) => level === 2).length;
|
|
2469
|
+
const h3 = levels.filter(({ level }) => level === 3).length;
|
|
2470
|
+
if (h3 >= RATIO_FLOOR && h3 > RATIO_TIMES * Math.max(h2, 1)) findings.push({
|
|
2471
|
+
path: page.path,
|
|
2472
|
+
message: `${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.`
|
|
2473
|
+
});
|
|
2474
|
+
},
|
|
2475
|
+
finish: () => findings
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
};
|
|
2479
|
+
//#endregion
|
|
2480
|
+
//#region src/env.ts
|
|
2481
|
+
/** The env files a production build reads, in the order Vite applies them (a later file wins per
|
|
2482
|
+
* key). The `.local` pair is left out on purpose: it is the developer's machine, never what the
|
|
2483
|
+
* deployed site builds against, and a site must not commit it. */
|
|
2484
|
+
const BUILD_ENV_FILES = [".env", ".env.production"];
|
|
2485
|
+
/** Files Vite loads after the committed ones in every mode; committed, they win in CI too. */
|
|
2486
|
+
const LOCAL_ENV_FILES = [".env.local", ".env.production.local"];
|
|
2487
|
+
const ASSIGNMENT = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;
|
|
2488
|
+
/** `KEY=value` lines of one env file: `export` allowed, a value in matching quotes unquoted, a
|
|
2489
|
+
* ` # comment` after the value (quoted or not) dropped. The last assignment of a key wins. */
|
|
2490
|
+
const parseEnv = (text) => {
|
|
2491
|
+
const env = {};
|
|
2492
|
+
for (const line of text.split(/\r?\n/)) {
|
|
2493
|
+
const match = ASSIGNMENT.exec(line);
|
|
2494
|
+
if (!match) continue;
|
|
2495
|
+
let value = match[2].trim();
|
|
2496
|
+
const quoted = /^(["'])(.*?)\1(?:\s+#.*)?$/.exec(value);
|
|
2497
|
+
value = quoted ? quoted[2] : value.replace(/\s+#.*$/, "").trim();
|
|
2498
|
+
env[match[1]] = value;
|
|
2499
|
+
}
|
|
2500
|
+
return env;
|
|
2501
|
+
};
|
|
2502
|
+
const readEnvFile = (root, file) => {
|
|
2503
|
+
const full = path.join(root, file);
|
|
2504
|
+
return fs.existsSync(full) ? parseEnv(fs.readFileSync(full, "utf8")) : {};
|
|
2505
|
+
};
|
|
2506
|
+
/** What a production build of the site reads from its committed env files. */
|
|
2507
|
+
const buildEnv = (root) => Object.assign({}, ...BUILD_ENV_FILES.map((file) => readEnvFile(root, file)));
|
|
2508
|
+
/** The SDK's env names (`SDK_ENV` in `@v-office/website-headless`) a build reads, and the two v9
|
|
2509
|
+
* config switches of the Website SDK CLI. */
|
|
2510
|
+
const SDK_NAMES = [
|
|
2511
|
+
"CMS_BACKEND",
|
|
2512
|
+
"CMS_STAGE",
|
|
2513
|
+
"HUB_API_KEY",
|
|
2514
|
+
"HUB_GRAPHQL_URL",
|
|
2515
|
+
"HUB_V0_API_BASE_URL",
|
|
2516
|
+
"HUB_V1_API_BASE_URL",
|
|
2517
|
+
"IMAGE_PROXY_BASE_URL",
|
|
2518
|
+
"VOFFICE_LOCAL_DEV_ACCESS_TOKEN",
|
|
2519
|
+
"VOFFICE_API_ENDPOINT",
|
|
2520
|
+
"VOFFICE_SEARCH_ENDPOINT",
|
|
2521
|
+
"VOFFICE_IMAGE_BASE_URL",
|
|
2522
|
+
"HUB_RENTAL_SCOPE_PROPERTY_KIND",
|
|
2523
|
+
"HUB_RENTAL_IDS_SEARCH"
|
|
2524
|
+
];
|
|
2525
|
+
/** The env name the SDK reads a backend's token under (`SDK_ENV` in `@v-office/website-headless`). */
|
|
2526
|
+
const TOKEN_NAMES = {
|
|
2527
|
+
v9: "HUB_API_KEY",
|
|
2528
|
+
v10: "VOFFICE_LOCAL_DEV_ACCESS_TOKEN"
|
|
2529
|
+
};
|
|
2530
|
+
/** The SDK env the build runs with, resolved the way the site starter does: a value in the
|
|
2531
|
+
* process env wins over the committed files (Vite's order), and what neither sets comes from what
|
|
2532
|
+
* AI Studio's builder passes: the website's PMS generation as `PMS_BACKEND`, its key as
|
|
2533
|
+
* `PMS_TOKEN` (`HUB_API_KEY` on v9, `VOFFICE_LOCAL_DEV_ACCESS_TOKEN` on v10). A template site
|
|
2534
|
+
* commits no backend, so without the fallback a v9 site there would read as no site at all. */
|
|
2535
|
+
const sdkEnv = (root, processEnv = process.env) => {
|
|
2536
|
+
const env = {};
|
|
2537
|
+
for (const [name, value] of Object.entries(buildEnv(root))) if (value.trim()) env[name] = value.trim();
|
|
2538
|
+
for (const name of SDK_NAMES) {
|
|
2539
|
+
const value = processEnv[name]?.trim();
|
|
2540
|
+
if (value) env[name] = value;
|
|
2541
|
+
}
|
|
2542
|
+
if (!env.CMS_BACKEND && processEnv.PMS_BACKEND?.trim()) env.CMS_BACKEND = processEnv.PMS_BACKEND.trim();
|
|
2543
|
+
const token = TOKEN_NAMES[env.CMS_BACKEND ?? ""];
|
|
2544
|
+
if (token && !env[token] && processEnv.PMS_TOKEN?.trim()) env[token] = processEnv.PMS_TOKEN.trim();
|
|
2545
|
+
return env;
|
|
2546
|
+
};
|
|
2547
|
+
/** What the developer's `.local` files set. */
|
|
2548
|
+
const localEnv = (root) => Object.assign({}, ...LOCAL_ENV_FILES.map((file) => readEnvFile(root, file)));
|
|
2549
|
+
//#endregion
|
|
2550
|
+
//#region src/checks/v9.ts
|
|
2551
|
+
/** The be-on! Hub endpoints per stage, as `@v-office/website-headless` resolves `CMS_STAGE` for v9
|
|
2552
|
+
* (`sdk/endpoints.ts`). Production is what a live v9 site calls. */
|
|
2553
|
+
const HUB = {
|
|
2554
|
+
production: {
|
|
2555
|
+
api: "https://api.voffice.be-on.io",
|
|
2556
|
+
imageProxy: "https://imgproxy.voffice.be-on.io"
|
|
2557
|
+
},
|
|
2558
|
+
development: {
|
|
2559
|
+
api: "https://api.voffice.demo-on.de",
|
|
2560
|
+
imageProxy: "https://imgproxy.voffice.demo-on.de"
|
|
2561
|
+
}
|
|
2562
|
+
};
|
|
2563
|
+
const hubUrls = (stage) => ({
|
|
2564
|
+
HUB_V1_API_BASE_URL: `${HUB[stage].api}/api/v1`,
|
|
2565
|
+
HUB_V0_API_BASE_URL: `${HUB[stage].api}/api/v0`,
|
|
2566
|
+
HUB_GRAPHQL_URL: `${HUB[stage].api}/graphql`,
|
|
2567
|
+
IMAGE_PROXY_BASE_URL: HUB[stage].imageProxy
|
|
2568
|
+
});
|
|
2569
|
+
/** The build's SDK env, when it builds a v9 site: `CMS_BACKEND=v9` from the process env, the
|
|
2570
|
+
* committed `.env` / `.env.production`, or AI Studio's `PMS_BACKEND` (`sdkEnv`). Every v9 check
|
|
2571
|
+
* starts here, so a v10 site, or one with no backend at all, never runs one. */
|
|
2572
|
+
const v9Env = (ctx) => {
|
|
2573
|
+
const env = sdkEnv(ctx.root);
|
|
2574
|
+
return env.CMS_BACKEND === "v9" ? env : null;
|
|
2575
|
+
};
|
|
2576
|
+
/** How long the Hub may take to answer before the check gives up. */
|
|
2577
|
+
const HUB_TIMEOUT_MS = 6e4;
|
|
2578
|
+
/** The Website SDK CLI's v9 config, from the build's SDK env (`sdkEnv`): the stage's endpoints with
|
|
2579
|
+
* `CMS_STAGE`, else the URL variables, and the key. */
|
|
2580
|
+
const cliConfig = (env) => {
|
|
2581
|
+
const stage = env.CMS_STAGE === "production" || env.CMS_STAGE === "development" ? env.CMS_STAGE : void 0;
|
|
2582
|
+
const urls = stage ? hubUrls(stage) : env;
|
|
2583
|
+
return {
|
|
2584
|
+
backend: "v9",
|
|
2585
|
+
apiKey: env.HUB_API_KEY ?? "",
|
|
2586
|
+
graphqlUrl: urls.HUB_GRAPHQL_URL ?? "",
|
|
2587
|
+
imageProxyBaseUrl: urls.IMAGE_PROXY_BASE_URL ?? "",
|
|
2588
|
+
...urls.HUB_V0_API_BASE_URL ? { v0ApiBaseUrl: urls.HUB_V0_API_BASE_URL } : {},
|
|
2589
|
+
...urls.HUB_V1_API_BASE_URL ? { v1ApiBaseUrl: urls.HUB_V1_API_BASE_URL } : {},
|
|
2590
|
+
...env.HUB_RENTAL_SCOPE_PROPERTY_KIND === "facility" || env.HUB_RENTAL_SCOPE_PROPERTY_KIND === "objectGroup" ? { rentalScopePropertyKind: env.HUB_RENTAL_SCOPE_PROPERTY_KIND } : {},
|
|
2591
|
+
...env.HUB_RENTAL_IDS_SEARCH === "true" || env.HUB_RENTAL_IDS_SEARCH === "false" ? { rentalIdsSearch: env.HUB_RENTAL_IDS_SEARCH === "true" } : {}
|
|
2592
|
+
};
|
|
2593
|
+
};
|
|
2594
|
+
const sdkVersion = (root) => {
|
|
2595
|
+
try {
|
|
2596
|
+
const file = path.join(root, "node_modules", "@v-office", "website-sdk", "package.json");
|
|
2597
|
+
return JSON.parse(fs.readFileSync(file, "utf8")).version ?? "unknown version";
|
|
2598
|
+
} catch {
|
|
2599
|
+
return "unknown version";
|
|
2600
|
+
}
|
|
2601
|
+
};
|
|
2602
|
+
const run = async (cli, args, cwd) => {
|
|
2603
|
+
const { execFile } = await import("node:child_process");
|
|
2604
|
+
return new Promise((resolve) => {
|
|
2605
|
+
execFile(cli, args, {
|
|
2606
|
+
cwd,
|
|
2607
|
+
timeout: HUB_TIMEOUT_MS,
|
|
2608
|
+
maxBuffer: 1048576
|
|
2609
|
+
}, (err, stdout, stderr) => resolve({
|
|
2610
|
+
code: err ? typeof err.code === "number" ? err.code : 1 : 0,
|
|
2611
|
+
output: `${stdout}${stderr}`.trim()
|
|
2612
|
+
}));
|
|
2613
|
+
});
|
|
2614
|
+
};
|
|
2615
|
+
/** The backend-filter definitions a v9 site passes to the SDK, as its own data file. */
|
|
2616
|
+
const HUB_FILTERS_FILE = path.join("data", "hub-filters.json");
|
|
2617
|
+
/** Every be-on! Hub filter the site's search needs (the scope filter, the Merkliste's rental-id
|
|
2618
|
+
* filter, each searchable backend-filter definition) exists in the Hub the site builds against.
|
|
2619
|
+
* A filter the Hub does not serve matches nothing, or everything once a date is set. Asks the Hub
|
|
2620
|
+
* through the site's own `website-sdk hub-filters check`, with the build's env and the SDK
|
|
2621
|
+
* options in `hubFilterOptions`; the site's own list in `src/data/hub-filters.json`, when it has
|
|
2622
|
+
* one, is the `customAttributeFilterDefinitions`, so no copy of it can drift. A warning: the
|
|
2623
|
+
* outcome is the Hub's data, and a Hub that cannot be asked must not stop the nightly builds; it
|
|
2624
|
+
* is reported, never passed. v9 only. */
|
|
2625
|
+
const v9HubFilters = {
|
|
2626
|
+
id: "v9-hub-filters",
|
|
2627
|
+
title: "The be-on! Hub serves the filters the v9 site needs",
|
|
2628
|
+
severity: "warning",
|
|
2629
|
+
stage: "src",
|
|
2630
|
+
begin: (ctx) => {
|
|
2631
|
+
const env = v9Env(ctx);
|
|
2632
|
+
if (!env) return null;
|
|
2633
|
+
return { finish: async () => {
|
|
2634
|
+
let hubFilterOptions = ctx.options.hubFilterOptions;
|
|
2635
|
+
const listFile = path.join(ctx.srcDir, HUB_FILTERS_FILE);
|
|
2636
|
+
if (fs.existsSync(listFile)) {
|
|
2637
|
+
let list;
|
|
2638
|
+
try {
|
|
2639
|
+
list = JSON.parse(fs.readFileSync(listFile, "utf8"));
|
|
2640
|
+
} catch {}
|
|
2641
|
+
if (!Array.isArray(list)) return [{
|
|
2642
|
+
path: ctx.rel(listFile),
|
|
2643
|
+
message: `${ctx.rel(listFile)} is not a JSON array of filter definitions, so the Hub could not be asked.`
|
|
2644
|
+
}];
|
|
2645
|
+
hubFilterOptions = {
|
|
2646
|
+
...hubFilterOptions,
|
|
2647
|
+
customAttributeFilterDefinitions: list
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
const cli = path.join(ctx.root, "node_modules", ".bin", process.platform === "win32" ? "website-sdk.cmd" : "website-sdk");
|
|
2651
|
+
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." }];
|
|
2652
|
+
const config = cliConfig(env);
|
|
2653
|
+
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." }];
|
|
2654
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "site-checks-hub-"));
|
|
2655
|
+
try {
|
|
2656
|
+
const configFile = path.join(dir, "config.json");
|
|
2657
|
+
const optionsFile = path.join(dir, "options.json");
|
|
2658
|
+
fs.writeFileSync(configFile, JSON.stringify(config));
|
|
2659
|
+
fs.writeFileSync(optionsFile, JSON.stringify(hubFilterOptions));
|
|
2660
|
+
const { code, output } = await run(cli, [
|
|
2661
|
+
"--backend",
|
|
2662
|
+
"v9",
|
|
2663
|
+
"--config",
|
|
2664
|
+
configFile,
|
|
2665
|
+
"--options",
|
|
2666
|
+
optionsFile,
|
|
2667
|
+
"hub-filters",
|
|
2668
|
+
"check"
|
|
2669
|
+
], ctx.root);
|
|
2670
|
+
if (code === 0) return [];
|
|
2671
|
+
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.` }];
|
|
2672
|
+
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.` }];
|
|
2673
|
+
} finally {
|
|
2674
|
+
fs.rmSync(dir, {
|
|
2675
|
+
recursive: true,
|
|
2676
|
+
force: true
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
} };
|
|
2680
|
+
}
|
|
2681
|
+
};
|
|
2682
|
+
//#endregion
|
|
2683
|
+
//#region src/checks/productionEnv.ts
|
|
2684
|
+
/** The v10 endpoints of production, as `@v-office/website-headless` resolves `CMS_STAGE`
|
|
2685
|
+
* (`sdk/endpoints.ts`, `VOFFICE_ENDPOINTS`). */
|
|
2686
|
+
const V10_PRODUCTION = {
|
|
2687
|
+
VOFFICE_API_ENDPOINT: "https://api.production.v-office.io",
|
|
2688
|
+
VOFFICE_SEARCH_ENDPOINT: "https://search.production.v-office.io/search",
|
|
2689
|
+
VOFFICE_IMAGE_BASE_URL: "https://images.production.v-office.io"
|
|
2690
|
+
};
|
|
2691
|
+
const sameUrl = (a, b) => (a ?? "").replace(/\/+$/, "") === b.replace(/\/+$/, "");
|
|
2692
|
+
/** The `.local` env files git tracks; empty outside a git checkout (nothing to tell then). */
|
|
2693
|
+
const committedLocalFiles = async (root) => {
|
|
2694
|
+
const { execFileSync } = await import("node:child_process");
|
|
2695
|
+
return LOCAL_ENV_FILES.filter((file) => {
|
|
2696
|
+
try {
|
|
2697
|
+
execFileSync("git", [
|
|
2698
|
+
"ls-files",
|
|
2699
|
+
"--error-unmatch",
|
|
2700
|
+
"--",
|
|
2701
|
+
file
|
|
2702
|
+
], {
|
|
2703
|
+
cwd: root,
|
|
2704
|
+
stdio: "ignore"
|
|
2705
|
+
});
|
|
2706
|
+
return true;
|
|
2707
|
+
} catch {
|
|
2708
|
+
return false;
|
|
2709
|
+
}
|
|
2710
|
+
});
|
|
2711
|
+
};
|
|
2712
|
+
const WHERE = `the build's env (${BUILD_ENV_FILES.join(" / ")} or the process env)`;
|
|
2713
|
+
/** A launched site of one PMS generation builds against that PMS's production: the build's env says
|
|
2714
|
+
* `CMS_STAGE=production`, or names the production endpoints. The endpoints are baked in at build
|
|
2715
|
+
* time, so a site built against the development PMS renders fine, only with the test catalogue.
|
|
2716
|
+
* Also reported: a committed `.env.local` (Vite loads it after `.env` in every mode, so CI builds
|
|
2717
|
+
* from it) and a committed token that is the developer's own, from `.env.local`. Waits while every
|
|
2718
|
+
* page is noindex, and while the Astro `site` is a preview host or unset: before launch a site
|
|
2719
|
+
* builds against the test PMS on purpose. An error: every finding is the site's own env. A token
|
|
2720
|
+
* the build's env lacks is no finding: AI Studio's builder passes it (`PMS_TOKEN`), and a build
|
|
2721
|
+
* without one fails in the SDK before any check runs. */
|
|
2722
|
+
const productionEnv = (base, backend, pms, expected) => ({
|
|
2723
|
+
...base,
|
|
2724
|
+
severity: "error",
|
|
2725
|
+
stage: "dist",
|
|
2726
|
+
begin: (ctx) => {
|
|
2727
|
+
const env = sdkEnv(ctx.root);
|
|
2728
|
+
if (env.CMS_BACKEND !== backend) return null;
|
|
2729
|
+
return whenLaunched(ctx, async () => {
|
|
2730
|
+
const findings = [];
|
|
2731
|
+
for (const file of await committedLocalFiles(ctx.root)) findings.push({
|
|
2732
|
+
path: file,
|
|
2733
|
+
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.`
|
|
2734
|
+
});
|
|
2735
|
+
if (env.CMS_STAGE) {
|
|
2736
|
+
if (env.CMS_STAGE !== "production") findings.push({
|
|
2737
|
+
path: ".env",
|
|
2738
|
+
message: `CMS_STAGE is "${env.CMS_STAGE}" in ${WHERE}: the live site calls the ${env.CMS_STAGE} ${pms}. Set CMS_STAGE=production.`
|
|
2739
|
+
});
|
|
2740
|
+
} else {
|
|
2741
|
+
const wrong = Object.keys(expected).filter((name) => !sameUrl(env[name], expected[name]));
|
|
2742
|
+
if (wrong.length > 0) findings.push({
|
|
2743
|
+
path: ".env",
|
|
2744
|
+
message: `${WHERE[0].toUpperCase()}${WHERE.slice(1)} does not call the production ${pms}: ${wrong.map((name) => `${name}=${env[name] || "(unset)"}`).join(", ")}. Set ${wrong.map((name) => `${name}=${expected[name]}`).join(", ")}, or CMS_STAGE=production without the URLs.`
|
|
2745
|
+
});
|
|
2746
|
+
}
|
|
2747
|
+
const name = TOKEN_NAMES[backend];
|
|
2748
|
+
const token = env[name];
|
|
2749
|
+
if (token && token === localEnv(ctx.root)[name]) findings.push({
|
|
2750
|
+
path: ".env",
|
|
2751
|
+
message: backend === "v9" ? "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." : "VOFFICE_LOCAL_DEV_ACCESS_TOKEN in the build's env is the token of .env.local, the developer's token: production needs the customer's token from the production environment."
|
|
2752
|
+
});
|
|
2753
|
+
return findings;
|
|
2754
|
+
});
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2757
|
+
/** v9: the production be-on! Hub. */
|
|
2758
|
+
const v9ProductionHub = productionEnv({
|
|
2759
|
+
id: "v9-production-hub",
|
|
2760
|
+
title: "A launched v9 site calls the production Hub"
|
|
2761
|
+
}, "v9", "Hub", hubUrls("production"));
|
|
2762
|
+
/** v10: the production vOffice API. */
|
|
2763
|
+
const v10ProductionApi = productionEnv({
|
|
2764
|
+
id: "v10-production-api",
|
|
2765
|
+
title: "A launched v10 site calls the production vOffice API"
|
|
2766
|
+
}, "v10", "vOffice API", V10_PRODUCTION);
|
|
1588
2767
|
//#endregion
|
|
1589
2768
|
//#region src/checks/rentalFacts.ts
|
|
1590
2769
|
/** The markers the platform's rental blocks carry for this check (`GATE_MARKERS` in
|
|
1591
2770
|
* `@v-office/website-headless`): the fact row, the owner's description, the amenity section and
|
|
1592
|
-
* its all-amenities dialog.
|
|
2771
|
+
* its all-amenities dialog. A site's own layout may put facts in a chip row marked
|
|
2772
|
+
* `data-rental-facts` as well: both are read, or the facts in the other one go unchecked. */
|
|
1593
2773
|
const MARKERS = {
|
|
1594
|
-
stats: "[data-rental-stats]",
|
|
2774
|
+
stats: "[data-rental-stats], [data-rental-facts]",
|
|
1595
2775
|
description: "[data-rental-description]",
|
|
1596
2776
|
amenities: "[data-rental-amenities]",
|
|
1597
2777
|
amenitiesModal: "[data-amenities-modal]"
|
|
@@ -1616,17 +2796,20 @@ const WORDS = {
|
|
|
1616
2796
|
elf: 11,
|
|
1617
2797
|
zwölf: 12
|
|
1618
2798
|
};
|
|
1619
|
-
/** Grouped thousands first, or `\d+` matches only the tail: "2.000 m²" would read as 0.
|
|
1620
|
-
*
|
|
1621
|
-
* "zehn": a compound number is not read at
|
|
1622
|
-
|
|
2799
|
+
/** Grouped thousands first, or `\d+` matches only the tail: "2.000 m²" would read as 0. A decimal
|
|
2800
|
+
* comma is part of the number ("4,5 Badezimmer" is 4.5). Never the tail of a decimal ("2.5" is no
|
|
2801
|
+
* count of 5) or of a longer word ("dreizehn" is not "zehn": a compound number is not read at
|
|
2802
|
+
* all); a dot after a word is no decimal ("ca.130 qm" is 130). */
|
|
2803
|
+
const NUM = `(?<![\\d\\p{L}])(?<!\\d[.,])(\\d{1,3}(?:\\.\\d{3})+|\\d+(?:,\\d+)?|${Object.keys(WORDS).join("|")})`;
|
|
1623
2804
|
/** "ca." / "etwa" / "rund": the author's own approximation, a rounded statement. The group is
|
|
1624
2805
|
* load-bearing: without it `?` binds to the trailing `\s*` and only hedged figures match. */
|
|
1625
2806
|
const HEDGE = "(?:(?:ca\\.|etwa|rund)\\s*)";
|
|
1626
2807
|
const toNumber = (token) => {
|
|
1627
2808
|
const plain = token.replace(/\./g, "");
|
|
1628
|
-
return /^\d
|
|
2809
|
+
return /^\d+(?:,\d+)?$/.test(plain) ? Number(plain.replace(",", ".")) : WORDS[plain.toLowerCase()] ?? NaN;
|
|
1629
2810
|
};
|
|
2811
|
+
/** A count as the finding and its `factCheckAccepted` key write it: 2, or 2,5. */
|
|
2812
|
+
const german = (value) => String(value).replace(".", ",");
|
|
1630
2813
|
/** Prose pattern (group 1 the number) and fact pattern (group 1 the number, or `km` a kilometre
|
|
1631
2814
|
* figure), in every form a site renders and the older ones. Prose is matched case-insensitively:
|
|
1632
2815
|
* a sentence may open with the number word ("Drei Schlafzimmer …"). */
|
|
@@ -1665,15 +2848,23 @@ const PART_KINDS = /* @__PURE__ */ new Set([
|
|
|
1665
2848
|
"bathrooms"
|
|
1666
2849
|
]);
|
|
1667
2850
|
/** Occupancy only: a capacity that belongs to a room or a furnishing ("eine Sauna für bis zu zwei
|
|
1668
|
-
* Personen"). Never applied to other kinds: "Zimmer" is inside
|
|
1669
|
-
|
|
2851
|
+
* Personen", "Geschirr für 8 Personen"). Never applied to other kinds: "Zimmer" is inside
|
|
2852
|
+
* "Badezimmer" and "Schlafzimmer". */
|
|
2853
|
+
const NOT_CAPACITY = /Schlafzimmer|Zimmer|Bett|Sofa|Couch|Küche|Tisch|Essplatz|Essbereich|Sauna|Whirlpool|Gartenmöbel|Terrasse|Sitzgruppe|Balkon|Geschirr|Besteck|Gläser|Tassen|Kochutensilien/i;
|
|
2854
|
+
/** Occupancy only: the capacity of this unit combined with another ("kann mit der Nachbarwohnung
|
|
2855
|
+
* kombiniert werden und bietet so Platz für 8 Personen"). "kombiniert" alone is not enough: "Die
|
|
2856
|
+
* Wohnung kombiniert Komfort mit Tradition" still states the unit's own. */
|
|
2857
|
+
const COMBINED = /kombinierbar|kombinieren|kombiniert\s+(?:werden|und)|in Kombination mit|(?:zusammen|gemeinsam|dazu|hinzu|zusätzlich)\s*(?:ge)?buch|Nachbar(?:wohnung|haus|apartment|appartement)|benachbarte[nrsm]?\s+(?:Ferien)?(?:wohnung|haus|apartment|appartement)/i;
|
|
1670
2858
|
/** The unit as the clause's subject: whichever subject comes first governs the claim. */
|
|
1671
2859
|
const UNIT_SUBJECT = /Ferienwohnung|Ferienhaus|Wohnung|Apartment|Appartement|Unterkunft|Ferienunterkunft|Objekt|Haus\b|Hauses\b/i;
|
|
1672
2860
|
/** ':' ends a clause too: in "… Bereich des Hauses: Eine Sauna für …" the sauna governs. */
|
|
1673
2861
|
const CLAUSE_END = /[.!?•:]/g;
|
|
1674
2862
|
/** A part stated alone, with no total on the page ("im Erdgeschoss zwei Schlafzimmer"). Loose
|
|
1675
2863
|
* stems: feeds carry typos ("Erdgschoss") and both the -ss and -ß spellings. */
|
|
1676
|
-
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;
|
|
2864
|
+
const PART_SCOPE = /(?:Erd|Ober|Dach|Unter|Zwischen)g\p{L}*scho|Souterrain|Etage|Stockwerk|Gescho[sß]|Ebene(?![\p{L}])|die anderen|die beiden anderen|weitere[nrs]?(?![\p{L}])/iu;
|
|
2865
|
+
/** The floor abbreviations ("im EG 1 Schlafzimmer, im OG 2", "im 1. OG"), case-sensitive: "eg" and
|
|
2866
|
+
* "og" are no floors. */
|
|
2867
|
+
const FLOOR_ABBREVIATION = /(?<![\p{L}])(?:EG|OG|UG|DG|KG)(?![\p{L}])/u;
|
|
1677
2868
|
const OUTDOOR_SCOPE = /Grundst\p{L}*ck|Garten|Gartens|Terrasse|Wiese|Parzelle|Areal|Rasen|Außenbereich|Hofst\p{L}*|Innenhof/iu;
|
|
1678
2869
|
const clauseBefore = (prose, start) => {
|
|
1679
2870
|
let from = 0;
|
|
@@ -1690,7 +2881,12 @@ const roomScoped = (prose, start) => {
|
|
|
1690
2881
|
/** German puts the noun after the measurement ("auf einem 3000 m² großen Grundstück"), so this
|
|
1691
2882
|
* looks both ways. */
|
|
1692
2883
|
const outdoorScoped = (prose, start, end) => OUTDOOR_SCOPE.test(`${clauseBefore(prose, start)} ${prose.slice(end, end + 60).split(".")[0]}`);
|
|
1693
|
-
|
|
2884
|
+
/** Both ways, to the sentence's end: "Platz für 7 Personen, wenn Sie die Nachbarwohnung dazubuchen". */
|
|
2885
|
+
const combinedScoped = (prose, start, end) => COMBINED.test(`${clauseBefore(prose, start)} ${prose.slice(end, end + 200).split(/[.!?]/)[0]}`);
|
|
2886
|
+
const partScoped = (prose, start) => {
|
|
2887
|
+
const clause = clauseBefore(prose, start);
|
|
2888
|
+
return PART_SCOPE.test(clause) || FLOOR_ABBREVIATION.test(clause);
|
|
2889
|
+
};
|
|
1694
2890
|
/** The first fact a kind reads, with its tolerance: a km fact is metres rounded to its last digit
|
|
1695
2891
|
* ("4,2 km" is 4150–4250 m), every other fact is exact. */
|
|
1696
2892
|
const factValue = (pattern, facts) => {
|
|
@@ -1733,13 +2929,15 @@ const scanRental = (slug, input) => {
|
|
|
1733
2929
|
let agrees = false;
|
|
1734
2930
|
for (const match of prose.matchAll(proseRe)) {
|
|
1735
2931
|
const start = match.index;
|
|
1736
|
-
|
|
1737
|
-
if (kind === "
|
|
2932
|
+
const end = start + match[0].length;
|
|
2933
|
+
if (kind === "occupancy" && (roomScoped(prose, start) || combinedScoped(prose, start, end))) continue;
|
|
2934
|
+
if (kind === "area" && outdoorScoped(prose, start, end)) continue;
|
|
1738
2935
|
const got = toNumber(match[1]);
|
|
1739
2936
|
if (Number.isNaN(got)) continue;
|
|
1740
2937
|
if (PART_KINDS.has(kind) && got < value && partScoped(prose, start)) continue;
|
|
1741
2938
|
compared += 1;
|
|
1742
|
-
|
|
2939
|
+
const diff = Math.abs(got - value);
|
|
2940
|
+
if (diff <= tolerance || !Number.isInteger(got) && diff < 1) {
|
|
1743
2941
|
agrees = true;
|
|
1744
2942
|
continue;
|
|
1745
2943
|
}
|
|
@@ -1750,8 +2948,8 @@ const scanRental = (slug, input) => {
|
|
|
1750
2948
|
if (agrees && PART_KINDS.has(kind) && got <= value) continue;
|
|
1751
2949
|
found.push({
|
|
1752
2950
|
kind,
|
|
1753
|
-
key: `${slug} ${kind} prose=${got} feed=${value}`,
|
|
1754
|
-
message: `The description says ${got}${hedged ? " (approximately)" : ""}, the ${kind} fact says ${value}. Both come from the PMS: the customer corrects one of them there.`
|
|
2951
|
+
key: `${slug} ${kind} prose=${german(got)} feed=${value}`,
|
|
2952
|
+
message: `The description says ${german(got)}${hedged ? " (approximately)" : ""}, the ${kind} fact says ${value}. Both come from the PMS: the customer corrects one of them there.`
|
|
1755
2953
|
});
|
|
1756
2954
|
}
|
|
1757
2955
|
}
|
|
@@ -1780,34 +2978,42 @@ const rentalFacts = {
|
|
|
1780
2978
|
stage: "dist",
|
|
1781
2979
|
begin: (ctx) => {
|
|
1782
2980
|
if (!ctx.hasDist) return null;
|
|
1783
|
-
const accepted = new Set(ctx.options.factCheckAccepted.map((line) => line.trim().split(/\s+/).join(" ")));
|
|
2981
|
+
const accepted = new Set(ctx.options.factCheckAccepted.map((line) => line.trim().split(/\s+/).join(" ")).filter((line) => line !== ""));
|
|
1784
2982
|
const perksFile = path.join(ctx.root, PERKS_FILE);
|
|
1785
2983
|
const perks = fs.existsSync(perksFile) ? [...fs.readFileSync(perksFile, "utf8").matchAll(/^\s*"([^"]+)",\s*$/gm)].map((m) => m[1]) : [];
|
|
1786
2984
|
const findings = [];
|
|
1787
2985
|
const seen = /* @__PURE__ */ new Set();
|
|
1788
2986
|
let marked = 0;
|
|
2987
|
+
let compared = 0;
|
|
2988
|
+
let undescribed = 0;
|
|
2989
|
+
let firstMarked;
|
|
1789
2990
|
let unmarked;
|
|
1790
2991
|
return {
|
|
1791
2992
|
visit: (page) => {
|
|
1792
2993
|
if (page.redirect) return;
|
|
1793
2994
|
const { document } = page;
|
|
1794
2995
|
const stats = [...document.querySelectorAll(MARKERS.stats)];
|
|
1795
|
-
if (stats.length === 0) {
|
|
2996
|
+
if (stats.length === 0 || !isRentalPage(document)) {
|
|
1796
2997
|
if (document.querySelector(FACTS_PART)) unmarked ??= page.path;
|
|
1797
2998
|
return;
|
|
1798
2999
|
}
|
|
1799
3000
|
marked += 1;
|
|
3001
|
+
firstMarked ??= page.path;
|
|
1800
3002
|
const description = document.querySelector(MARKERS.description);
|
|
1801
|
-
if (!description)
|
|
3003
|
+
if (!description) {
|
|
3004
|
+
undescribed += 1;
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
1802
3007
|
const facts = stats.flatMap((row) => [...row.querySelectorAll("span")].map((span) => (span.textContent ?? "").replace(/\s+/g, " ").trim()));
|
|
1803
3008
|
const slug = slugOf(page);
|
|
1804
|
-
const
|
|
3009
|
+
const scanned = scanRental(slug, {
|
|
1805
3010
|
facts,
|
|
1806
3011
|
prose: textOf(description),
|
|
1807
3012
|
amenities: textOf(document.querySelector(MARKERS.amenitiesModal) ?? document.querySelector(MARKERS.amenities)),
|
|
1808
3013
|
perks
|
|
1809
3014
|
});
|
|
1810
|
-
|
|
3015
|
+
compared += scanned.compared;
|
|
3016
|
+
for (const f of scanned.found) {
|
|
1811
3017
|
seen.add(f.key);
|
|
1812
3018
|
if (!accepted.has(f.key)) findings.push({
|
|
1813
3019
|
path: page.path,
|
|
@@ -1820,366 +3026,303 @@ const rentalFacts = {
|
|
|
1820
3026
|
path: unmarked,
|
|
1821
3027
|
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."
|
|
1822
3028
|
});
|
|
1823
|
-
if (
|
|
3029
|
+
if (firstMarked && compared === 0) findings.push({
|
|
3030
|
+
path: firstMarked,
|
|
3031
|
+
message: `${marked === 1 ? "A rental page carries" : `${marked} rental pages carry`} the fact row, but no fact was compared on any of them: ` + (undescribed > 0 ? `${undescribed} of them have no data-rental-description marker on the owner's description, or ` : "") + "no description states a figure the fact row shows (guests, bedrooms, bathrooms, m², beach). Mark the description, or exclude this finding where the descriptions state no figures."
|
|
3032
|
+
});
|
|
3033
|
+
if (compared > 0) {
|
|
1824
3034
|
for (const key of accepted) if (!seen.has(key)) findings.push({ message: `factCheckAccepted lists "${key}", which no longer disagrees: remove the entry.` });
|
|
1825
3035
|
}
|
|
1826
|
-
return findings;
|
|
1827
|
-
}
|
|
1828
|
-
};
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
|
-
//#endregion
|
|
1832
|
-
//#region src/checks/syncOnce.ts
|
|
1833
|
-
const LOADER_FILES = ["src/content.config.ts", "src/content/config.ts"];
|
|
1834
|
-
/** A loader written inline, as opposed to `glob()` or `file()`. */
|
|
1835
|
-
const INLINE_LOADER = /\bloader\s*:\s*\{/;
|
|
1836
|
-
/** It talks to the PMS. */
|
|
1837
|
-
const LIVE_FETCH = /\bfetch\s*\(|createWebsiteSDK|createVofficeSdk|\.static\./;
|
|
1838
|
-
/** The reuse idiom: the loader keeps the sync token in the store's meta and, when the token the
|
|
1839
|
-
* build was started with is still the same, serves the entries it already has. */
|
|
1840
|
-
const REUSE_IDIOM = [
|
|
1841
|
-
/CONTENT_SYNC_TOKEN/,
|
|
1842
|
-
/\bmeta\.get\(/,
|
|
1843
|
-
/\bstore\.keys\(\)/
|
|
1844
|
-
];
|
|
1845
|
-
/** `astro check` and `astro build` each run the content loader, so an unguarded loader pays every
|
|
1846
|
-
* remote fetch twice on every build, against a rate-limited PMS. The build worker starts both with
|
|
1847
|
-
* one `CONTENT_SYNC_TOKEN`; a loader that keys its store on it syncs once. A text heuristic, hence
|
|
1848
|
-
* a warning. */
|
|
1849
|
-
const syncOnce = {
|
|
1850
|
-
id: "sync-once",
|
|
1851
|
-
title: "Content loaders sync the PMS once per build",
|
|
1852
|
-
severity: "warning",
|
|
1853
|
-
stage: "src",
|
|
1854
|
-
begin: (ctx) => {
|
|
1855
|
-
const loader = ctx.sourceFiles(/* @__PURE__ */ new Set([".ts"])).find((file) => LOADER_FILES.includes(ctx.rel(file)));
|
|
1856
|
-
if (!loader) return null;
|
|
1857
|
-
return { finish: () => {
|
|
1858
|
-
const text = ctx.readSource(loader);
|
|
1859
|
-
if (!INLINE_LOADER.test(text) || !LIVE_FETCH.test(text)) return [];
|
|
1860
|
-
if (REUSE_IDIOM.every((idiom) => idiom.test(text))) return [];
|
|
1861
|
-
return [{
|
|
1862
|
-
path: ctx.rel(loader),
|
|
1863
|
-
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."
|
|
1864
|
-
}];
|
|
1865
|
-
} };
|
|
1866
|
-
}
|
|
1867
|
-
};
|
|
1868
|
-
//#endregion
|
|
1869
|
-
//#region src/env.ts
|
|
1870
|
-
/** The env files a production build reads, in the order Vite applies them (a later file wins per
|
|
1871
|
-
* key). The `.local` pair is left out on purpose: it is the developer's machine, never what the
|
|
1872
|
-
* deployed site builds against, and a site must not commit it. */
|
|
1873
|
-
const BUILD_ENV_FILES = [".env", ".env.production"];
|
|
1874
|
-
/** Files Vite loads after the committed ones in every mode; committed, they win in CI too. */
|
|
1875
|
-
const LOCAL_ENV_FILES = [".env.local", ".env.production.local"];
|
|
1876
|
-
const ASSIGNMENT = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;
|
|
1877
|
-
/** `KEY=value` lines of one env file: `export` allowed, a value in matching quotes unquoted, a
|
|
1878
|
-
* ` # comment` after the value (quoted or not) dropped. The last assignment of a key wins. */
|
|
1879
|
-
const parseEnv = (text) => {
|
|
1880
|
-
const env = {};
|
|
1881
|
-
for (const line of text.split(/\r?\n/)) {
|
|
1882
|
-
const match = ASSIGNMENT.exec(line);
|
|
1883
|
-
if (!match) continue;
|
|
1884
|
-
let value = match[2].trim();
|
|
1885
|
-
const quoted = /^(["'])(.*?)\1(?:\s+#.*)?$/.exec(value);
|
|
1886
|
-
value = quoted ? quoted[2] : value.replace(/\s+#.*$/, "").trim();
|
|
1887
|
-
env[match[1]] = value;
|
|
1888
|
-
}
|
|
1889
|
-
return env;
|
|
1890
|
-
};
|
|
1891
|
-
const readEnvFile = (root, file) => {
|
|
1892
|
-
const full = path.join(root, file);
|
|
1893
|
-
return fs.existsSync(full) ? parseEnv(fs.readFileSync(full, "utf8")) : {};
|
|
1894
|
-
};
|
|
1895
|
-
/** What a production build of the site reads from its committed env files. */
|
|
1896
|
-
const buildEnv = (root) => Object.assign({}, ...BUILD_ENV_FILES.map((file) => readEnvFile(root, file)));
|
|
1897
|
-
/** The SDK's env names (`SDK_ENV` in `@v-office/website-headless`) a build reads, and the two v9
|
|
1898
|
-
* config switches of the Website SDK CLI. */
|
|
1899
|
-
const SDK_NAMES = [
|
|
1900
|
-
"CMS_BACKEND",
|
|
1901
|
-
"CMS_STAGE",
|
|
1902
|
-
"HUB_API_KEY",
|
|
1903
|
-
"HUB_GRAPHQL_URL",
|
|
1904
|
-
"HUB_V0_API_BASE_URL",
|
|
1905
|
-
"HUB_V1_API_BASE_URL",
|
|
1906
|
-
"IMAGE_PROXY_BASE_URL",
|
|
1907
|
-
"HUB_RENTAL_SCOPE_PROPERTY_KIND",
|
|
1908
|
-
"HUB_RENTAL_IDS_SEARCH"
|
|
1909
|
-
];
|
|
1910
|
-
/** The SDK env the build runs with, resolved the way the site starter does: a value in the
|
|
1911
|
-
* process env wins over the committed files (Vite's order), and what neither sets comes from what
|
|
1912
|
-
* AI Studio's builder passes: the website's PMS generation as `PMS_BACKEND`, its key as
|
|
1913
|
-
* `PMS_TOKEN`. A template site commits no backend, so without the fallback a v9 site there would
|
|
1914
|
-
* read as no site at all. */
|
|
1915
|
-
const sdkEnv = (root, processEnv = process.env) => {
|
|
1916
|
-
const env = {};
|
|
1917
|
-
for (const [name, value] of Object.entries(buildEnv(root))) if (value.trim()) env[name] = value.trim();
|
|
1918
|
-
for (const name of SDK_NAMES) {
|
|
1919
|
-
const value = processEnv[name]?.trim();
|
|
1920
|
-
if (value) env[name] = value;
|
|
1921
|
-
}
|
|
1922
|
-
if (!env.CMS_BACKEND && processEnv.PMS_BACKEND?.trim()) env.CMS_BACKEND = processEnv.PMS_BACKEND.trim();
|
|
1923
|
-
if (env.CMS_BACKEND === "v9" && !env.HUB_API_KEY && processEnv.PMS_TOKEN?.trim()) env.HUB_API_KEY = processEnv.PMS_TOKEN.trim();
|
|
1924
|
-
return env;
|
|
1925
|
-
};
|
|
1926
|
-
/** What the developer's `.local` files set. */
|
|
1927
|
-
const localEnv = (root) => Object.assign({}, ...LOCAL_ENV_FILES.map((file) => readEnvFile(root, file)));
|
|
1928
|
-
//#endregion
|
|
1929
|
-
//#region src/checks/v9.ts
|
|
1930
|
-
/** The be-on! Hub endpoints per stage, as `@v-office/website-headless` resolves `CMS_STAGE` for v9
|
|
1931
|
-
* (`sdk/endpoints.ts`). Production is what a live v9 site calls. */
|
|
1932
|
-
const HUB = {
|
|
1933
|
-
production: {
|
|
1934
|
-
api: "https://api.voffice.be-on.io",
|
|
1935
|
-
imageProxy: "https://imgproxy.voffice.be-on.io"
|
|
1936
|
-
},
|
|
1937
|
-
development: {
|
|
1938
|
-
api: "https://api.voffice.demo-on.de",
|
|
1939
|
-
imageProxy: "https://imgproxy.voffice.demo-on.de"
|
|
1940
|
-
}
|
|
1941
|
-
};
|
|
1942
|
-
const hubUrls = (stage) => ({
|
|
1943
|
-
HUB_V1_API_BASE_URL: `${HUB[stage].api}/api/v1`,
|
|
1944
|
-
HUB_V0_API_BASE_URL: `${HUB[stage].api}/api/v0`,
|
|
1945
|
-
HUB_GRAPHQL_URL: `${HUB[stage].api}/graphql`,
|
|
1946
|
-
IMAGE_PROXY_BASE_URL: HUB[stage].imageProxy
|
|
1947
|
-
});
|
|
1948
|
-
/** The build's SDK env, when it builds a v9 site: `CMS_BACKEND=v9` from the process env, the
|
|
1949
|
-
* committed `.env` / `.env.production`, or AI Studio's `PMS_BACKEND` (`sdkEnv`). Every v9 check
|
|
1950
|
-
* starts here, so a v10 site, or one with no backend at all, never runs one. */
|
|
1951
|
-
const v9Env = (ctx) => {
|
|
1952
|
-
const env = sdkEnv(ctx.root);
|
|
1953
|
-
return env.CMS_BACKEND === "v9" ? env : null;
|
|
3036
|
+
return findings;
|
|
3037
|
+
}
|
|
3038
|
+
};
|
|
3039
|
+
}
|
|
1954
3040
|
};
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
3041
|
+
//#endregion
|
|
3042
|
+
//#region src/checks/robotsTxt.ts
|
|
3043
|
+
/** The extensions an Astro endpoint is written in. */
|
|
3044
|
+
const ENDPOINT_EXTENSIONS = [
|
|
3045
|
+
".ts",
|
|
3046
|
+
".js",
|
|
3047
|
+
".mjs",
|
|
3048
|
+
".mts"
|
|
3049
|
+
];
|
|
3050
|
+
/** A site that generates robots.txt (`src/pages/robots.txt.ts`) ships no `public/robots.txt`
|
|
3051
|
+
* beside it: both answer `/robots.txt`, and which one the build keeps is not the site's choice. */
|
|
3052
|
+
const robotsTxt = {
|
|
3053
|
+
id: "robots-txt",
|
|
3054
|
+
title: "One file answers /robots.txt",
|
|
3055
|
+
severity: "error",
|
|
3056
|
+
stage: "src",
|
|
3057
|
+
begin: (ctx) => {
|
|
3058
|
+
const generator = ENDPOINT_EXTENSIONS.map((ext) => path.join(ctx.srcDir, "pages", `robots.txt${ext}`)).find((file) => fs.existsSync(file));
|
|
3059
|
+
const file = path.join(ctx.publicDir, "robots.txt");
|
|
3060
|
+
if (!generator) return null;
|
|
3061
|
+
return { finish: () => fs.existsSync(file) ? [{
|
|
3062
|
+
path: ctx.rel(file),
|
|
3063
|
+
message: `${ctx.rel(file)} and the generator ${ctx.rel(generator)} both answer /robots.txt. Delete ${ctx.rel(file)} and keep any rule it adds in the generator.`
|
|
3064
|
+
}] : [] };
|
|
3065
|
+
}
|
|
1975
3066
|
};
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
*
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
3067
|
+
//#endregion
|
|
3068
|
+
//#region src/checks/sitemapNoindex.ts
|
|
3069
|
+
const SITEMAP = /^sitemap[^/]*\.xml$/;
|
|
3070
|
+
const SITEMAP_INDEX = "sitemap-index.xml";
|
|
3071
|
+
const LLMS = "llms.txt";
|
|
3072
|
+
/** What keeps an `llms.txt` from the llms.txt spec's shape: a `# ` heading naming the site on the
|
|
3073
|
+
* first line, a `> ` summary above the first section, `## ` sections of links. The content is the
|
|
3074
|
+
* site's; only the shape is checked. A blockquote below the first section is no summary. */
|
|
3075
|
+
const llmsShape = (text) => {
|
|
3076
|
+
const body = text.split(/\r?\n/).filter((line) => line.trim() !== "");
|
|
3077
|
+
const problems = [];
|
|
3078
|
+
if (!body[0]?.startsWith("# ")) problems.push("no `# ` heading naming the site on the first line");
|
|
3079
|
+
const firstSection = body.findIndex((line) => line.startsWith("## "));
|
|
3080
|
+
if (!(firstSection === -1 ? body : body.slice(0, firstSection)).some((line) => line.startsWith("> "))) problems.push("no `> ` summary above the first section");
|
|
3081
|
+
if (firstSection === -1) problems.push("no `## ` section");
|
|
3082
|
+
return problems;
|
|
3083
|
+
};
|
|
3084
|
+
/** The URL lists the build publishes agree with the pages it built: no sitemap entry whose own page
|
|
3085
|
+
* says noindex or is not in the build, an `llms.txt` in the spec's shape and without a link to a
|
|
3086
|
+
* page that is not there. Every `sitemap*.xml` of the build is read, and every sitemap an index
|
|
3087
|
+
* names. Skipped when the build publishes neither. While every page is noindex (a site before
|
|
3088
|
+
* launch, under its blanket robots meta; the 404 page and redirect stubs do not count), a sitemap
|
|
3089
|
+
* listing them is not refused: that disagreement ends with the launch. */
|
|
3090
|
+
const sitemapNoindex = {
|
|
3091
|
+
id: "sitemap-noindex",
|
|
3092
|
+
title: "Published URL lists match the built pages",
|
|
3093
|
+
severity: "error",
|
|
1987
3094
|
stage: "dist",
|
|
1988
3095
|
begin: (ctx) => {
|
|
1989
|
-
|
|
1990
|
-
if (!
|
|
3096
|
+
if (!ctx.hasDist) return null;
|
|
3097
|
+
if (!ctx.files.some((f) => SITEMAP.test(f)) && !ctx.has(LLMS)) return null;
|
|
3098
|
+
const noindex = /* @__PURE__ */ new Set();
|
|
1991
3099
|
let launched = false;
|
|
1992
3100
|
return {
|
|
1993
3101
|
visit: (page) => {
|
|
1994
|
-
if (
|
|
3102
|
+
if (page.redirect) return;
|
|
3103
|
+
if (page.noindex) noindex.add(normalize(page.url));
|
|
3104
|
+
else if (isIndexable(page)) launched = true;
|
|
1995
3105
|
},
|
|
1996
|
-
finish:
|
|
1997
|
-
|
|
1998
|
-
const findings = [];
|
|
1999
|
-
const
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
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.`
|
|
3106
|
+
finish: () => {
|
|
3107
|
+
const { entries, missing } = readSitemaps(ctx);
|
|
3108
|
+
const findings = [...missing];
|
|
3109
|
+
for (const { sitemap, loc, path } of entries) if (!ctx.serves(path)) findings.push({
|
|
3110
|
+
path: sitemap,
|
|
3111
|
+
message: `The sitemap lists ${loc}, which is not in the build.`
|
|
2003
3112
|
});
|
|
2004
|
-
if (
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
const
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
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.`
|
|
3113
|
+
else if (launched && noindex.has(path)) findings.push({
|
|
3114
|
+
path: sitemap,
|
|
3115
|
+
message: `The sitemap lists ${loc}, whose page says noindex: the sitemap filter and the noindex routes disagree.`
|
|
3116
|
+
});
|
|
3117
|
+
if (ctx.has(LLMS)) {
|
|
3118
|
+
const text = ctx.read(LLMS);
|
|
3119
|
+
const shape = llmsShape(text);
|
|
3120
|
+
if (shape.length > 0) findings.push({
|
|
3121
|
+
path: LLMS,
|
|
3122
|
+
message: `llms.txt does not follow the spec's shape: ${shape.join("; ")}. Start with \`# \` and the site's name, a \`> \` summary, then \`## \` sections of links.`
|
|
2015
3123
|
});
|
|
3124
|
+
for (const match of text.matchAll(/\]\(([^)\s]+)\)/g)) {
|
|
3125
|
+
const link = match[1];
|
|
3126
|
+
if (/^(?:mailto|tel):|^#/i.test(link)) continue;
|
|
3127
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(link)) {
|
|
3128
|
+
if (!ctx.config.site) continue;
|
|
3129
|
+
let host;
|
|
3130
|
+
try {
|
|
3131
|
+
host = new URL(link).host;
|
|
3132
|
+
} catch {
|
|
3133
|
+
continue;
|
|
3134
|
+
}
|
|
3135
|
+
if (host !== new URL(ctx.config.site).host) continue;
|
|
3136
|
+
}
|
|
3137
|
+
if (!ctx.serves(toPath(link))) findings.push({
|
|
3138
|
+
path: LLMS,
|
|
3139
|
+
message: `llms.txt links ${link}, which is not in the build.`
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
2016
3142
|
}
|
|
2017
|
-
const key = env.HUB_API_KEY;
|
|
2018
|
-
if (key && key === localEnv(ctx.root).HUB_API_KEY) findings.push({
|
|
2019
|
-
path: ".env",
|
|
2020
|
-
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."
|
|
2021
|
-
});
|
|
2022
3143
|
return findings;
|
|
2023
3144
|
}
|
|
2024
3145
|
};
|
|
2025
3146
|
}
|
|
2026
3147
|
};
|
|
2027
|
-
/**
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
3148
|
+
/** Every indexable page is in the sitemap, and a build with `sitemap-index.xml` also serves
|
|
3149
|
+
* `/sitemap.xml`, the URL tools and search consoles try first (static hosting redirects nothing).
|
|
3150
|
+
* A warning: a page can be left out for a reason this cannot see. Skipped without a sitemap. */
|
|
3151
|
+
const sitemapCoverage = {
|
|
3152
|
+
id: "sitemap-coverage",
|
|
3153
|
+
title: "The sitemap covers the indexable pages",
|
|
3154
|
+
severity: "warning",
|
|
3155
|
+
stage: "dist",
|
|
3156
|
+
begin: (ctx) => {
|
|
3157
|
+
if (!ctx.hasDist || !ctx.files.some((f) => SITEMAP.test(f))) return null;
|
|
3158
|
+
const listed = new Set(readSitemaps(ctx).entries.map((entry) => entry.path));
|
|
3159
|
+
const findings = [];
|
|
3160
|
+
if (ctx.has(SITEMAP_INDEX) && !ctx.has("sitemap.xml")) findings.push({
|
|
3161
|
+
path: SITEMAP_INDEX,
|
|
3162
|
+
message: "sitemap-index.xml has no /sitemap.xml beside it, the URL tools and search consoles try first: write a copy of the index as sitemap.xml at build time."
|
|
3163
|
+
});
|
|
3164
|
+
return {
|
|
3165
|
+
visit: (page) => {
|
|
3166
|
+
if (isIndexable(page) && !listed.has(normalize(page.url))) findings.push({
|
|
3167
|
+
path: page.path,
|
|
3168
|
+
message: `${page.url} is indexable but not in the sitemap: list it, or give it noindex if it must stay out.`
|
|
3169
|
+
});
|
|
3170
|
+
},
|
|
3171
|
+
finish: () => findings
|
|
3172
|
+
};
|
|
3173
|
+
}
|
|
2044
3174
|
};
|
|
2045
|
-
|
|
3175
|
+
//#endregion
|
|
3176
|
+
//#region src/checks/syncOnce.ts
|
|
3177
|
+
const LOADER_FILES = ["src/content.config.ts", "src/content/config.ts"];
|
|
3178
|
+
/** A loader written inline, as opposed to `glob()` or `file()`. */
|
|
3179
|
+
const INLINE_LOADER = /\bloader\s*:\s*\{/;
|
|
3180
|
+
/** It talks to the PMS: a fetch, the SDK by its factory or its package (imported under any name),
|
|
3181
|
+
* or a store it clears to fill again. */
|
|
3182
|
+
const LIVE_FETCH = /\bfetch\s*\(|createWebsiteSDK|createVofficeSdk|\.static\.|["']@v-office\/website-(?:sdk|headless)\b|\bstore\.clear\(\)/;
|
|
3183
|
+
/** The reuse idiom: the loader keeps the sync token in the store's meta and, when the token the
|
|
3184
|
+
* build was started with is still the same, serves the entries it already has. */
|
|
3185
|
+
const REUSE_IDIOM = [
|
|
3186
|
+
/CONTENT_SYNC_TOKEN/,
|
|
3187
|
+
/\bmeta\.get\(/,
|
|
3188
|
+
/\bstore\.keys\(\)/
|
|
3189
|
+
];
|
|
3190
|
+
/** A script that runs the type check and then the build in one shell. */
|
|
3191
|
+
const CHECK_THEN_BUILD = /\bastro\s+check\b[\s\S]*\bastro\s+build\b/;
|
|
3192
|
+
/** The `package.json` scripts that chain `astro check` and `astro build` without minting a
|
|
3193
|
+
* `CONTENT_SYNC_TOKEN`: run from a shell that sets none, the loader syncs the PMS in both. */
|
|
3194
|
+
const tokenlessScripts = (root) => {
|
|
2046
3195
|
try {
|
|
2047
|
-
const
|
|
2048
|
-
return
|
|
3196
|
+
const { scripts } = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
3197
|
+
return Object.entries(scripts ?? {}).filter(([, script]) => typeof script === "string" && CHECK_THEN_BUILD.test(script) && !script.includes("CONTENT_SYNC_TOKEN")).map(([name]) => name);
|
|
2049
3198
|
} catch {
|
|
2050
|
-
return
|
|
3199
|
+
return [];
|
|
2051
3200
|
}
|
|
2052
3201
|
};
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
code: err ? typeof err.code === "number" ? err.code : 1 : 0,
|
|
2062
|
-
output: `${stdout}${stderr}`.trim()
|
|
2063
|
-
}));
|
|
2064
|
-
});
|
|
2065
|
-
};
|
|
2066
|
-
/** Every be-on! Hub filter the site's search needs (the scope filter, the Merkliste's rental-id
|
|
2067
|
-
* filter, each searchable backend-filter definition) exists in the Hub the site builds against.
|
|
2068
|
-
* A filter the Hub does not serve matches nothing, or everything once a date is set. Asks the Hub
|
|
2069
|
-
* through the site's own `website-sdk hub-filters check`, with the build's env and the SDK
|
|
2070
|
-
* options in `hubFilterOptions`. A warning: the outcome is the Hub's data, and a Hub that cannot be
|
|
2071
|
-
* asked must not stop the nightly builds; it is reported, never passed. v9 only. */
|
|
2072
|
-
const v9HubFilters = {
|
|
2073
|
-
id: "v9-hub-filters",
|
|
2074
|
-
title: "The be-on! Hub serves the filters the v9 site needs",
|
|
3202
|
+
/** `astro check` and `astro build` each run the content loader, so an unguarded loader pays every
|
|
3203
|
+
* remote fetch twice on every build, against a rate-limited PMS. The build worker starts both with
|
|
3204
|
+
* one `CONTENT_SYNC_TOKEN`; a loader that keys its store on it syncs once. A loader that does is
|
|
3205
|
+
* then let down by a `package.json` script that chains the two without a token, also reported.
|
|
3206
|
+
* A text heuristic, hence a warning. */
|
|
3207
|
+
const syncOnce = {
|
|
3208
|
+
id: "sync-once",
|
|
3209
|
+
title: "Content loaders sync the PMS once per build",
|
|
2075
3210
|
severity: "warning",
|
|
2076
3211
|
stage: "src",
|
|
2077
3212
|
begin: (ctx) => {
|
|
2078
|
-
const
|
|
2079
|
-
if (!
|
|
2080
|
-
return { finish:
|
|
2081
|
-
const
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
if (
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
"--backend",
|
|
2093
|
-
"v9",
|
|
2094
|
-
"--config",
|
|
2095
|
-
configFile,
|
|
2096
|
-
"--options",
|
|
2097
|
-
optionsFile,
|
|
2098
|
-
"hub-filters",
|
|
2099
|
-
"check"
|
|
2100
|
-
], ctx.root);
|
|
2101
|
-
if (code === 0) return [];
|
|
2102
|
-
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.` }];
|
|
2103
|
-
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.` }];
|
|
2104
|
-
} finally {
|
|
2105
|
-
fs.rmSync(dir, {
|
|
2106
|
-
recursive: true,
|
|
2107
|
-
force: true
|
|
2108
|
-
});
|
|
2109
|
-
}
|
|
3213
|
+
const loader = ctx.sourceFiles(/* @__PURE__ */ new Set([".ts"])).find((file) => LOADER_FILES.includes(ctx.rel(file)));
|
|
3214
|
+
if (!loader) return null;
|
|
3215
|
+
return { finish: () => {
|
|
3216
|
+
const text = ctx.readSource(loader);
|
|
3217
|
+
const code = text.replace(/^\s*import\s+type\b[\s\S]*?\bfrom\s*["'][^"'\n]*["'];?/gm, "").replace(/^\s*import\s*\{([^}]*)\}\s*from\s*["'][^"'\n]*["'];?/gm, (line, names) => names.split(",").map((n) => n.trim()).filter(Boolean).every((n) => /^type\s/.test(n)) ? "" : line);
|
|
3218
|
+
if (!INLINE_LOADER.test(text) || !LIVE_FETCH.test(code)) return [];
|
|
3219
|
+
if (REUSE_IDIOM.every((idiom) => idiom.test(text))) return tokenlessScripts(ctx.root).map((name) => ({
|
|
3220
|
+
path: "package.json",
|
|
3221
|
+
message: `The "${name}" script runs astro check and astro build without a CONTENT_SYNC_TOKEN, so the content loader syncs the PMS in both. Set one token for the pair (export CONTENT_SYNC_TOKEN="\$(date +%s)" && astro check && astro build) or run site-checks verify.`
|
|
3222
|
+
}));
|
|
3223
|
+
return [{
|
|
3224
|
+
path: ctx.rel(loader),
|
|
3225
|
+
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."
|
|
3226
|
+
}];
|
|
2110
3227
|
} };
|
|
2111
3228
|
}
|
|
2112
3229
|
};
|
|
2113
3230
|
//#endregion
|
|
2114
3231
|
//#region src/checks/viewSource.ts
|
|
2115
|
-
/** Comments the frameworks themselves write into static HTML, and no developer did
|
|
2116
|
-
* island and server-island
|
|
2117
|
-
*
|
|
2118
|
-
*
|
|
2119
|
-
*
|
|
3232
|
+
/** Comments the frameworks themselves write into static HTML, and no developer did, matched
|
|
3233
|
+
* exactly on the trimmed comment text: Astro's island end and server-island start, React 19's
|
|
3234
|
+
* form-state and document markers, Vue's teleport markers and its placeholder for a false `v-if`
|
|
3235
|
+
* (`createCommentVNode("v-if")`, e.g. a closed reka-ui dialog portal). A comment without a letter
|
|
3236
|
+
* or digit is a marker too and needs no entry (React's `<!--$-->`, `<!--/$-->`, `<!-- -->`, Vue's
|
|
3237
|
+
* `<!--[-->`, `<!--]-->`): it has nothing to say. Named exactly, so `<!--astro: TODO-->` is a
|
|
3238
|
+
* note. A framework upgrade that adds a marker shows up as a refused build; extend the list here,
|
|
3239
|
+
* in one place. */
|
|
2120
3240
|
const FRAMEWORK_COMMENTS = /* @__PURE__ */ new Set([
|
|
2121
|
-
"",
|
|
2122
|
-
"
|
|
2123
|
-
"/$",
|
|
2124
|
-
"$!",
|
|
2125
|
-
"$?",
|
|
2126
|
-
"&",
|
|
2127
|
-
"/&",
|
|
3241
|
+
"astro:end",
|
|
3242
|
+
"[if astro]>server-island-start<![endif]",
|
|
2128
3243
|
"F",
|
|
2129
3244
|
"F!",
|
|
2130
3245
|
"html",
|
|
2131
3246
|
"head",
|
|
2132
3247
|
"body",
|
|
2133
|
-
"[",
|
|
2134
|
-
"]",
|
|
2135
3248
|
"teleport start",
|
|
2136
3249
|
"teleport end",
|
|
2137
3250
|
"v-if"
|
|
2138
3251
|
]);
|
|
3252
|
+
const WORDLESS = /^[^\p{L}\p{N}]*$/u;
|
|
2139
3253
|
const isFrameworkComment = (data) => {
|
|
2140
3254
|
const text = data.trim();
|
|
2141
|
-
return
|
|
2142
|
-
};
|
|
2143
|
-
/** Licence banners
|
|
2144
|
-
const
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
3255
|
+
return WORDLESS.test(text) || FRAMEWORK_COMMENTS.has(text);
|
|
3256
|
+
};
|
|
3257
|
+
/** Licence banners (`/*!`, `//!`, `@license`, `@preserve`) survive minification on purpose. */
|
|
3258
|
+
const LEGAL_COMMENT = /^\/[*/]!|@license|@preserve/;
|
|
3259
|
+
/** Markers a build tool writes into its own output, named exactly: a note that merely mentions
|
|
3260
|
+
* one (`/* @todo … *\/`) is still a note. */
|
|
3261
|
+
const TOOL_MARKER = /^\/\*\s*(?:empty css|@vite-ignore|[#@]__PURE__|[#@]__NO_SIDE_EFFECTS__)\s*\*\/$/;
|
|
3262
|
+
/** A library the site ships as it comes, from `public/`: minified (`*.min.js`), in a `vendor/`
|
|
3263
|
+
* folder, or opening with a licence banner. Its notes are its authors', not the site's to remove. */
|
|
3264
|
+
const VENDORED_NAME = /(?:^|\/)vendor\/|\.min\.(?:m?js|css)$/;
|
|
3265
|
+
const VENDORED_BANNER = /^\s*\/\*!|^\s*\/\*[\s\S]{0,400}?@license/;
|
|
3266
|
+
const vendored = (ctx, file, text) => fs.existsSync(path.join(ctx.publicDir, file)) && (VENDORED_NAME.test(file) || VENDORED_BANNER.test(text.slice(0, 600)));
|
|
3267
|
+
/** A source-map pointer, reported on its own. */
|
|
3268
|
+
const SOURCE_MAP_URL = /(?:\/\/|\/\*)[#@] sourceMappingURL=/;
|
|
3269
|
+
/** A comment that tells a visitor nothing of the developer's. */
|
|
3270
|
+
const saysNothing = (comment) => LEGAL_COMMENT.test(comment) || TOOL_MARKER.test(comment) || SOURCE_MAP_URL.test(comment) || WORDLESS.test(comment);
|
|
3271
|
+
/** CSS has one comment form; a string may hold `/*` (`content: "/*"`). */
|
|
3272
|
+
const cssComments = (text) => {
|
|
3273
|
+
const comments = [];
|
|
3274
|
+
let i = 0;
|
|
3275
|
+
while (i < text.length) {
|
|
3276
|
+
const c = text[i];
|
|
3277
|
+
if (c === "'" || c === "\"") {
|
|
3278
|
+
i += 1;
|
|
3279
|
+
while (i < text.length && text[i] !== c && text[i] !== "\n") i += text[i] === "\\" ? 2 : 1;
|
|
3280
|
+
i += 1;
|
|
3281
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
3282
|
+
const close = text.indexOf("*/", i + 2);
|
|
3283
|
+
const end = close === -1 ? text.length : close + 2;
|
|
3284
|
+
comments.push(text.slice(i, end));
|
|
3285
|
+
i = end;
|
|
3286
|
+
} else i += 1;
|
|
3287
|
+
}
|
|
3288
|
+
return comments;
|
|
3289
|
+
};
|
|
2150
3290
|
const excerpt = (text) => {
|
|
2151
3291
|
const flat = text.replace(/\s+/g, " ").trim();
|
|
2152
3292
|
return flat.length > 80 ? `${flat.slice(0, 79)}…` : flat;
|
|
2153
3293
|
};
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
* the same line is not read, and `//#` and `//!` are directives (source maps, legal comments),
|
|
2158
|
-
* reported or allowed on their own. */
|
|
2159
|
-
const lineComments = (text) => findComments(text).filter(({ start, text: comment }) => {
|
|
2160
|
-
if (!comment.startsWith("//") || DIRECTIVE.test(comment)) return false;
|
|
2161
|
-
let k = start;
|
|
2162
|
-
while (k > 0 && (text[k - 1] === " " || text[k - 1] === " ")) k -= 1;
|
|
2163
|
-
return k === 0 || LINE_BREAK.has(text[k - 1]);
|
|
2164
|
-
}).map((comment) => comment.text);
|
|
2165
|
-
/** The site's own text files, where a comment it wrote into an inline script, style or handler
|
|
2166
|
-
* lives. */
|
|
2167
|
-
const SOURCE_EXTENSIONS = new Set(".astro .tsx .jsx .ts .js .mjs .cjs .css .scss .vue .md .mdx .html .json .svg".split(" "));
|
|
3294
|
+
/** The project's own text files, where a comment it wrote lives: `src/`, `public/`, the Astro
|
|
3295
|
+
* config and the integrations it injects from. */
|
|
3296
|
+
const SOURCE_EXTENSIONS = new Set(".astro .tsx .jsx .ts .mts .cts .js .mjs .cjs .css .scss .sass .less .vue .svelte .md .mdx .mdoc .html .json .svg".split(" "));
|
|
2168
3297
|
/** Below this length a comment's inner text appears in almost any source by accident; such a
|
|
2169
3298
|
* comment is matched whole, with its markers. */
|
|
2170
3299
|
const MIN_INNER_TEXT = 8;
|
|
2171
3300
|
const collapse = (text) => text.replace(/\s+/g, " ").trim();
|
|
2172
|
-
/**
|
|
2173
|
-
*
|
|
2174
|
-
*
|
|
2175
|
-
|
|
3301
|
+
/** Every text file of the project, as the old guard's `git grep -- . ':!dist'` read it: the
|
|
3302
|
+
* build's output, `node_modules` and dot folders (`.git`, `.astro`) are no source. No git call, so
|
|
3303
|
+
* a checkout without `.git` reads the same. */
|
|
3304
|
+
const projectFiles = (ctx) => {
|
|
3305
|
+
const root = path.resolve(ctx.root);
|
|
3306
|
+
const dist = path.resolve(ctx.distDir) + path.sep;
|
|
3307
|
+
return fs.readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
|
|
3308
|
+
const full = path.join(root, entry.name);
|
|
3309
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") return [];
|
|
3310
|
+
if (entry.isDirectory()) return [...filesUnder(full, SOURCE_EXTENSIONS)];
|
|
3311
|
+
return SOURCE_EXTENSIONS.has(path.extname(entry.name).toLowerCase()) ? [full] : [];
|
|
3312
|
+
}).filter((file) => !file.startsWith(dist));
|
|
3313
|
+
};
|
|
3314
|
+
/** Whether the site wrote a comment found in an inline script, style or attribute, or in a shipped
|
|
3315
|
+
* JS or CSS file: its text, whitespace collapsed, appears in a file of the project. A comment in
|
|
3316
|
+
* none of them was rendered or bundled from a dependency (c15t's theme `<style>` in the consent
|
|
3317
|
+
* kit, a library's banner in `_astro/`) and is not the site's to remove. The files are read once,
|
|
3318
|
+
* on the first such comment. */
|
|
2176
3319
|
const siteWrote = (ctx) => {
|
|
2177
3320
|
let corpus;
|
|
2178
3321
|
const seen = /* @__PURE__ */ new Map();
|
|
2179
3322
|
return (comment) => {
|
|
2180
3323
|
let wrote = seen.get(comment);
|
|
2181
3324
|
if (wrote === void 0) {
|
|
2182
|
-
corpus ??=
|
|
3325
|
+
corpus ??= projectFiles(ctx).map((file) => collapse(ctx.readSource(file))).join("\n");
|
|
2183
3326
|
const inner = collapse(comment.startsWith("//") ? comment.slice(2) : comment.slice(2, -2));
|
|
2184
3327
|
wrote = corpus.includes(inner.length < MIN_INNER_TEXT ? collapse(comment) : inner);
|
|
2185
3328
|
seen.set(comment, wrote);
|
|
@@ -2187,6 +3330,93 @@ const siteWrote = (ctx) => {
|
|
|
2187
3330
|
return wrote;
|
|
2188
3331
|
};
|
|
2189
3332
|
};
|
|
3333
|
+
/** What a visitor can read with View Source, and no developer meant for them: every HTML comment
|
|
3334
|
+
* in the built pages, before and after `<html>` included; comments in their inline scripts,
|
|
3335
|
+
* styles, `style` attributes and event handlers, and in every shipped JS and CSS file (`_astro/`
|
|
3336
|
+
* and `public/` alike), that the project's own files contain; source maps and references to them
|
|
3337
|
+
* in every shipped file. Scripts and handlers are read as JavaScript and styles as CSS, so `//` in
|
|
3338
|
+
* `"https://…"`, a regular expression or a shader in a template literal is text. Vite minifies
|
|
3339
|
+
* what it bundles, so a comment left in `_astro/` is a licence banner (allowed) or a dependency's
|
|
3340
|
+
* (not in the project's files). */
|
|
3341
|
+
const viewSource = {
|
|
3342
|
+
id: "view-source",
|
|
3343
|
+
title: "Developer notes visible in View Source",
|
|
3344
|
+
severity: "error",
|
|
3345
|
+
stage: "dist",
|
|
3346
|
+
begin: (ctx) => {
|
|
3347
|
+
if (!ctx.hasDist) return null;
|
|
3348
|
+
const findings = [];
|
|
3349
|
+
const report = (path, what, text) => findings.push({
|
|
3350
|
+
path,
|
|
3351
|
+
message: `${what}: "${excerpt(text)}"`
|
|
3352
|
+
});
|
|
3353
|
+
const wrote = siteWrote(ctx);
|
|
3354
|
+
const reportWritten = (path, what, comments) => {
|
|
3355
|
+
for (const comment of comments) if (!saysNothing(comment) && wrote(comment)) report(path, what, comment);
|
|
3356
|
+
};
|
|
3357
|
+
const visit = (page) => {
|
|
3358
|
+
for (const comment of page.comments()) if (!isFrameworkComment(comment)) report(page.path, "HTML comment in the page", comment);
|
|
3359
|
+
for (const el of page.document.querySelectorAll("*")) for (const name of el.getAttributeNames()) {
|
|
3360
|
+
const isStyle = name === "style";
|
|
3361
|
+
if (!isStyle && !name.startsWith("on")) continue;
|
|
3362
|
+
const code = el.getAttribute(name) ?? "";
|
|
3363
|
+
if (isStyle) reportWritten(page.path, "comment in an inline style", cssComments(code));
|
|
3364
|
+
else reportWritten(page.path, `comment in an inline ${name} handler`, jsComments(code));
|
|
3365
|
+
}
|
|
3366
|
+
for (const el of page.document.querySelectorAll("script, style")) {
|
|
3367
|
+
const text = el.textContent ?? "";
|
|
3368
|
+
const tag = el.tagName.toLowerCase();
|
|
3369
|
+
if (SOURCE_MAP_URL.test(text)) report(page.path, `source map reference in an inline <${tag}>`, text);
|
|
3370
|
+
const comments = tag === "script" ? jsComments(text) : cssComments(text);
|
|
3371
|
+
reportWritten(page.path, `comment in an inline <${tag}>`, comments);
|
|
3372
|
+
}
|
|
3373
|
+
};
|
|
3374
|
+
const finish = () => {
|
|
3375
|
+
for (const file of ctx.files) {
|
|
3376
|
+
if (file.endsWith(".map")) {
|
|
3377
|
+
findings.push({
|
|
3378
|
+
path: file,
|
|
3379
|
+
message: "A source map ships the original source to anyone who asks for it."
|
|
3380
|
+
});
|
|
3381
|
+
continue;
|
|
3382
|
+
}
|
|
3383
|
+
const isJs = /\.m?js$/.test(file);
|
|
3384
|
+
const isCss = file.endsWith(".css");
|
|
3385
|
+
if (!isJs && !isCss) continue;
|
|
3386
|
+
const text = ctx.read(file);
|
|
3387
|
+
if (vendored(ctx, file, text)) continue;
|
|
3388
|
+
if (SOURCE_MAP_URL.test(text)) report(file, "source map reference", "sourceMappingURL");
|
|
3389
|
+
if (isCss) reportWritten(file, "comment in shipped CSS", cssComments(text));
|
|
3390
|
+
else reportWritten(file, "comment in shipped JS", jsComments(text));
|
|
3391
|
+
}
|
|
3392
|
+
return findings;
|
|
3393
|
+
};
|
|
3394
|
+
return {
|
|
3395
|
+
visit,
|
|
3396
|
+
finish
|
|
3397
|
+
};
|
|
3398
|
+
}
|
|
3399
|
+
};
|
|
3400
|
+
//#endregion
|
|
3401
|
+
//#region src/checks/vofficeCredit.ts
|
|
3402
|
+
/** The host itself, not a substring: `v-office.com.example` is someone else's, `dyn.v-office.com`
|
|
3403
|
+
* the photo host. */
|
|
3404
|
+
const CREDIT = /^https?:\/\/(?:www\.)?v-office\.com(?:[/?#]|$)/i;
|
|
3405
|
+
/** A `<footer>` inside one of these belongs to that block (a card, a quote), not to the site. */
|
|
3406
|
+
const SECTIONING = "article, aside, main, nav, section, blockquote, figure, dialog";
|
|
3407
|
+
/** The home page, and a locale's (`de/index.html`, `en-gb/index.html`): where a root redirects to
|
|
3408
|
+
* its language, the locale home is the one a visitor lands on. */
|
|
3409
|
+
const HOME = /^(?:[a-z]{2}(?:-[a-z]{2})?\/)?index\.html$/i;
|
|
3410
|
+
/** The page's site footers (a `<footer>` in no sectioning block and no other footer), and whether
|
|
3411
|
+
* one of them links v-office.com. */
|
|
3412
|
+
const footerCredit = (document) => {
|
|
3413
|
+
const footers = [...document.querySelectorAll("footer")].filter((footer) => !footer.parentElement?.closest(`footer, ${SECTIONING}`));
|
|
3414
|
+
const credit = footers.some((footer) => [...footer.querySelectorAll("a[href]")].some((a) => CREDIT.test((a.getAttribute("href") ?? "").trim())));
|
|
3415
|
+
return {
|
|
3416
|
+
footers: footers.length,
|
|
3417
|
+
credit
|
|
3418
|
+
};
|
|
3419
|
+
};
|
|
2190
3420
|
//#endregion
|
|
2191
3421
|
//#region src/checks/index.ts
|
|
2192
3422
|
/** The site checks, in the order the report shows them: the `src` stage first, then the `dist`
|
|
@@ -2199,79 +3429,59 @@ const checks = [
|
|
|
2199
3429
|
imageFormats,
|
|
2200
3430
|
syncOnce,
|
|
2201
3431
|
v9HubFilters,
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
const findings = [];
|
|
2210
|
-
const report = (path, what, text) => findings.push({
|
|
2211
|
-
path,
|
|
2212
|
-
message: `${what}: "${excerpt(text)}"`
|
|
2213
|
-
});
|
|
2214
|
-
const wrote = siteWrote(ctx);
|
|
2215
|
-
const reportInline = (path, what, comment) => {
|
|
2216
|
-
if (wrote(comment)) report(path, what, comment);
|
|
2217
|
-
};
|
|
2218
|
-
const visit = (page) => {
|
|
2219
|
-
for (const comment of page.comments()) if (!isFrameworkComment(comment)) report(page.path, "HTML comment in the page", comment);
|
|
2220
|
-
for (const el of page.document.querySelectorAll("*")) for (const name of el.getAttributeNames()) {
|
|
2221
|
-
if (!name.startsWith("on")) continue;
|
|
2222
|
-
const code = el.getAttribute(name) ?? "";
|
|
2223
|
-
const what = `comment in an inline ${name} handler`;
|
|
2224
|
-
for (const comment of jsComments(code)) if (!DIRECTIVE.test(comment) && !LEGAL_BLOCK_COMMENT.test(comment)) reportInline(page.path, what, comment);
|
|
2225
|
-
}
|
|
2226
|
-
for (const el of page.document.querySelectorAll("script, style")) {
|
|
2227
|
-
const text = el.textContent ?? "";
|
|
2228
|
-
const what = `comment in an inline <${el.tagName.toLowerCase()}>`;
|
|
2229
|
-
for (const comment of blockComments(text)) reportInline(page.path, what, comment);
|
|
2230
|
-
if (el.tagName === "SCRIPT") {
|
|
2231
|
-
if (SOURCE_MAP_URL.test(text)) report(page.path, "source map reference in an inline <script>", text);
|
|
2232
|
-
for (const comment of lineComments(text)) reportInline(page.path, what, comment);
|
|
2233
|
-
}
|
|
2234
|
-
}
|
|
2235
|
-
};
|
|
2236
|
-
const finish = () => {
|
|
2237
|
-
for (const file of ctx.files) {
|
|
2238
|
-
if (file.endsWith(".map")) {
|
|
2239
|
-
findings.push({
|
|
2240
|
-
path: file,
|
|
2241
|
-
message: "A source map ships the original source to anyone who asks for it."
|
|
2242
|
-
});
|
|
2243
|
-
continue;
|
|
2244
|
-
}
|
|
2245
|
-
const isJs = /\.m?js$/.test(file);
|
|
2246
|
-
const isCss = file.endsWith(".css");
|
|
2247
|
-
if (!isJs && !isCss) continue;
|
|
2248
|
-
const text = ctx.read(file);
|
|
2249
|
-
if (SOURCE_MAP_URL.test(text)) report(file, "source map reference", "sourceMappingURL");
|
|
2250
|
-
if (!fs.existsSync(path.join(ctx.publicDir, file))) continue;
|
|
2251
|
-
if (isCss) for (const comment of blockComments(text)) report(file, "comment in shipped CSS", comment);
|
|
2252
|
-
if (isJs) for (const comment of lineComments(text)) report(file, "comment in shipped JS", comment);
|
|
2253
|
-
}
|
|
2254
|
-
return findings;
|
|
2255
|
-
};
|
|
2256
|
-
return {
|
|
2257
|
-
visit,
|
|
2258
|
-
finish
|
|
2259
|
-
};
|
|
2260
|
-
}
|
|
2261
|
-
},
|
|
3432
|
+
bannedCopySrc,
|
|
3433
|
+
copyEnglish,
|
|
3434
|
+
copyAddress,
|
|
3435
|
+
donorTermsSource,
|
|
3436
|
+
consentGateSource,
|
|
3437
|
+
robotsTxt,
|
|
3438
|
+
viewSource,
|
|
2262
3439
|
donorTerms,
|
|
2263
3440
|
consentGate,
|
|
2264
3441
|
feedImageFormats,
|
|
2265
3442
|
listingNoindex,
|
|
2266
3443
|
listingLinks,
|
|
2267
3444
|
sitemapNoindex,
|
|
3445
|
+
sitemapCoverage,
|
|
3446
|
+
orphanPages,
|
|
2268
3447
|
pageHeads,
|
|
2269
3448
|
canonicalLink,
|
|
2270
3449
|
openGraph,
|
|
2271
3450
|
trailingSlash,
|
|
3451
|
+
jsonLd,
|
|
3452
|
+
rentalMarkup,
|
|
3453
|
+
breadcrumbs,
|
|
2272
3454
|
v9ProductionHub,
|
|
3455
|
+
v10ProductionApi,
|
|
2273
3456
|
pageStructure,
|
|
3457
|
+
headingRatio,
|
|
3458
|
+
{
|
|
3459
|
+
id: "voffice-credit",
|
|
3460
|
+
title: "The site footer credits vOffice",
|
|
3461
|
+
severity: "error",
|
|
3462
|
+
stage: "dist",
|
|
3463
|
+
begin: (ctx) => {
|
|
3464
|
+
if (!ctx.hasDist) return null;
|
|
3465
|
+
const findings = [];
|
|
3466
|
+
return {
|
|
3467
|
+
visit: (page) => {
|
|
3468
|
+
if (page.redirect) return;
|
|
3469
|
+
const { footers, credit } = footerCredit(page.document);
|
|
3470
|
+
if (footers === 0 && HOME.test(page.path)) findings.push({
|
|
3471
|
+
path: page.path,
|
|
3472
|
+
message: "The home page has no site footer, so it carries no vOffice credit. Render the site footer (a <footer> outside main, article, section, …) with: Realisiert mit <a href=\"https://www.v-office.com\">vOffice</a>."
|
|
3473
|
+
});
|
|
3474
|
+
else if (footers > 0 && !credit) findings.push({
|
|
3475
|
+
path: page.path,
|
|
3476
|
+
message: "The site footer does not link https://www.v-office.com. Add the credit line: Realisiert mit <a href=\"https://www.v-office.com\">vOffice</a> (the starter's footer has it, worded per language)."
|
|
3477
|
+
});
|
|
3478
|
+
},
|
|
3479
|
+
finish: () => findings
|
|
3480
|
+
};
|
|
3481
|
+
}
|
|
3482
|
+
},
|
|
2274
3483
|
loadOrder,
|
|
3484
|
+
firstPaintPhotos,
|
|
2275
3485
|
bannedCopy,
|
|
2276
3486
|
duplicateSentences,
|
|
2277
3487
|
quoteSources,
|
|
@@ -2287,9 +3497,16 @@ const RETIRED_KEYS = {
|
|
|
2287
3497
|
wiring: "the wiring check was removed in 0.3.0",
|
|
2288
3498
|
optimizeDepsIgnore: "the optimize-deps check was removed in 0.3.0"
|
|
2289
3499
|
};
|
|
2290
|
-
/** The vOffice image hosts that answer JPEG unless asked for WebP: imgproxy's `plain` path
|
|
2291
|
-
* `…jpg@webp`)
|
|
2292
|
-
|
|
3500
|
+
/** The vOffice image hosts that answer JPEG unless asked for WebP: imgproxy's `plain` path on any
|
|
3501
|
+
* host (v9, `…jpg@webp`), any path on an `imgproxy.*` host and imgproxy's base64 form on any host
|
|
3502
|
+
* (`/_/rs:fit:…/aHR0….jpg`, `….webp`), and `dyn.v-office.com` (`….webp`). The v10 host
|
|
3503
|
+
* (`images.*.v-office.io`) answers WebP by itself and `webpUrl()` leaves it as it is. */
|
|
3504
|
+
const DEFAULT_FEED_IMAGE_PATTERNS = [
|
|
3505
|
+
"\\/_\\/[^\\s]*\\/plain\\/[^\\s@]+\\.(?:jpe?g|png)$",
|
|
3506
|
+
"^https:\\/\\/imgproxy\\.[a-z0-9.-]+\\/_\\/[^\\s]+\\.(?:jpe?g|png)$",
|
|
3507
|
+
"\\/_\\/[^\\s]*\\/aHR0[A-Za-z0-9_=\\/-]*\\.(?:jpe?g|png)$",
|
|
3508
|
+
"^https:\\/\\/dyn\\.v-office\\.com\\/image\\/[^\\s]+\\.(?:jpe?g|png)$"
|
|
3509
|
+
];
|
|
2293
3510
|
const STRUCTURE_RULES = [
|
|
2294
3511
|
"one-h1",
|
|
2295
3512
|
"heading-skip",
|
|
@@ -2321,6 +3538,13 @@ const stringList = (source, key, value) => {
|
|
|
2321
3538
|
};
|
|
2322
3539
|
const VALIDATORS = {
|
|
2323
3540
|
donorTerms: stringList,
|
|
3541
|
+
donorPatterns: (source, key, value) => {
|
|
3542
|
+
if (!isStringList(value) || !value.every(nonEmpty)) throw new Error(`[site-checks] ${source}: "${key}" must be an array of non-empty strings`);
|
|
3543
|
+
for (const pattern of value) {
|
|
3544
|
+
if (pattern.includes("[[:")) throw new Error(`[site-checks] ${source}: "${key}" has a POSIX class in ${JSON.stringify(pattern)}: write [[:space:]] as \\s, [[:alpha:]] as \\p{L}`);
|
|
3545
|
+
compiles(source, key, pattern, "u");
|
|
3546
|
+
}
|
|
3547
|
+
},
|
|
2324
3548
|
imageIgnore: stringList,
|
|
2325
3549
|
feedImagePatterns: (source, key, value) => {
|
|
2326
3550
|
stringList(source, key, value);
|
|
@@ -2332,11 +3556,15 @@ const VALIDATORS = {
|
|
|
2332
3556
|
},
|
|
2333
3557
|
consentAllowedHosts: stringList,
|
|
2334
3558
|
bannedCopy: (source, key, value) => {
|
|
2335
|
-
if (!isListOf(value, (e) => nonEmpty(e.pattern) && nonEmpty(e.why))) throw new Error(`[site-checks] ${source}: "${key}" must be an array of { pattern, why }`);
|
|
3559
|
+
if (!isListOf(value, (e) => nonEmpty(e.pattern) && nonEmpty(e.why) && (e.in === void 0 || e.in === "src") && (e.srcExclude === void 0 || isStringList(e.srcExclude)))) throw new Error(`[site-checks] ${source}: "${key}" must be an array of { pattern, why } ("in" is "src" when given, "srcExclude" a list of paths)`);
|
|
2336
3560
|
for (const { pattern } of value) compiles(source, key, pattern, "g");
|
|
2337
3561
|
},
|
|
2338
3562
|
copyExcludePaths: stringList,
|
|
2339
3563
|
bannedCopyExcludePaths: stringList,
|
|
3564
|
+
address: (source, key, value) => {
|
|
3565
|
+
if (value !== null && value !== "du" && value !== "Sie") throw new Error(`[site-checks] ${source}: "${key}" must be "du", "Sie" or null`);
|
|
3566
|
+
},
|
|
3567
|
+
addressAllow: stringList,
|
|
2340
3568
|
allowDuplicateSentences: stringList,
|
|
2341
3569
|
quoteSources: stringList,
|
|
2342
3570
|
factCheckAccepted: stringList,
|
|
@@ -2390,6 +3618,7 @@ function loadOptions(root, overrides = {}, note = () => {}) {
|
|
|
2390
3618
|
const pick = (key, fallback) => given[key] ?? fromFile[key] ?? fallback;
|
|
2391
3619
|
return {
|
|
2392
3620
|
donorTerms: pick("donorTerms", []),
|
|
3621
|
+
donorPatterns: pick("donorPatterns", []),
|
|
2393
3622
|
imageIgnore: pick("imageIgnore", []),
|
|
2394
3623
|
feedImagePatterns: pick("feedImagePatterns", DEFAULT_FEED_IMAGE_PATTERNS),
|
|
2395
3624
|
listingPages: pick("listingPages", []),
|
|
@@ -2398,6 +3627,8 @@ function loadOptions(root, overrides = {}, note = () => {}) {
|
|
|
2398
3627
|
bannedCopy: pick("bannedCopy", []),
|
|
2399
3628
|
copyExcludePaths: pick("copyExcludePaths", []),
|
|
2400
3629
|
bannedCopyExcludePaths: pick("bannedCopyExcludePaths", []),
|
|
3630
|
+
address: given.address !== void 0 ? given.address : fromFile.address ?? null,
|
|
3631
|
+
addressAllow: pick("addressAllow", []),
|
|
2401
3632
|
allowDuplicateSentences: pick("allowDuplicateSentences", []),
|
|
2402
3633
|
quoteSources: pick("quoteSources", []),
|
|
2403
3634
|
factCheckAccepted: pick("factCheckAccepted", []),
|
|
@@ -2721,28 +3952,61 @@ const legalPages = {
|
|
|
2721
3952
|
};
|
|
2722
3953
|
//#endregion
|
|
2723
3954
|
//#region src/distChecks/notFoundBeacon.ts
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
*
|
|
2727
|
-
|
|
2728
|
-
*
|
|
2729
|
-
*
|
|
3955
|
+
/** A call that posts to the endpoint, not the bare path: a comment or a string naming
|
|
3956
|
+
* `/api/404-log` logs nothing. `fetch("/api/404-log", …)`, `fetch(new URL("/api/404-log", …))`,
|
|
3957
|
+
* `navigator.sendBeacon("…/api/404-log", …)`. */
|
|
3958
|
+
/** The start of a call that posts what follows: `fetch(…)`, `fetch(new URL(…))`,
|
|
3959
|
+
* `fetch(new Request(…))`, `navigator.sendBeacon(…)`, optional calls (`sendBeacon?.(…)`) too. A
|
|
3960
|
+
* Request is no URL for `sendBeacon`. */
|
|
3961
|
+
const POSTS_TO = "\\b(?:fetch\\s*(?:\\?\\.)?\\s*\\(\\s*(?:new\\s+(?:URL|Request)\\s*\\(\\s*)?|sendBeacon\\s*(?:\\?\\.)?\\s*\\(\\s*(?:new\\s+URL\\s*\\(\\s*)?)";
|
|
3962
|
+
const BEACON = new RegExp(`${POSTS_TO}["'\`][^"'\`]*\\/api\\/404-log\\b`);
|
|
3963
|
+
/** A binding that holds the endpoint, as written or minified: `const endpoint = "/api/404-log"`,
|
|
3964
|
+
* `let a=1,e="/api/404-log"`. It counts only where a call posts to it. */
|
|
3965
|
+
const ENDPOINT_BINDING = /(?:\b(?:const|let|var)\s+|,\s*)([A-Za-z_$][\w$]*)\s*=\s*(?:new\s+(?:URL|Request)\s*\(\s*)?["'`][^"'`]*\/api\/404-log\b/g;
|
|
3966
|
+
const callsBinding = (code) => [...code.matchAll(ENDPOINT_BINDING)].some((m) => new RegExp(`${POSTS_TO}${m[1].replace(/\$/g, "\\$")}(?![\\w$])`).test(code));
|
|
3967
|
+
/** The modules a script imports, statically or on demand: Astro splits a page's script into chunks
|
|
3968
|
+
* under _astro/ that import each other. */
|
|
3969
|
+
const IMPORT = /(?:\bfrom\s*|\bimport\s*\(?\s*)["']([^"']+\.m?js)(?:\?[^"']*)?["']/g;
|
|
3970
|
+
/** The hosting serves 404.html for every unknown path, and AI Studio learns of the miss only when
|
|
3971
|
+
* that page posts the URL to /api/404-log (docs/internal/operations/404-logging.md). Without the
|
|
3972
|
+
* beacon the site's 404 list stays empty and no redirect is ever suggested. Astro bundles page
|
|
3973
|
+
* scripts into files under _astro/, so the page's same-site scripts count, with the chunks they
|
|
3974
|
+
* import. An error: the 404 page is the site's own code. Astro builds only: the guest and owner
|
|
3975
|
+
* apps route every path themselves and have no 404 page. */
|
|
2730
3976
|
const notFoundBeacon = {
|
|
2731
3977
|
id: "not-found-beacon",
|
|
2732
3978
|
title: "The 404 page reports missing URLs to AI Studio",
|
|
2733
|
-
severity: "
|
|
3979
|
+
severity: "error",
|
|
2734
3980
|
begin(ctx) {
|
|
2735
3981
|
if (!ctx.isAstro || !ctx.has("404.html")) return null;
|
|
2736
3982
|
let beacon = false;
|
|
3983
|
+
/** Whether the code, or a build file it imports (`dir` is where it resolves from), calls the
|
|
3984
|
+
* beacon. Each file is read once. */
|
|
3985
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3986
|
+
const calls = (code, dir) => {
|
|
3987
|
+
const stripped = stripComments(code);
|
|
3988
|
+
if (BEACON.test(stripped) || callsBinding(stripped)) return true;
|
|
3989
|
+
for (const match of stripped.matchAll(IMPORT)) {
|
|
3990
|
+
const spec = match[1];
|
|
3991
|
+
if (!spec.startsWith("/") && !spec.startsWith(".")) continue;
|
|
3992
|
+
const rel = path.posix.normalize(spec.startsWith("/") ? spec : path.posix.join(dir, spec)).replace(/^\/+/, "");
|
|
3993
|
+
if (seen.has(rel) || !ctx.has(rel)) continue;
|
|
3994
|
+
seen.add(rel);
|
|
3995
|
+
if (calls(ctx.read(rel), path.posix.dirname(`/${rel}`))) return true;
|
|
3996
|
+
}
|
|
3997
|
+
return false;
|
|
3998
|
+
};
|
|
2737
3999
|
const visit = (page) => {
|
|
2738
4000
|
if (page.path !== "404.html") return;
|
|
2739
|
-
beacon = [...page.document.querySelectorAll("script")].
|
|
4001
|
+
beacon = [...page.document.querySelectorAll("script")].some((script) => {
|
|
2740
4002
|
const src = script.getAttribute("src");
|
|
2741
|
-
if (!src) return script.textContent ?? "";
|
|
2742
|
-
if (!isSameSiteReference(src, ctx.origin)) return
|
|
4003
|
+
if (!src) return calls(script.textContent ?? "", page.base.replace(/[^/]*$/, ""));
|
|
4004
|
+
if (!isSameSiteReference(src, ctx.origin)) return false;
|
|
2743
4005
|
const file = resolveReference(page, src).replace(/^\//, "");
|
|
2744
|
-
|
|
2745
|
-
|
|
4006
|
+
if (seen.has(file) || !ctx.has(file)) return false;
|
|
4007
|
+
seen.add(file);
|
|
4008
|
+
return calls(ctx.read(file), path.posix.dirname(`/${file}`));
|
|
4009
|
+
});
|
|
2746
4010
|
};
|
|
2747
4011
|
const finish = () => beacon ? [] : [{
|
|
2748
4012
|
message: "404.html does not call /api/404-log: missing URLs are never logged",
|