@uxfront/site-checks 0.1.0 → 0.1.1
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 +19 -19
- package/bin/site-checks.js +3 -3
- package/index.d.ts +260 -259
- package/lib/check.js +222 -196
- package/lib/cli.js +59 -56
- package/lib/html.js +166 -137
- package/lib/rules.js +1194 -1046
- package/lib/site.js +534 -501
- package/lib/validate.js +140 -117
- package/lighthouse.d.ts +26 -24
- package/lighthouse.js +52 -48
- package/package.json +2 -2
package/lib/rules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, readdirSync } from "node:fs";
|
|
2
2
|
import { join, sep } from "node:path";
|
|
3
3
|
|
|
4
|
-
import { escapeRegExp, imageSize, isType } from "./html.js";
|
|
4
|
+
import { escapeRegExp, imageSize, isObject, isType } from "./html.js";
|
|
5
5
|
import { inScope, isFile } from "./site.js";
|
|
6
6
|
import { bool, count, list, oneOf, pattern, source, text, typesByPath, url } from "./validate.js";
|
|
7
7
|
|
|
@@ -28,35 +28,35 @@ import { bool, count, list, oneOf, pattern, source, text, typesByPath, url } fro
|
|
|
28
28
|
|
|
29
29
|
/** The crawlers that read pages for AI search and assistants, each allowed by name. */
|
|
30
30
|
export const AI_CRAWLERS = Object.freeze([
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
"OAI-SearchBot",
|
|
32
|
+
"ChatGPT-User",
|
|
33
|
+
"PerplexityBot",
|
|
34
|
+
"Claude-SearchBot",
|
|
35
|
+
"Claude-User",
|
|
36
|
+
"GPTBot",
|
|
37
|
+
"ClaudeBot",
|
|
38
|
+
"Google-Extended",
|
|
39
|
+
"CCBot",
|
|
40
40
|
]);
|
|
41
41
|
|
|
42
42
|
/** The directives Lighthouse's robots.txt audit knows. Any other fails it. */
|
|
43
43
|
const ROBOTS_DIRECTIVES = new Set([
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
"user-agent",
|
|
45
|
+
"disallow",
|
|
46
|
+
"allow",
|
|
47
|
+
"sitemap",
|
|
48
|
+
"crawl-delay",
|
|
49
|
+
"clean-param",
|
|
50
|
+
"host",
|
|
51
|
+
"request-rate",
|
|
52
|
+
"visit-time",
|
|
53
|
+
"noindex",
|
|
54
54
|
]);
|
|
55
55
|
|
|
56
56
|
const LASTMOD_FORMATS = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
loose: /^\d{4}-\d{2}-\d{2}(T[\d:.]+(Z|[+-]\d{2}:\d{2}))?$/,
|
|
58
|
+
date: /^\d{4}-\d{2}-\d{2}$/,
|
|
59
|
+
w3c: /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2}))?$/,
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
/** @param {string} value */
|
|
@@ -64,13 +64,13 @@ const dateOnly = (value) => /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
|
64
64
|
|
|
65
65
|
/** Whether a `YYYY-MM-DD` value is a day on the calendar, not February 30 or month 13. @param {string} value */
|
|
66
66
|
function isCalendarDay(value) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const time = Date.parse(`${value}T00:00:00Z`);
|
|
68
|
+
return !Number.isNaN(time) && new Date(time).toISOString().slice(0, 10) === value;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/** The time a `<lastmod>` stands for, or `NaN`. @param {string} value */
|
|
72
72
|
const lastmodTime = (value) =>
|
|
73
|
-
|
|
73
|
+
dateOnly(value) ? Date.parse(`${value}T00:00:00Z`) : Date.parse(value);
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Whether a line is blank: with `whitespace`, when it holds only spaces, and with `empty`, only when
|
|
@@ -88,11 +88,11 @@ const field = (node, key) => node[key];
|
|
|
88
88
|
* @returns {{ path: string, url: URL, loc: string }[]}
|
|
89
89
|
*/
|
|
90
90
|
const listed = ({ site }) =>
|
|
91
|
-
|
|
91
|
+
site.sitemap.entries.flatMap(({ loc, url }) => (url ? [{ loc, url, path: url.pathname }] : []));
|
|
92
92
|
|
|
93
93
|
/** The `<lastmod>` of a `<loc>`: the last one, when the `<loc>` is listed twice. @param {Site} site @param {string} loc */
|
|
94
94
|
const lastmodOf = (site, loc) =>
|
|
95
|
-
|
|
95
|
+
site.sitemap.entries.findLast((entry) => entry.loc === loc)?.lastmod;
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* The groups of a robots.txt, each a run of `User-agent` lines and the rules after them. A new
|
|
@@ -103,50 +103,59 @@ const lastmodOf = (site, loc) =>
|
|
|
103
103
|
* @param {"all" | "directives" | "allow-disallow"} [groupRules]
|
|
104
104
|
*/
|
|
105
105
|
function robotsGroups(text, groupRules = "all") {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
106
|
+
/** @type {{ agents: string[], rules: { field: string, value: string }[] }[]} */
|
|
107
|
+
const groups = [];
|
|
108
|
+
/** @type {{ field: string, value: string }[]} */
|
|
109
|
+
const lines = [];
|
|
110
|
+
for (const raw of text.split("\n")) {
|
|
111
|
+
const line = raw.replace(/#.*/, "").trim();
|
|
112
|
+
const at = line.indexOf(":");
|
|
113
|
+
if (at < 0) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const name = line.slice(0, at).trim().toLowerCase();
|
|
117
|
+
const value = line.slice(at + 1).trim();
|
|
118
|
+
lines.push({ field: name, value });
|
|
119
|
+
if (groupRules === "directives" && !/^[\w-]+$/.test(name)) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (name === "user-agent") {
|
|
123
|
+
const last = groups.at(-1);
|
|
124
|
+
if (!last || last.rules.length) {
|
|
125
|
+
groups.push({ agents: [value], rules: [] });
|
|
126
|
+
} else {
|
|
127
|
+
last.agents.push(value);
|
|
128
|
+
}
|
|
129
|
+
} else if (name !== "sitemap") {
|
|
130
|
+
if (groupRules === "allow-disallow" && name !== "allow" && name !== "disallow") {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
groups.at(-1)?.rules.push({ field: name, value });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { groups, lines };
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
/** @param {{ field: string, value: string }[]} rules @param {string} name @param {string} value */
|
|
131
140
|
const hasRule = (rules, name, value) =>
|
|
132
|
-
|
|
141
|
+
rules.some((entry) => entry.field === name && entry.value === value);
|
|
133
142
|
|
|
134
143
|
/** Every file in `dist`, with `/` between folders. @param {string} dist */
|
|
135
144
|
function allFiles(dist) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
return readdirSync(dist, { recursive: true, encoding: "utf8" })
|
|
146
|
+
.map((file) => file.split(sep).join("/"))
|
|
147
|
+
.filter((file) => isFile(join(dist, file)))
|
|
148
|
+
.toSorted();
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
/** A file pattern, where `**` matches any folders and `*` anything but `/`. @param {string} glob */
|
|
143
152
|
const globRegExp = (glob) =>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
153
|
+
new RegExp(
|
|
154
|
+
`^${glob
|
|
155
|
+
.split(/(\*\*\/|\*)/)
|
|
156
|
+
.map((part) => (part === "**/" ? "(?:.*/)?" : part === "*" ? "[^/]*" : escapeRegExp(part)))
|
|
157
|
+
.join("")}$`,
|
|
158
|
+
);
|
|
150
159
|
|
|
151
160
|
/**
|
|
152
161
|
* @template {RuleId} Id
|
|
@@ -156,927 +165,1062 @@ const globRegExp = (glob) =>
|
|
|
156
165
|
const rule = (definition) => definition;
|
|
157
166
|
|
|
158
167
|
export const RULES = [
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
168
|
+
rule({
|
|
169
|
+
id: "sitemap",
|
|
170
|
+
core: true,
|
|
171
|
+
defaults: {},
|
|
172
|
+
run({ site, report }) {
|
|
173
|
+
const { exists, entries } = site.sitemap;
|
|
174
|
+
if (!exists) {
|
|
175
|
+
return report("sitemap.xml", "missing");
|
|
176
|
+
}
|
|
177
|
+
if (!entries.length) {
|
|
178
|
+
report("sitemap.xml", "no <url>");
|
|
179
|
+
}
|
|
180
|
+
for (const entry of entries) {
|
|
181
|
+
if (entry.error) {
|
|
182
|
+
report("sitemap.xml", `${entry.loc} can't be decoded: ${entry.error}`);
|
|
183
|
+
} else if (!entry.hasLoc) {
|
|
184
|
+
report("sitemap.xml", "a <url> has no <loc>");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
}),
|
|
189
|
+
rule({
|
|
190
|
+
id: "sitemap-host",
|
|
191
|
+
core: true,
|
|
192
|
+
defaults: {},
|
|
193
|
+
run({ site, report }) {
|
|
194
|
+
for (const { loc, hasLoc } of site.sitemap.entries) {
|
|
195
|
+
if (hasLoc && !loc.startsWith(`${site.site}/`)) {
|
|
196
|
+
report("sitemap.xml", `${loc} isn't on ${site.site}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
rule({
|
|
202
|
+
id: "sitemap-duplicates",
|
|
203
|
+
core: false,
|
|
204
|
+
defaults: {},
|
|
205
|
+
run({ site, report }) {
|
|
206
|
+
const seen = new Set();
|
|
207
|
+
for (const { loc, hasLoc } of site.sitemap.entries) {
|
|
208
|
+
if (hasLoc && seen.has(loc)) {
|
|
209
|
+
report("sitemap.xml", `${loc} is listed twice`);
|
|
210
|
+
}
|
|
211
|
+
seen.add(loc);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
}),
|
|
215
|
+
rule({
|
|
216
|
+
id: "lastmod",
|
|
217
|
+
core: true,
|
|
218
|
+
defaults: { format: "loose", realDate: "none" },
|
|
219
|
+
run({ site, report }, { format, realDate }) {
|
|
220
|
+
for (const { loc, lastmod } of site.sitemap.entries) {
|
|
221
|
+
if (!lastmod) {
|
|
222
|
+
report("sitemap.xml", `${loc} has no <lastmod>`);
|
|
223
|
+
} else if (!LASTMOD_FORMATS[format].test(lastmod)) {
|
|
224
|
+
report("sitemap.xml", `${loc} has a <lastmod> that isn't a ${format} date: ${lastmod}`);
|
|
225
|
+
} else if (
|
|
226
|
+
(realDate === "date-only" &&
|
|
227
|
+
(dateOnly(lastmod) ? !isCalendarDay(lastmod) : Number.isNaN(Date.parse(lastmod)))) ||
|
|
228
|
+
(realDate === "parseable" && Number.isNaN(Date.parse(lastmod)))
|
|
229
|
+
) {
|
|
230
|
+
report("sitemap.xml", `${loc} has a <lastmod> that isn't a real date: ${lastmod}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
}),
|
|
235
|
+
rule({
|
|
236
|
+
id: "lastmod-future",
|
|
237
|
+
core: false,
|
|
238
|
+
defaults: { skewHours: 0 },
|
|
239
|
+
run({ site, report }, { skewHours }) {
|
|
240
|
+
const latest = site.now.getTime() + skewHours * 60 * 60 * 1000;
|
|
241
|
+
for (const { loc, lastmod } of site.sitemap.entries) {
|
|
242
|
+
if (lastmod && lastmodTime(lastmod) > latest) {
|
|
243
|
+
report("sitemap.xml", `${loc} has a <lastmod> in the future: ${lastmod}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
rule({
|
|
249
|
+
id: "sitemap-pages",
|
|
250
|
+
core: true,
|
|
251
|
+
defaults: { paths: "exact", notFoundCopy: false },
|
|
252
|
+
run({ site, report }, { notFoundCopy }) {
|
|
253
|
+
const notFound = site.read("404.html");
|
|
254
|
+
for (const { loc, url, hasLoc } of site.sitemap.entries) {
|
|
255
|
+
if (!hasLoc) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (!url) {
|
|
259
|
+
report("sitemap.xml", `${loc} isn't a URL`);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const file = site.resolve(url.pathname);
|
|
263
|
+
if (!file) {
|
|
264
|
+
report(url.pathname, `no HTML file in dist is served at ${loc}`);
|
|
265
|
+
} else if (notFoundCopy && notFound !== undefined && site.read(file) === notFound) {
|
|
266
|
+
report(url.pathname, `${file} is the 404 page`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
}),
|
|
271
|
+
rule({
|
|
272
|
+
id: "sitemap-indexable",
|
|
273
|
+
core: true,
|
|
274
|
+
defaults: { sources: [{ type: "meta", names: ["robots", "googlebot"] }] },
|
|
275
|
+
run(context, { sources }) {
|
|
276
|
+
for (const { path, url } of listed(context)) {
|
|
277
|
+
const file = context.site.resolve(path);
|
|
278
|
+
if (!file) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const why = context.site.outOfIndex(sources, { file, path, host: url.host });
|
|
282
|
+
if (why) {
|
|
283
|
+
context.report(path, `it's in the sitemap, but out of the index: ${why}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
}),
|
|
288
|
+
rule({
|
|
289
|
+
id: "sitemap-coverage",
|
|
290
|
+
core: false,
|
|
291
|
+
defaults: { exclude: /** @type {readonly IndexSource[]} */ ([]) },
|
|
292
|
+
run({ site, report }, { exclude }) {
|
|
293
|
+
const locs = site.locs;
|
|
294
|
+
for (const file of site.htmlFiles) {
|
|
295
|
+
const path = site.served(file);
|
|
296
|
+
if (site.outOfIndex(exclude, { file, path, host: site.host })) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (!locs.has(`${site.site}${path}`)) {
|
|
300
|
+
report(path, `${file} isn't in the sitemap`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
}),
|
|
305
|
+
rule({
|
|
306
|
+
id: "title",
|
|
307
|
+
core: true,
|
|
308
|
+
defaults: { max: 60, exactlyOne: false, nonEmpty: true },
|
|
309
|
+
run({ site, pages, report }, { max, exactlyOne, nonEmpty }) {
|
|
310
|
+
for (const page of pages) {
|
|
311
|
+
const { titles } = page;
|
|
312
|
+
if (exactlyOne && titles.length !== 1) {
|
|
313
|
+
report(page.path, `${titles.length} <title> elements, not exactly one`);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const title = titles[0] ?? "";
|
|
317
|
+
if (nonEmpty && !title) {
|
|
318
|
+
report(page.path, "no <title>");
|
|
319
|
+
} else if (site.length(title) > max) {
|
|
320
|
+
report(page.path, `<title> is ${site.length(title)} characters, over ${max}: "${title}"`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
}),
|
|
325
|
+
rule({
|
|
326
|
+
id: "title-unique",
|
|
327
|
+
core: true,
|
|
328
|
+
defaults: {},
|
|
329
|
+
run({ pages, report }) {
|
|
330
|
+
const seen = new Map();
|
|
331
|
+
for (const page of pages) {
|
|
332
|
+
const title = page.titles[0];
|
|
333
|
+
if (!title) {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (seen.has(title)) {
|
|
337
|
+
report(page.path, `<title> is the same as ${seen.get(title)}'s`);
|
|
338
|
+
} else {
|
|
339
|
+
seen.set(title, page.path);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
}),
|
|
344
|
+
rule({
|
|
345
|
+
id: "description",
|
|
346
|
+
core: true,
|
|
347
|
+
defaults: { min: 70, max: 160, exactlyOne: false },
|
|
348
|
+
run({ site, pages, report }, { min, max, exactlyOne }) {
|
|
349
|
+
for (const page of pages) {
|
|
350
|
+
const values = page.meta("description");
|
|
351
|
+
if (exactlyOne && values.length !== 1) {
|
|
352
|
+
report(page.path, `${values.length} meta descriptions, not exactly one`);
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const description = values[0] ?? "";
|
|
356
|
+
const length = site.length(description);
|
|
357
|
+
if (!exactlyOne && !description) {
|
|
358
|
+
report(page.path, "no meta description");
|
|
359
|
+
} else if (length < min || length > max) {
|
|
360
|
+
report(page.path, `meta description is ${length} characters, outside ${min} to ${max}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
}),
|
|
365
|
+
rule({
|
|
366
|
+
id: "description-unique",
|
|
367
|
+
core: true,
|
|
368
|
+
defaults: {},
|
|
369
|
+
run({ pages, report }) {
|
|
370
|
+
const seen = new Map();
|
|
371
|
+
for (const page of pages) {
|
|
372
|
+
const description = page.meta("description")[0];
|
|
373
|
+
if (!description) {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (seen.has(description)) {
|
|
377
|
+
report(page.path, `meta description is the same as ${seen.get(description)}'s`);
|
|
378
|
+
} else {
|
|
379
|
+
seen.set(description, page.path);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
}),
|
|
384
|
+
rule({
|
|
385
|
+
id: "h1",
|
|
386
|
+
core: true,
|
|
387
|
+
defaults: {},
|
|
388
|
+
run({ pages, report }) {
|
|
389
|
+
for (const page of pages) {
|
|
390
|
+
if (page.h1 !== 1) {
|
|
391
|
+
report(page.path, `${page.h1} <h1> elements, not exactly one`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
}),
|
|
396
|
+
rule({
|
|
397
|
+
id: "canonical",
|
|
398
|
+
core: true,
|
|
399
|
+
defaults: { exactlyOne: true, rel: "exact", requireHref: false },
|
|
400
|
+
run({ pages, report }, { exactlyOne, rel, requireHref }) {
|
|
401
|
+
for (const page of pages) {
|
|
402
|
+
const hrefs = page.canonicals(rel, requireHref);
|
|
403
|
+
if (exactlyOne && hrefs.length !== 1) {
|
|
404
|
+
report(page.path, `${hrefs.length} canonical links, not exactly one`);
|
|
405
|
+
} else if (!hrefs[0]) {
|
|
406
|
+
report(page.path, "no canonical link");
|
|
407
|
+
} else if (hrefs[0] !== page.loc) {
|
|
408
|
+
report(page.path, `canonical link ${hrefs[0]} isn't its URL, ${page.loc}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
}),
|
|
413
|
+
rule({
|
|
414
|
+
id: "lang",
|
|
415
|
+
core: true,
|
|
416
|
+
defaults: { lang: "en" },
|
|
417
|
+
run({ pages, report }, { lang }) {
|
|
418
|
+
for (const page of pages) {
|
|
419
|
+
if (lang === false ? !page.lang : page.lang !== lang) {
|
|
420
|
+
report(page.path, `<html lang="${page.lang ?? ""}">, needs ${lang || "a language"}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
}),
|
|
425
|
+
rule({
|
|
426
|
+
id: "open-graph",
|
|
427
|
+
core: true,
|
|
428
|
+
defaults: { url: "loc" },
|
|
429
|
+
run({ pages, report, optionsOf }, { url }) {
|
|
430
|
+
const { rel, requireHref } = optionsOf("canonical");
|
|
431
|
+
for (const page of pages) {
|
|
432
|
+
for (const key of ["og:title", "og:description", "og:type", "og:image", "og:url"]) {
|
|
433
|
+
if (!page.has(key)) {
|
|
434
|
+
report(page.path, `no ${key}`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
const ogUrl = page.first("og:url");
|
|
438
|
+
const expected = url === "loc" ? page.loc : page.canonicals(rel, requireHref)[0];
|
|
439
|
+
if (ogUrl?.trim() && ogUrl !== expected) {
|
|
440
|
+
report(
|
|
441
|
+
page.path,
|
|
442
|
+
`og:url ${ogUrl} isn't the ${url === "loc" ? "page's URL" : "canonical link"}`,
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
}),
|
|
448
|
+
rule({
|
|
449
|
+
id: "og-image-alt",
|
|
450
|
+
core: false,
|
|
451
|
+
defaults: {},
|
|
452
|
+
run({ pages, report }) {
|
|
453
|
+
for (const page of pages) {
|
|
454
|
+
if (!page.has("og:image:alt")) {
|
|
455
|
+
report(page.path, "no og:image:alt");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
}),
|
|
460
|
+
rule({
|
|
461
|
+
id: "meta-conflicts",
|
|
462
|
+
core: false,
|
|
463
|
+
defaults: {
|
|
464
|
+
keys: [
|
|
465
|
+
"og:title",
|
|
466
|
+
"og:description",
|
|
467
|
+
"og:url",
|
|
468
|
+
"og:type",
|
|
469
|
+
"og:image",
|
|
470
|
+
"og:image:alt",
|
|
471
|
+
"twitter:title",
|
|
472
|
+
"twitter:description",
|
|
473
|
+
"twitter:image",
|
|
474
|
+
],
|
|
475
|
+
},
|
|
476
|
+
run({ pages, report }, { keys }) {
|
|
477
|
+
for (const page of pages) {
|
|
478
|
+
for (const key of keys) {
|
|
479
|
+
const values = new Set(page.meta(key));
|
|
480
|
+
if (values.size > 1) {
|
|
481
|
+
report(page.path, `${values.size} different values of ${key}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
}),
|
|
487
|
+
rule({
|
|
488
|
+
id: "og-image-host",
|
|
489
|
+
core: true,
|
|
490
|
+
defaults: {},
|
|
491
|
+
run({ site, pages, report }) {
|
|
492
|
+
for (const page of pages) {
|
|
493
|
+
const image = page.first("og:image");
|
|
494
|
+
if (image?.trim() && !image.startsWith(`${site.site}/`)) {
|
|
495
|
+
report(page.path, `og:image ${image} isn't on ${site.site}`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
}),
|
|
500
|
+
rule({
|
|
501
|
+
id: "og-image-size-tags",
|
|
502
|
+
core: false,
|
|
503
|
+
defaults: { onHostOnly: false },
|
|
504
|
+
run({ site, pages, report }, { onHostOnly }) {
|
|
505
|
+
for (const page of pages) {
|
|
506
|
+
if (onHostOnly && !page.first("og:image")?.startsWith(`${site.site}/`)) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const width = page.first("og:image:width");
|
|
510
|
+
const height = page.first("og:image:height");
|
|
511
|
+
if (width !== "1200") {
|
|
512
|
+
report(page.path, `og:image:width is ${width ?? "(none)"}, not 1200`);
|
|
513
|
+
}
|
|
514
|
+
if (height !== "630") {
|
|
515
|
+
report(page.path, `og:image:height is ${height ?? "(none)"}, not 630`);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
}),
|
|
520
|
+
rule({
|
|
521
|
+
id: "og-image-file",
|
|
522
|
+
core: true,
|
|
523
|
+
defaults: { types: ["png", "jpeg"], png: "name" },
|
|
524
|
+
run({ site, pages, report }, { types, png }) {
|
|
525
|
+
for (const page of pages) {
|
|
526
|
+
const image = page.first("og:image");
|
|
527
|
+
if (!image?.startsWith(`${site.site}/`)) {
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
let pathname = "";
|
|
531
|
+
try {
|
|
532
|
+
pathname = new URL(image).pathname;
|
|
533
|
+
} catch {
|
|
534
|
+
// Reported as off the site, if anywhere.
|
|
535
|
+
}
|
|
536
|
+
let decoded = pathname;
|
|
537
|
+
try {
|
|
538
|
+
decoded = decodeURIComponent(pathname);
|
|
539
|
+
} catch {
|
|
540
|
+
// Keep the path as it is.
|
|
541
|
+
}
|
|
542
|
+
const file = [decoded, pathname]
|
|
543
|
+
.map((path) => join(site.dist, path))
|
|
544
|
+
.find((path) => isFile(path));
|
|
545
|
+
if (!file) {
|
|
546
|
+
report(page.path, `og:image ${image} isn't in dist`);
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
const size = imageSize(readFileSync(file), png);
|
|
550
|
+
if (!size || !types.includes(size.type)) {
|
|
551
|
+
report(page.path, `og:image ${image} isn't a ${types.join(" or ").toUpperCase()}`);
|
|
552
|
+
} else if (size.width !== 1200 || size.height !== 630) {
|
|
553
|
+
report(page.path, `og:image ${image} is ${size.width} × ${size.height}, not 1200 × 630`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
}),
|
|
558
|
+
rule({
|
|
559
|
+
id: "twitter",
|
|
560
|
+
core: true,
|
|
561
|
+
defaults: { card: "summary_large_image" },
|
|
562
|
+
run({ pages, report }, { card }) {
|
|
563
|
+
for (const page of pages) {
|
|
564
|
+
const value = page.first("twitter:card");
|
|
565
|
+
if (card === "any" ? !page.has("twitter:card") : value !== card) {
|
|
566
|
+
report(page.path, `twitter:card is ${value || "(none)"}`);
|
|
567
|
+
}
|
|
568
|
+
if (!page.has("twitter:image")) {
|
|
569
|
+
report(page.path, "no twitter:image");
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
}),
|
|
574
|
+
rule({
|
|
575
|
+
id: "twitter-text",
|
|
576
|
+
core: false,
|
|
577
|
+
defaults: {},
|
|
578
|
+
run({ pages, report }) {
|
|
579
|
+
for (const page of pages) {
|
|
580
|
+
for (const key of ["twitter:title", "twitter:description"]) {
|
|
581
|
+
if (!page.has(key)) {
|
|
582
|
+
report(page.path, `no ${key}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
}),
|
|
588
|
+
rule({
|
|
589
|
+
id: "json-ld-parse",
|
|
590
|
+
core: true,
|
|
591
|
+
defaults: {},
|
|
592
|
+
run({ pages, report }) {
|
|
593
|
+
for (const page of pages) {
|
|
594
|
+
for (const [index, block] of page.blocks.entries()) {
|
|
595
|
+
if (!block.ok) {
|
|
596
|
+
report(page.path, `JSON-LD block ${index + 1} doesn't parse: ${block.error}`);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
}),
|
|
602
|
+
rule({
|
|
603
|
+
id: "json-ld-present",
|
|
604
|
+
core: false,
|
|
605
|
+
defaults: {},
|
|
606
|
+
run({ pages, report }) {
|
|
607
|
+
for (const page of pages) {
|
|
608
|
+
if (!page.blocks.length) {
|
|
609
|
+
report(page.path, "no JSON-LD");
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
}),
|
|
614
|
+
rule({
|
|
615
|
+
id: "json-ld-context",
|
|
616
|
+
core: false,
|
|
617
|
+
defaults: {},
|
|
618
|
+
run({ pages, report }) {
|
|
619
|
+
for (const page of pages) {
|
|
620
|
+
for (const block of page.blocks) {
|
|
621
|
+
if (!block.ok) {
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
const context = isObject(block.value) ? block.value["@context"] : undefined;
|
|
625
|
+
if (context !== "https://schema.org") {
|
|
626
|
+
report(page.path, "a JSON-LD block's @context isn't https://schema.org");
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
},
|
|
631
|
+
}),
|
|
632
|
+
rule({
|
|
633
|
+
id: "json-ld-ids",
|
|
634
|
+
core: false,
|
|
635
|
+
defaults: {},
|
|
636
|
+
run({ pages, report }) {
|
|
637
|
+
for (const page of pages) {
|
|
638
|
+
const ids = new Set();
|
|
639
|
+
for (const node of page.nodes) {
|
|
640
|
+
const id = node["@id"];
|
|
641
|
+
if (typeof id !== "string") {
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
if (ids.has(id)) {
|
|
645
|
+
report(page.path, `two JSON-LD nodes with the @id ${id}`);
|
|
646
|
+
}
|
|
647
|
+
ids.add(id);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
}),
|
|
652
|
+
rule({
|
|
653
|
+
id: "json-ld-types",
|
|
654
|
+
core: false,
|
|
655
|
+
defaults: {
|
|
656
|
+
types: {
|
|
657
|
+
"/": ["WebSite", "SoftwareSourceCode", "Organization"],
|
|
658
|
+
"/docs/*": ["TechArticle", "BreadcrumbList"],
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
run({ site, pages, report }, { types }) {
|
|
662
|
+
for (const page of pages) {
|
|
663
|
+
for (const [pattern, required] of Object.entries(types)) {
|
|
664
|
+
if (!inScope(page.path, [pattern])) {
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
for (const type of required) {
|
|
668
|
+
if (!page.nodes.some((node) => isType(node, type, site.profile.typeArrays))) {
|
|
669
|
+
report(page.path, `no ${type} in the JSON-LD`);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
}),
|
|
676
|
+
rule({
|
|
677
|
+
id: "json-ld-breadcrumbs",
|
|
678
|
+
core: false,
|
|
679
|
+
defaults: {
|
|
680
|
+
scope: ["/docs/*"],
|
|
681
|
+
nodes: "first",
|
|
682
|
+
item: ["url"],
|
|
683
|
+
exactType: false,
|
|
684
|
+
nonArray: "skip",
|
|
685
|
+
},
|
|
686
|
+
run({ site, pages, report }, { scope, nodes, item: forms, exactType, nonArray }) {
|
|
687
|
+
const locs = site.locs;
|
|
688
|
+
for (const page of pages) {
|
|
689
|
+
if (!inScope(page.path, scope)) {
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
const lists = page.nodes.filter((node) =>
|
|
693
|
+
isType(node, "BreadcrumbList", !exactType && site.profile.typeArrays),
|
|
694
|
+
);
|
|
695
|
+
for (const breadcrumbs of nodes === "first" ? lists.slice(0, 1) : lists) {
|
|
696
|
+
const items = field(breadcrumbs, "itemListElement");
|
|
697
|
+
// With `iterate`, a value that isn't a list is read as one, and one that can't be read
|
|
698
|
+
// as one fails the rule, as a checker that loops over it does.
|
|
699
|
+
const entries =
|
|
700
|
+
nonArray === "iterate"
|
|
701
|
+
? // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the spread is the check
|
|
702
|
+
[.../** @type {Iterable<unknown>} */ (items ?? [])]
|
|
703
|
+
: Array.isArray(items)
|
|
704
|
+
? items
|
|
705
|
+
: [];
|
|
706
|
+
for (const entry of entries) {
|
|
707
|
+
const item = entry && typeof entry === "object" ? entry.item : undefined;
|
|
708
|
+
const target =
|
|
709
|
+
typeof item === "string"
|
|
710
|
+
? forms.includes("url")
|
|
711
|
+
? item
|
|
712
|
+
: undefined
|
|
713
|
+
: forms.includes("id") && isObject(item)
|
|
714
|
+
? item["@id"]
|
|
715
|
+
: undefined;
|
|
716
|
+
if (typeof target !== "string" || !locs.has(target)) {
|
|
717
|
+
report(
|
|
718
|
+
page.path,
|
|
719
|
+
`a breadcrumb links ${typeof target === "string" ? target : (JSON.stringify(target) ?? "nothing")}, which isn't in the sitemap`,
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
}),
|
|
727
|
+
rule({
|
|
728
|
+
id: "json-ld-article",
|
|
729
|
+
core: false,
|
|
730
|
+
defaults: { scope: ["/docs/*"] },
|
|
731
|
+
run({ site, pages, report }, { scope }) {
|
|
732
|
+
for (const page of pages) {
|
|
733
|
+
if (!inScope(page.path, scope)) {
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
const article = page.nodes.find((node) =>
|
|
737
|
+
isType(node, "TechArticle", site.profile.typeArrays),
|
|
738
|
+
);
|
|
739
|
+
if (!article) {
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
const lastmod = lastmodOf(site, page.loc);
|
|
743
|
+
if (lastmod && article.dateModified !== lastmod) {
|
|
744
|
+
report(
|
|
745
|
+
page.path,
|
|
746
|
+
`the TechArticle's dateModified ${String(article.dateModified)} isn't the sitemap's ${lastmod}`,
|
|
747
|
+
);
|
|
748
|
+
}
|
|
749
|
+
const image = page.first("og:image");
|
|
750
|
+
if (image && article.image !== image) {
|
|
751
|
+
report(page.path, `the TechArticle's image isn't the og:image, ${image}`);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
}),
|
|
756
|
+
rule({
|
|
757
|
+
id: "json-ld-posting",
|
|
758
|
+
core: false,
|
|
759
|
+
defaults: { scope: ["/blog/*"] },
|
|
760
|
+
run({ site, pages, report }, { scope }) {
|
|
761
|
+
const { typeArrays } = site.profile;
|
|
762
|
+
for (const page of pages) {
|
|
763
|
+
if (!inScope(page.path, scope)) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
const postings = page.nodes.filter((node) => isType(node, "BlogPosting", typeArrays));
|
|
767
|
+
if (postings.length !== 1) {
|
|
768
|
+
report(page.path, `${postings.length} BlogPosting nodes, not one`);
|
|
769
|
+
}
|
|
770
|
+
for (const posting of postings) {
|
|
771
|
+
const missing = ["headline", "description", "datePublished", "image", "url"].filter(
|
|
772
|
+
(key) => !posting[key],
|
|
773
|
+
);
|
|
774
|
+
const author = posting.author;
|
|
775
|
+
if (!isObject(author) || !field(author, "name")) {
|
|
776
|
+
missing.push("author.name");
|
|
777
|
+
}
|
|
778
|
+
if (missing.length) {
|
|
779
|
+
report(page.path, `a BlogPosting without ${missing.join(", ")}`);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (page.nodes.some((node) => isType(node, "Article", typeArrays))) {
|
|
783
|
+
report(page.path, "an Article node beside the BlogPosting");
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
}),
|
|
788
|
+
rule({
|
|
789
|
+
id: "json-ld-organization",
|
|
790
|
+
core: false,
|
|
791
|
+
defaults: { name: "", scope: ["*"] },
|
|
792
|
+
run({ site, pages, report }, { name, scope }) {
|
|
793
|
+
for (const page of pages) {
|
|
794
|
+
if (!inScope(page.path, scope)) {
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
const named = page.nodes.some(
|
|
798
|
+
(node) => isType(node, "Organization", site.profile.typeArrays) && node.name === name,
|
|
799
|
+
);
|
|
800
|
+
if (named) {
|
|
801
|
+
report(page.path, `an Organization named ${name}, which isn't an organisation`);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
}),
|
|
806
|
+
rule({
|
|
807
|
+
id: "robots-sitemap",
|
|
808
|
+
core: true,
|
|
809
|
+
defaults: { match: "exact" },
|
|
810
|
+
run({ site, report }, { match }) {
|
|
811
|
+
const text = site.read("robots.txt");
|
|
812
|
+
if (text === undefined) {
|
|
813
|
+
return report("robots.txt", "missing");
|
|
814
|
+
}
|
|
815
|
+
const url = `${site.site}/sitemap.xml`;
|
|
816
|
+
const line = `Sitemap: ${url}`;
|
|
817
|
+
const found =
|
|
818
|
+
match === "loose"
|
|
819
|
+
? new RegExp(`^Sitemap:\\s*${escapeRegExp(url)}\\s*$`, "im").test(text)
|
|
820
|
+
: match === "trimmed"
|
|
821
|
+
? text
|
|
822
|
+
.split("\n")
|
|
823
|
+
.map((raw) => raw.replace(/#.*/, "").trim())
|
|
824
|
+
.includes(line)
|
|
825
|
+
: match === "exact"
|
|
826
|
+
? text.split("\n").includes(line)
|
|
827
|
+
: match === "anchored"
|
|
828
|
+
? new RegExp(`^${escapeRegExp(line)}$`, "m").test(text)
|
|
829
|
+
: robotsGroups(text).lines.some(
|
|
830
|
+
(entry) => entry.field === "sitemap" && entry.value === url,
|
|
831
|
+
);
|
|
832
|
+
if (!found) {
|
|
833
|
+
report("robots.txt", `no "${line}" line`);
|
|
834
|
+
}
|
|
835
|
+
},
|
|
836
|
+
}),
|
|
837
|
+
rule({
|
|
838
|
+
id: "robots-crawlers",
|
|
839
|
+
core: false,
|
|
840
|
+
defaults: {
|
|
841
|
+
crawlers: AI_CRAWLERS,
|
|
842
|
+
allow: false,
|
|
843
|
+
case: "exact",
|
|
844
|
+
agents: "groups",
|
|
845
|
+
groupRules: "all",
|
|
846
|
+
},
|
|
847
|
+
run({ site, report }, { crawlers, allow, case: letterCase, agents, groupRules }) {
|
|
848
|
+
const text = site.read("robots.txt");
|
|
849
|
+
if (text === undefined) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
// With `lines`, every `User-agent` line counts, read as it is, comments and all.
|
|
853
|
+
const groups =
|
|
854
|
+
agents === "lines"
|
|
855
|
+
? [...text.matchAll(/^user-agent:\s*(.+?)\s*$/gim)].map(([, agent = ""]) => ({
|
|
856
|
+
agents: [agent],
|
|
857
|
+
rules: /** @type {{ field: string, value: string }[]} */ ([]),
|
|
858
|
+
}))
|
|
859
|
+
: robotsGroups(text, groupRules).groups;
|
|
860
|
+
/** @param {string} agent */
|
|
861
|
+
const key = (agent) => (letterCase === "insensitive" ? agent.toLowerCase() : agent);
|
|
862
|
+
for (const crawler of crawlers) {
|
|
863
|
+
const own = groups.filter((group) =>
|
|
864
|
+
group.agents.some((agent) => key(agent) === key(crawler)),
|
|
865
|
+
);
|
|
866
|
+
if (!own.length) {
|
|
867
|
+
report("robots.txt", `no group for User-agent: ${crawler}`);
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
const checked = allow === "first" ? own.slice(0, 1) : own;
|
|
871
|
+
if (
|
|
872
|
+
allow &&
|
|
873
|
+
(!checked.some((group) => hasRule(group.rules, "allow", "/")) ||
|
|
874
|
+
checked.some((group) => hasRule(group.rules, "disallow", "/")))
|
|
875
|
+
) {
|
|
876
|
+
report("robots.txt", `User-agent: ${crawler} isn't allowed everywhere`);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
},
|
|
880
|
+
}),
|
|
881
|
+
rule({
|
|
882
|
+
id: "robots-no-disallow",
|
|
883
|
+
core: false,
|
|
884
|
+
defaults: { match: "lines" },
|
|
885
|
+
run({ site, report }, { match }) {
|
|
886
|
+
const text = site.read("robots.txt");
|
|
887
|
+
if (text === undefined) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const found =
|
|
891
|
+
match === "lines"
|
|
892
|
+
? /^disallow:\s*\/\s*$/im.test(text)
|
|
893
|
+
: robotsGroups(text).groups.some((group) => hasRule(group.rules, "disallow", "/"));
|
|
894
|
+
if (found) {
|
|
895
|
+
report("robots.txt", '"Disallow: /" blocks crawlers from the site');
|
|
896
|
+
}
|
|
897
|
+
},
|
|
898
|
+
}),
|
|
899
|
+
rule({
|
|
900
|
+
id: "robots-wildcard",
|
|
901
|
+
core: false,
|
|
902
|
+
defaults: {},
|
|
903
|
+
run({ site, report }) {
|
|
904
|
+
const text = site.read("robots.txt");
|
|
905
|
+
if (text === undefined) {
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
const wildcards = [...text.matchAll(/^user-agent:\s*(.+?)\s*$/gim)].filter(
|
|
909
|
+
([, agent]) => agent === "*",
|
|
910
|
+
).length;
|
|
911
|
+
if (wildcards !== 1) {
|
|
912
|
+
report("robots.txt", `${wildcards} "User-agent: *" lines, not one`);
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
}),
|
|
916
|
+
rule({
|
|
917
|
+
id: "robots-directives",
|
|
918
|
+
core: false,
|
|
919
|
+
defaults: {},
|
|
920
|
+
run({ site, report }) {
|
|
921
|
+
const text = site.read("robots.txt");
|
|
922
|
+
if (text === undefined) {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
for (const raw of text.split("\n")) {
|
|
926
|
+
const line = raw.replace(/#.*/, "").trim();
|
|
927
|
+
const name = line.match(/^([\w-]+):\s*(.*)$/)?.[1];
|
|
928
|
+
if (name && !ROBOTS_DIRECTIVES.has(name.toLowerCase())) {
|
|
929
|
+
report("robots.txt", `"${line}": Lighthouse doesn't know ${name}`);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
}),
|
|
934
|
+
rule({
|
|
935
|
+
id: "llms",
|
|
936
|
+
core: true,
|
|
937
|
+
defaults: { first: "non-empty", title: "", nonEmpty: false },
|
|
938
|
+
run({ site, report }, { first, title, nonEmpty }) {
|
|
939
|
+
const text = site.read("llms.txt");
|
|
940
|
+
if (text === undefined) {
|
|
941
|
+
return report("llms.txt", "missing");
|
|
942
|
+
}
|
|
943
|
+
const line =
|
|
944
|
+
first === "line"
|
|
945
|
+
? text.split("\n")[0]
|
|
946
|
+
: text.split("\n").find((entry) => !isBlank(entry, site.profile.blankLines));
|
|
947
|
+
const ok = title
|
|
948
|
+
? first === "line"
|
|
949
|
+
? text.startsWith(`# ${title}\n`)
|
|
950
|
+
: line === `# ${title}`
|
|
951
|
+
: nonEmpty
|
|
952
|
+
? /^# \S/.test(line ?? "")
|
|
953
|
+
: Boolean(line?.startsWith("# "));
|
|
954
|
+
if (!ok) {
|
|
955
|
+
report("llms.txt", `doesn't start with "# ${title || "<title>"}"`);
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
}),
|
|
959
|
+
rule({
|
|
960
|
+
id: "llms-summary",
|
|
961
|
+
core: true,
|
|
962
|
+
defaults: { position: "second", nonEmpty: false },
|
|
963
|
+
run({ site, report }, { position, nonEmpty }) {
|
|
964
|
+
const text = site.read("llms.txt");
|
|
965
|
+
if (text === undefined) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
const lines = text.split("\n").filter((line) => !isBlank(line, site.profile.blankLines));
|
|
969
|
+
/** @param {string | undefined} line */
|
|
970
|
+
const summary = (line) =>
|
|
971
|
+
nonEmpty ? /^> \S/.test(line ?? "") : Boolean(line?.startsWith("> "));
|
|
972
|
+
const found = position === "second" ? summary(lines[1]) : lines.some(summary);
|
|
973
|
+
if (!found) {
|
|
974
|
+
report(
|
|
975
|
+
"llms.txt",
|
|
976
|
+
`no "> " summary line${position === "second" ? " under the heading" : ""}`,
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
}),
|
|
981
|
+
rule({
|
|
982
|
+
id: "llms-links",
|
|
983
|
+
core: false,
|
|
984
|
+
defaults: { scope: ["/docs/*"], links: [], form: "parens", minPages: 0 },
|
|
985
|
+
run(context, { scope, links, form, minPages }) {
|
|
986
|
+
const { site, report } = context;
|
|
987
|
+
const text = site.read("llms.txt");
|
|
988
|
+
if (text === undefined) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
/** @param {string} url */
|
|
992
|
+
const linked = (url) => text.includes(form === "markdown" ? `](${url})` : `(${url})`);
|
|
993
|
+
const paths = listed(context)
|
|
994
|
+
.filter(({ loc, path }) => loc.startsWith(`${site.site}/`) && inScope(path, scope))
|
|
995
|
+
.map(({ path }) => path);
|
|
996
|
+
if (paths.length < minPages) {
|
|
997
|
+
report("llms.txt", `${paths.length} pages in ${scope.join(", ")}, needs ${minPages}`);
|
|
998
|
+
}
|
|
999
|
+
for (const url of [...paths.map((path) => `${site.site}/raw${path}.md`), ...links]) {
|
|
1000
|
+
if (!linked(url)) {
|
|
1001
|
+
report("llms.txt", `no link to ${url}`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
}),
|
|
1006
|
+
rule({
|
|
1007
|
+
id: "llms-docs-section",
|
|
1008
|
+
core: false,
|
|
1009
|
+
defaults: {},
|
|
1010
|
+
run({ site, report }) {
|
|
1011
|
+
const text = site.read("llms.txt");
|
|
1012
|
+
if (text === undefined) {
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
const section = text.split(/^## Docs$/m)[1]?.split(/^## /m)[0] ?? "";
|
|
1016
|
+
const titles = [...section.matchAll(/^- \[([^\]]+)\]\(([^)]+)\)/gm)].map(
|
|
1017
|
+
([, title]) => title,
|
|
1018
|
+
);
|
|
1019
|
+
if (!titles.length) {
|
|
1020
|
+
report("llms.txt", "no ## Docs section with links");
|
|
1021
|
+
}
|
|
1022
|
+
for (const [title, same] of Map.groupBy(titles, (entry) => entry)) {
|
|
1023
|
+
if (same.length > 1) {
|
|
1024
|
+
report("llms.txt", `${same.length} links in ## Docs share the title "${title}"`);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
},
|
|
1028
|
+
}),
|
|
1029
|
+
rule({
|
|
1030
|
+
id: "llms-full",
|
|
1031
|
+
core: false,
|
|
1032
|
+
defaults: {},
|
|
1033
|
+
run({ site, report }) {
|
|
1034
|
+
if (site.read("llms-full.txt") === undefined) {
|
|
1035
|
+
report("llms-full.txt", "missing");
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
}),
|
|
1039
|
+
rule({
|
|
1040
|
+
id: "markdown-clean",
|
|
1041
|
+
core: false,
|
|
1042
|
+
defaults: { files: ["llms-full.txt"], tables: "line-start" },
|
|
1043
|
+
run({ site, report }, { files, tables }) {
|
|
1044
|
+
const globs = files.map(globRegExp);
|
|
1045
|
+
const names = files.every((file) => !file.includes("*"))
|
|
1046
|
+
? [...files]
|
|
1047
|
+
: allFiles(site.dist).filter((file) => globs.some((glob) => glob.test(file)));
|
|
1048
|
+
const table = tables === "line-start" ? /^\s*<(?:table|thead|tbody|tr)\b/im : /<table[\s>]/i;
|
|
1049
|
+
for (const name of names) {
|
|
1050
|
+
const text = site.read(name);
|
|
1051
|
+
if (text === undefined) {
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (table.test(text)) {
|
|
1055
|
+
report(name, "has an HTML table");
|
|
1056
|
+
}
|
|
1057
|
+
if (text.includes(""")) {
|
|
1058
|
+
report(name, "has ", left over from an MDC attribute");
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
}),
|
|
1063
|
+
rule({
|
|
1064
|
+
id: "markdown-copy",
|
|
1065
|
+
core: false,
|
|
1066
|
+
defaults: { scope: ["/docs/*", "/blog/*"] },
|
|
1067
|
+
run({ site, pages, report }, { scope }) {
|
|
1068
|
+
for (const page of pages) {
|
|
1069
|
+
if (inScope(page.path, scope) && site.read(`raw${page.path}.md`) === undefined) {
|
|
1070
|
+
report(page.path, `no raw${page.path}.md`);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
},
|
|
1074
|
+
}),
|
|
1075
|
+
rule({
|
|
1076
|
+
id: "markdown-heading",
|
|
1077
|
+
core: false,
|
|
1078
|
+
defaults: { scope: ["/docs/*"], ogTitle: ["/blog/*"] },
|
|
1079
|
+
run({ site, pages, report }, { scope, ogTitle }) {
|
|
1080
|
+
/** @type {Map<string, string[]>} */
|
|
1081
|
+
const headings = new Map();
|
|
1082
|
+
for (const page of pages) {
|
|
1083
|
+
const copy = `raw${page.path}.md`;
|
|
1084
|
+
const first = site.read(copy)?.split("\n")[0];
|
|
1085
|
+
if (first === undefined) {
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1088
|
+
if (inScope(page.path, scope)) {
|
|
1089
|
+
if (!first.startsWith("# ")) {
|
|
1090
|
+
report(copy, "doesn't start with a # heading");
|
|
1091
|
+
}
|
|
1092
|
+
headings.set(first, [...(headings.get(first) ?? []), copy]);
|
|
1093
|
+
}
|
|
1094
|
+
if (inScope(page.path, ogTitle) && first !== `# ${page.first("og:title")}`) {
|
|
1095
|
+
report(copy, `starts with "${first}", not "# ${page.first("og:title")}"`);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
for (const [first, copies] of headings) {
|
|
1099
|
+
if (copies.length > 1) {
|
|
1100
|
+
report(copies.join(", "), `all start with "${first}"`);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
}),
|
|
1105
|
+
rule({
|
|
1106
|
+
id: "markdown-alternate",
|
|
1107
|
+
core: false,
|
|
1108
|
+
defaults: { scope: ["/docs/*"] },
|
|
1109
|
+
run({ site, pages, report }, { scope }) {
|
|
1110
|
+
for (const page of pages) {
|
|
1111
|
+
if (!inScope(page.path, scope)) {
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
const copy = `${site.site}/raw${page.path}.md`;
|
|
1115
|
+
const linked = page
|
|
1116
|
+
.tags("link")
|
|
1117
|
+
.some(
|
|
1118
|
+
(link) =>
|
|
1119
|
+
link.rel?.toLowerCase() === "alternate" &&
|
|
1120
|
+
link.type === "text/markdown" &&
|
|
1121
|
+
link.href === copy,
|
|
1122
|
+
);
|
|
1123
|
+
if (!linked) {
|
|
1124
|
+
report(page.path, `no <link rel="alternate" type="text/markdown" href="${copy}">`);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
},
|
|
1128
|
+
}),
|
|
1129
|
+
rule({
|
|
1130
|
+
id: "redirects-permanent",
|
|
1131
|
+
core: false,
|
|
1132
|
+
defaults: { needsDestination: true },
|
|
1133
|
+
run({ site, report }, { needsDestination }) {
|
|
1134
|
+
for (const line of (site.read("_redirects") ?? "").split("\n")) {
|
|
1135
|
+
const [from, destination, status = "302"] = line.trim().split(/\s+/);
|
|
1136
|
+
if (!from || from.startsWith("#") || (needsDestination && !destination)) {
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
// Cloudflare redirects with a 302 when a rule names no status.
|
|
1140
|
+
if (status === "302" || status === "307") {
|
|
1141
|
+
report("_redirects", `${from} redirects with a temporary ${status}`);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
}),
|
|
1146
|
+
rule({
|
|
1147
|
+
id: "headers-noindex",
|
|
1148
|
+
core: false,
|
|
1149
|
+
defaults: { patterns: [], urls: [] },
|
|
1150
|
+
run({ site, report }, { patterns, urls }) {
|
|
1151
|
+
for (const pattern of patterns) {
|
|
1152
|
+
const found = site.headers.some(
|
|
1153
|
+
(entry) =>
|
|
1154
|
+
entry.pattern === pattern &&
|
|
1155
|
+
entry.headers.some(
|
|
1156
|
+
([name, value]) => name === "x-robots-tag" && /\bnoindex\b/i.test(value),
|
|
1157
|
+
),
|
|
1158
|
+
);
|
|
1159
|
+
if (!found) {
|
|
1160
|
+
report("_headers", `no ${pattern} rule with X-Robots-Tag: noindex`);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
for (const url of urls) {
|
|
1164
|
+
const tags = site
|
|
1165
|
+
.headersFor(url)
|
|
1166
|
+
.filter(([name]) => name === "x-robots-tag")
|
|
1167
|
+
.map(([, value]) => value)
|
|
1168
|
+
.join(", ");
|
|
1169
|
+
if (!/noindex/i.test(tags)) {
|
|
1170
|
+
report("_headers", `${url} gets no X-Robots-Tag: noindex`);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
},
|
|
1174
|
+
}),
|
|
1175
|
+
rule({
|
|
1176
|
+
id: "headers-duplicates",
|
|
1177
|
+
core: false,
|
|
1178
|
+
defaults: {},
|
|
1179
|
+
run({ site, report }) {
|
|
1180
|
+
for (const [pattern, same] of Map.groupBy(site.headers, (entry) => entry.pattern)) {
|
|
1181
|
+
if (same.length > 1) {
|
|
1182
|
+
report(
|
|
1183
|
+
"_headers",
|
|
1184
|
+
`${same.length} rules for ${pattern}, of which Cloudflare applies only the last`,
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
},
|
|
1189
|
+
}),
|
|
1190
|
+
rule({
|
|
1191
|
+
id: "headers-markdown",
|
|
1192
|
+
core: false,
|
|
1193
|
+
defaults: { scope: ["/docs/*", "/blog/*"] },
|
|
1194
|
+
run({ site, pages, report }, { scope }) {
|
|
1195
|
+
for (const page of pages) {
|
|
1196
|
+
if (!inScope(page.path, scope)) {
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
const url = `${site.site}/raw${page.path}.md`;
|
|
1200
|
+
const headers = site.headersFor(url);
|
|
1201
|
+
const link = headers.find(([name]) => name === "link")?.[1];
|
|
1202
|
+
if (link !== `<${site.site}${page.path}>; rel="canonical"`) {
|
|
1203
|
+
report(url, `Link ${link ?? "(none)"}, not its page as canonical`);
|
|
1204
|
+
}
|
|
1205
|
+
const robots = headers
|
|
1206
|
+
.filter(([name]) => name === "x-robots-tag")
|
|
1207
|
+
.map(([, value]) => value);
|
|
1208
|
+
if (robots.some((value) => /noindex/i.test(value))) {
|
|
1209
|
+
report(url, `X-Robots-Tag ${robots.join(", ")}`);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
},
|
|
1213
|
+
}),
|
|
1214
|
+
rule({
|
|
1215
|
+
id: "not-found",
|
|
1216
|
+
core: false,
|
|
1217
|
+
defaults: {},
|
|
1218
|
+
run({ site, report }) {
|
|
1219
|
+
if (site.read("404.html") === undefined) {
|
|
1220
|
+
report("404.html", "missing");
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
}),
|
|
1080
1224
|
];
|
|
1081
1225
|
|
|
1082
1226
|
const scope = list(pattern);
|
|
@@ -1086,68 +1230,72 @@ const scope = list(pattern);
|
|
|
1086
1230
|
* @type {Partial<Record<RuleId, Record<string, import("./validate.js").Validator>>>}
|
|
1087
1231
|
*/
|
|
1088
1232
|
export const SCHEMAS = {
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1233
|
+
lastmod: {
|
|
1234
|
+
format: oneOf("loose", "date", "w3c"),
|
|
1235
|
+
realDate: oneOf("none", "date-only", "parseable"),
|
|
1236
|
+
},
|
|
1237
|
+
"lastmod-future": { skewHours: count },
|
|
1238
|
+
"sitemap-pages": { paths: oneOf("lookup", "exact", "exact-slash"), notFoundCopy: bool },
|
|
1239
|
+
"sitemap-indexable": { sources: list(source) },
|
|
1240
|
+
"sitemap-coverage": { exclude: list(source) },
|
|
1241
|
+
title: { max: count, exactlyOne: bool, nonEmpty: bool },
|
|
1242
|
+
description: { min: count, max: count, exactlyOne: bool },
|
|
1243
|
+
canonical: {
|
|
1244
|
+
exactlyOne: bool,
|
|
1245
|
+
rel: oneOf("exact", "token", "exact-any-case"),
|
|
1246
|
+
requireHref: bool,
|
|
1247
|
+
},
|
|
1248
|
+
lang: {
|
|
1249
|
+
lang: (value, path) => {
|
|
1250
|
+
if (value !== false) {
|
|
1251
|
+
text(value, path);
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
},
|
|
1255
|
+
"open-graph": { url: oneOf("loc", "canonical") },
|
|
1256
|
+
"meta-conflicts": { keys: list(text) },
|
|
1257
|
+
"og-image-size-tags": { onHostOnly: bool },
|
|
1258
|
+
"og-image-file": {
|
|
1259
|
+
types: list(oneOf("png", "jpeg"), { nonEmpty: true }),
|
|
1260
|
+
png: oneOf("name", "signature"),
|
|
1261
|
+
},
|
|
1262
|
+
twitter: { card: oneOf("summary_large_image", "any") },
|
|
1263
|
+
"json-ld-types": { types: typesByPath },
|
|
1264
|
+
"json-ld-breadcrumbs": {
|
|
1265
|
+
scope,
|
|
1266
|
+
nodes: oneOf("first", "all"),
|
|
1267
|
+
item: list(oneOf("url", "id"), { nonEmpty: true }),
|
|
1268
|
+
exactType: bool,
|
|
1269
|
+
nonArray: oneOf("skip", "iterate"),
|
|
1270
|
+
},
|
|
1271
|
+
"json-ld-article": { scope },
|
|
1272
|
+
"json-ld-posting": { scope },
|
|
1273
|
+
"json-ld-organization": { name: text, scope },
|
|
1274
|
+
"robots-sitemap": { match: oneOf("loose", "trimmed", "anchored", "exact", "field") },
|
|
1275
|
+
"robots-crawlers": {
|
|
1276
|
+
crawlers: list(text),
|
|
1277
|
+
allow: oneOf(false, "first", "all"),
|
|
1278
|
+
case: oneOf("exact", "insensitive"),
|
|
1279
|
+
agents: oneOf("groups", "lines"),
|
|
1280
|
+
groupRules: oneOf("all", "directives", "allow-disallow"),
|
|
1281
|
+
},
|
|
1282
|
+
"robots-no-disallow": { match: oneOf("lines", "groups") },
|
|
1283
|
+
llms: {
|
|
1284
|
+
first: oneOf("line", "non-empty"),
|
|
1285
|
+
title: (value, path) => {
|
|
1286
|
+
if (typeof value !== "string") {
|
|
1287
|
+
text(value, path);
|
|
1288
|
+
}
|
|
1289
|
+
},
|
|
1290
|
+
nonEmpty: bool,
|
|
1291
|
+
},
|
|
1292
|
+
"llms-summary": { position: oneOf("second", "any"), nonEmpty: bool },
|
|
1293
|
+
"llms-links": { scope, links: list(url), form: oneOf("markdown", "parens"), minPages: count },
|
|
1294
|
+
"markdown-clean": { files: list(text), tables: oneOf("line-start", "anywhere") },
|
|
1295
|
+
"markdown-copy": { scope },
|
|
1296
|
+
"markdown-heading": { scope, ogTitle: scope },
|
|
1297
|
+
"markdown-alternate": { scope },
|
|
1298
|
+
"redirects-permanent": { needsDestination: bool },
|
|
1299
|
+
"headers-noindex": { patterns: list(text), urls: list(url) },
|
|
1300
|
+
"headers-markdown": { scope },
|
|
1153
1301
|
};
|