@uxfront/site-checks 0.0.0-stage → 0.1.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 +255 -2
- package/bin/site-checks.js +8 -0
- package/index.d.ts +361 -0
- package/index.js +10 -0
- package/lib/check.js +234 -0
- package/lib/cli.js +77 -0
- package/lib/html.js +259 -0
- package/lib/rules.js +1153 -0
- package/lib/site.js +568 -0
- package/lib/validate.js +188 -0
- package/lighthouse.d.ts +43 -0
- package/lighthouse.js +84 -0
- package/package.json +53 -3
package/README.md
CHANGED
|
@@ -1,3 +1,256 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @uxfront/site-checks
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The search and AI search checks, and the Lighthouse CI preset, that the uxfront.com family of sites shares. Point it at a built site, and it reads every page in the sitemap the way a crawler does: the title and description search results show, the canonical link, the social cards, the structured data, and the files crawlers read first, `sitemap.xml`, `robots.txt` and `llms.txt`. Think of a page that drops out of the sitemap after a refactor, a share image that's 1200 × 600, or a docs page that `llms.txt` forgot to link: each one fails a rule by name.
|
|
4
|
+
|
|
5
|
+
It has no dependencies and reads files only, so it runs in a few seconds after the build, in CI or on your machine. Each site picks the rules it keeps and how strict each one is, so five sites can share one checker without any of them checking more or less than it means to.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add -D @uxfront/site-checks
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
It needs Node 24 or later.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Write a config next to your site's `package.json`. Its default export holds the options, all but the build folder:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
// site-checks.config.mjs
|
|
21
|
+
import { defineConfig } from "@uxfront/site-checks";
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
site: "https://inkline.io",
|
|
25
|
+
rules: {
|
|
26
|
+
"sitemap-pages": { paths: "lookup" },
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then run the check on the build:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"scripts": {
|
|
36
|
+
"check:seo": "site-checks seo .output/public"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
It prints one line per rule, then a summary:
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
✓ sitemap
|
|
45
|
+
✓ sitemap-host
|
|
46
|
+
✗ title
|
|
47
|
+
/docs/components/button: <title> is 68 characters, over 60: "Button: the component people press to act on what's in front of them"
|
|
48
|
+
✓ title-unique
|
|
49
|
+
…
|
|
50
|
+
|
|
51
|
+
128 pages checked, 1 problem
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Without `rules`, the 20 **core** rules run with their defaults (the [rule table](#rules) marks them). Name a rule to turn it on, to change its options, or to turn it off with `false`.
|
|
55
|
+
|
|
56
|
+
## The CLI
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
site-checks seo [dist] [--config <file>]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
| Argument | Default | What it is |
|
|
63
|
+
| ----------------- | ------------------------ | ---------------------------------------------------------- |
|
|
64
|
+
| `dist` | `dist` | The build folder. |
|
|
65
|
+
| `--config <file>` | `site-checks.config.mjs` | The config module, whose default export holds the options. |
|
|
66
|
+
|
|
67
|
+
It exits 0 when every rule passes, 1 on any problem, and 2 when it can't run: there's no `index.html` in `dist`, no config, or the config can't be used. A config can't be used when it names a rule or an option that doesn't exist, or gives an option a value it doesn't take, like `paths: "lookups"`. So a typo fails the run instead of turning a check off. A problem in the build never stops the run: when a rule can't read a file, like a `<title>` with a character reference past the last code point, that rule reports it, and the others still run.
|
|
68
|
+
|
|
69
|
+
## Options
|
|
70
|
+
|
|
71
|
+
| Option | What it is |
|
|
72
|
+
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| `site` | The production origin, like `https://uxfront.com`. Every `<loc>`, canonical link and share image must be on it. |
|
|
74
|
+
| `dist` | The build folder. The CLI takes it as its argument. |
|
|
75
|
+
| `pages` | Site paths to check, like `["/", "/docs/"]`. By default, every `<loc>` in `sitemap.xml`. The sitemap rules still read the sitemap, and `sitemap-pages` reports a path here with no file. |
|
|
76
|
+
| `parse` | How a page is read: the [parsing profile](#the-parsing-profile). |
|
|
77
|
+
| `rules` | Each rule ID to `true`, `false` or its options. |
|
|
78
|
+
| `extraRules` | Rules of your own, run on the same parsed pages and reported like the others: see [Extra rules](#extra-rules). |
|
|
79
|
+
| `now` | The time `lastmod-future` compares with. Defaults to now. |
|
|
80
|
+
|
|
81
|
+
The page rules read each page the sitemap lists and the build serves. A `<loc>` with no file fails `sitemap-pages`, and the other page rules leave it out.
|
|
82
|
+
|
|
83
|
+
## The parsing profile
|
|
84
|
+
|
|
85
|
+
Sites write their HTML a little differently, and their checkers read it a little differently too, so `parse` says how to read a site. Every rule reads through it. Most sites need only `scope`, `h1` and maybe `count`: the other settings let a site keep exactly the reading its own checker had.
|
|
86
|
+
|
|
87
|
+
| Setting | Default | Values |
|
|
88
|
+
| -------------------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
89
|
+
| `scope` | `document` | Where `<meta>` and `<link>` tags are read: `document`, `head` (everything before `</head>`, or the whole page without one), `head-element` (the `<head>` element, or nothing without one) or `markup` (the document without its `<script>` elements and comments). |
|
|
90
|
+
| `titleScope` | `head` | Where `<title>` is read, with the same values. |
|
|
91
|
+
| `titleTag` | `any` | The `<title>` elements read: `any` (with attributes and any text), `plain-text` (with attributes, and text without a `<`) or `bare` (no attributes, and text without a `<`). |
|
|
92
|
+
| `trimTitle` | `after-decode` | When a title loses the spaces at its ends: `after-decode`, `before-decode` or `none`. |
|
|
93
|
+
| `quotes` | `any` | The attribute values read: `any` (double, single or no quotes) or `double` only. |
|
|
94
|
+
| `caseSensitiveTags` | `false` | With `true`, tag names match in lower case only, so `<META>` isn't a `<meta>`. |
|
|
95
|
+
| `tagEnd` | `word` | What ends a tag's name: `word` (a word boundary, so a `<meta-card>` reads as a `<meta>`) or `space` (a space, `/` or `>`). |
|
|
96
|
+
| `metaKey` | `name-or-property` | How a `<meta>` is found by key: `name-or-property` (either attribute), or `property-first` (its `property`, or else its `name`, leaving out a tag with no `content`). |
|
|
97
|
+
| `trimValues` | `false` | With `true`, `<meta>` `content` and `<html lang>` lose the spaces at their ends before they're read. |
|
|
98
|
+
| `decode` | `["numeric", "quot", "apos", "lt", "gt", "amp"]` | The entities decoded in attribute values, titles and sitemap URLs: `numeric` for every `&#…;` and `&#x…;`, or a name like `amp` or `#x2F`. |
|
|
99
|
+
| `decodeOrder` | `one-pass` | `one-pass` decodes each reference once, so `&lt;` stays `<`. `numeric-first` decodes numeric references before named ones, so `&lt;` becomes `<`. |
|
|
100
|
+
| `decodeIgnoreCase` | `false` | With `true`, named entities decode in any case, like `&`. |
|
|
101
|
+
| `count` | `utf-16` | The units of a length: `utf-16` code units, like `String.length`, or `code-points`, so an emoji counts once. |
|
|
102
|
+
| `h1` | `anywhere` | Where `<h1>` is counted: `anywhere`, `markup` (outside `<script>` and comments) or `rendered` (outside `<script>`, `<style>`, `<template>` and comments). Nuxt quotes markup in its payload script, so a Nuxt site wants `markup` or `rendered`. |
|
|
103
|
+
| `nodes` | `graph-or-block` | The JSON-LD nodes of a block: `graph-or-block` (the `@graph` members, or else the block), `block-and-graph` (the block and its `@graph` members), `all` (the block and its `@graph` members, recursively, arrays flattened) or `graph-deep` (the `@graph` members, recursively, or else the block, arrays flattened). |
|
|
104
|
+
| `typeArrays` | `true` | Whether an array `@type`, like `["SoftwareSourceCode", "SoftwareApplication"]`, matches each of its members. |
|
|
105
|
+
| `jsonLdType` | `exact` | The `<script>` elements read as JSON-LD: `exact` (`type="application/ld+json"`) or `prefix-any-case` (a `type` that starts with it, in any case). |
|
|
106
|
+
| `blankLines` | `whitespace` | The lines of `llms.txt` that count as blank: `whitespace` (only spaces) or `empty` (nothing at all, so a CRLF file's blank lines count as text). |
|
|
107
|
+
| `trimSitemap` | `true` | With `false`, `<loc>` and `<lastmod>` keep the spaces at their ends, so `<loc> https://… </loc>` isn't on the site. |
|
|
108
|
+
| `mergeDuplicateLocs` | `false` | With `true`, a `<loc>` listed twice is checked once. |
|
|
109
|
+
| `headersParser` | `lines` | How `_headers` is read: `lines` (line by line, skipping `#` lines and the spaces at each line's ends) or `blocks` (each unindented line and the indented lines after it as one rule, so a `#` line is a rule of its own, and a header line that ends in a CRLF's `\r` doesn't read). |
|
|
110
|
+
|
|
111
|
+
Each default is the value most of the five sites that wrote these checks use, with uxfront's own value where they tie.
|
|
112
|
+
|
|
113
|
+
## Rules
|
|
114
|
+
|
|
115
|
+
Rules come in four groups: the sitemap, the tags on each page, the structured data, and the files crawlers read. Each row gives the rule's options and their defaults. A rule without options takes `true` or `false`.
|
|
116
|
+
|
|
117
|
+
| ID | Core | What it checks | Options and defaults |
|
|
118
|
+
| ---------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
119
|
+
| `sitemap` | Yes | `sitemap.xml` exists, with at least one `<url>`, each with a `<loc>`. | |
|
|
120
|
+
| `sitemap-host` | Yes | Every `<loc>` is on `site`. | |
|
|
121
|
+
| `sitemap-duplicates` | | No `<loc>` is listed twice. | |
|
|
122
|
+
| `lastmod` | Yes | Every `<url>` has a `<lastmod>` in the format, and it's a real date. | `format`: `loose` (a date, or `T` and digits with a zone), `date` (`YYYY-MM-DD`) or `w3c` (a date, or a time to the minute or finer with a zone). `realDate`: `none`, `date-only` (a `YYYY-MM-DD` value is a real calendar day, and a time parses) or `parseable` (`Date.parse` reads it). |
|
|
123
|
+
| `lastmod-future` | | No `<lastmod>` is later than now. | `skewHours`: `0`. Commit dates are the committer's local time, up to 14 hours ahead of UTC, so a site that writes them wants `14`. |
|
|
124
|
+
| `sitemap-pages` | Yes | Every `<loc>` has an HTML file in `dist`. | `paths`: `exact` (the `<loc>` path is the file's served path: `docs/a.html` and `docs/a/index.html` at `/docs/a`), `exact-slash` (as `exact`, but a folder's `index.html` at `/docs/a/`) or `lookup` (`/a` is `a.html` or `a/index.html`, and `/a/` is `a/index.html`). `notFoundCopy`: `false`. With `true`, a page's file mustn't be the same text as `404.html`. |
|
|
125
|
+
| `sitemap-indexable` | Yes | No page in the sitemap is out of the index. | `sources`: what takes a page out of the index, as [sources](#sources). Defaults to a `robots` or `googlebot` `<meta>` with `noindex`. |
|
|
126
|
+
| `sitemap-coverage` | | Every HTML file in `dist` that `exclude` doesn't name is in the sitemap. | `exclude`: the [sources](#sources) of files left out on purpose. Defaults to `sitemap-indexable`'s `sources`. |
|
|
127
|
+
| `title` | Yes | A `<title>`, of at most `max` characters. | `max`: `60`. `exactlyOne`: `false`, so the first is read. With `true`, a page has exactly one. `nonEmpty`: `true`. |
|
|
128
|
+
| `title-unique` | Yes | No two pages share a title. | |
|
|
129
|
+
| `description` | Yes | A meta description of `min` to `max` characters. | `min`: `70`. `max`: `160`. `exactlyOne`: `false`. |
|
|
130
|
+
| `description-unique` | Yes | No two pages share a description. | |
|
|
131
|
+
| `h1` | Yes | Exactly one `<h1>`, counted where the profile's `h1` says. | |
|
|
132
|
+
| `canonical` | Yes | The canonical link is the page's URL. | `exactlyOne`: `true`. With `false`, the first is read. `rel`: `exact` (`rel="canonical"`), `exact-any-case` (the same, in any case) or `token` (`canonical` is one of the `rel` words, in any case). `requireHref`: `false`. With `true`, a link with no `href` doesn't count. |
|
|
133
|
+
| `lang` | Yes | `<html>` has a `lang`. | `lang`: `"en"`, the value it must have. With `false`, any value. |
|
|
134
|
+
| `open-graph` | Yes | `og:title`, `og:description`, `og:type`, `og:image` and `og:url` are set, and `og:url` is the page's URL. | `url`: `loc`, the sitemap's URL, or `canonical`, the canonical link. |
|
|
135
|
+
| `og-image-alt` | | `og:image:alt` is set. | |
|
|
136
|
+
| `meta-conflicts` | | No `<meta>` in `keys` has two different values. | `keys`: `og:title`, `og:description`, `og:url`, `og:type`, `og:image`, `og:image:alt`, `twitter:title`, `twitter:description` and `twitter:image`. |
|
|
137
|
+
| `og-image-host` | Yes | `og:image` is on `site`. | |
|
|
138
|
+
| `og-image-size-tags` | | `og:image:width` is `1200` and `og:image:height` is `630`. | `onHostOnly`: `false`. With `true`, only when the image is on `site`. |
|
|
139
|
+
| `og-image-file` | Yes | The `og:image` is in `dist`, 1200 × 630, of a type in `types`. | `types`: `["png", "jpeg"]`. `png`: `name`, so a PNG is a file whose bytes 1 to 3 spell `PNG`, or `signature`, all eight bytes of the PNG signature. |
|
|
140
|
+
| `twitter` | Yes | `twitter:image` is set, and `twitter:card` is `card`. | `card`: `summary_large_image`, or `any` value. |
|
|
141
|
+
| `twitter-text` | | `twitter:title` and `twitter:description` are set. | |
|
|
142
|
+
| `json-ld-parse` | Yes | Every `application/ld+json` block parses. | |
|
|
143
|
+
| `json-ld-present` | | Every page has at least one block. | |
|
|
144
|
+
| `json-ld-context` | | Every block's `@context` is `https://schema.org`. | |
|
|
145
|
+
| `json-ld-ids` | | No two nodes on a page share an `@id`. | |
|
|
146
|
+
| `json-ld-types` | | The pages in each [path pattern](#path-patterns) have each of its `@type`s. | `types`: `{ "/": ["WebSite", "SoftwareSourceCode", "Organization"], "/docs/*": ["TechArticle", "BreadcrumbList"] }`. |
|
|
147
|
+
| `json-ld-breadcrumbs` | | Every breadcrumb links a page in the sitemap. | `scope`: `["/docs/*"]`, the pages checked. `nodes`: `first` `BreadcrumbList`, or `all`. `item`: `["url"]`, the forms an item may take: `url`, a string, and `id`, an object's `@id`. Any other form fails. `exactType`: `false`. With `true`, a list must have exactly the `@type` `BreadcrumbList`, whatever `typeArrays` says. `nonArray`: `skip` an `itemListElement` that isn't a list, or `iterate` it, failing when it can't be read as one. |
|
|
148
|
+
| `json-ld-article` | | The first `TechArticle` has `dateModified` equal to the page's `<lastmod>`, when it has one, and `image` equal to its `og:image`, when it has one. | `scope`: `["/docs/*"]`. |
|
|
149
|
+
| `json-ld-posting` | | Exactly one `BlogPosting`, with `headline`, `description`, `datePublished`, `image`, `url` and `author.name`, and no `Article`. | `scope`: `["/blog/*"]`. |
|
|
150
|
+
| `json-ld-organization` | | No `Organization` is named `name`: a site about software describes it as software. | `name`, which it needs, like `"Unframework"`. `scope`: `["*"]`. |
|
|
151
|
+
| `robots-sitemap` | Yes | `robots.txt` has a `Sitemap: <site>/sitemap.xml` line. | `match`: `exact` (a line exactly as it is), `anchored` (the same, but a CRLF line end passes), `trimmed` (after comments and the spaces at its ends go), `field` (the field name in any case, the value trimmed) or `loose` (any case and spacing). |
|
|
152
|
+
| `robots-crawlers` | | A group for each crawler. | `crawlers`: `AI_CRAWLERS`, the nine AI crawlers. `allow`: `false`. With `first`, the first group that names a crawler allows `/` and doesn't disallow it. With `all`, one of them allows `/` and none disallows it. `case`: `exact` or `insensitive`. `agents`: `groups`, or `lines`, every `User-agent` line as it is, comments and all. `groupRules`: the lines that end a run of agents, `all` lines with a field, `directives` (fields that are a word) or `allow-disallow`. |
|
|
153
|
+
| `robots-no-disallow` | | No `Disallow: /`. | `match`: `lines` (any line) or `groups` (a rule inside a group). |
|
|
154
|
+
| `robots-wildcard` | | Exactly one `User-agent: *` line. | |
|
|
155
|
+
| `robots-directives` | | Only the directives Lighthouse's `robots.txt` audit knows, since any other fails it, and with it every page's SEO score. | |
|
|
156
|
+
| `llms` | Yes | `llms.txt` exists, and starts with a `# ` heading. | `first`: `non-empty`, the first line with text, or `line`, the very first line. `title`: none. With one, the heading is exactly `# <title>`. `nonEmpty`: `false`. With `true`, the heading's text starts right after `# `. |
|
|
157
|
+
| `llms-summary` | Yes | A `> ` summary line. | `position`: `second`, the line under the heading, or `any`. `nonEmpty`: `false`. With `true`, the summary's text starts right after `> `. |
|
|
158
|
+
| `llms-links` | | `llms.txt` links `<site>/raw<path>.md` for each sitemap page in `scope`, and every URL in `links`. | `scope`: `["/docs/*"]`. `links`: `[]`. `form`: `parens`, `(url)`, or `markdown`, `](url)`. `minPages`: `0`, the fewest pages `scope` must hold. |
|
|
159
|
+
| `llms-docs-section` | | A `## Docs` section of links, no two with one title. | |
|
|
160
|
+
| `llms-full` | | `llms-full.txt` exists. | |
|
|
161
|
+
| `markdown-clean` | | No `"`, left over from an MDC attribute, and no HTML table in `files`. | `files`: `["llms-full.txt"]`, where `**` matches any folders and `*` a name, like `raw/**/*.md`. `tables`: `line-start` (a line that starts with `<table`, `<thead`, `<tbody` or `<tr`) or `anywhere` (`<table` followed by a space or `>`). |
|
|
162
|
+
| `markdown-copy` | | Each page in `scope` has its Markdown copy, `dist/raw<path>.md`. | `scope`: `["/docs/*", "/blog/*"]`. |
|
|
163
|
+
| `markdown-heading` | | Each copy in `scope` starts with a `# ` heading no other copy has, and each copy in `ogTitle` starts with `# <og:title>`. | `scope`: `["/docs/*"]`. `ogTitle`: `["/blog/*"]`. |
|
|
164
|
+
| `markdown-alternate` | | Each page in `scope` links its copy with `<link rel="alternate" type="text/markdown">`. | `scope`: `["/docs/*"]`. |
|
|
165
|
+
| `redirects-permanent` | | No `_redirects` rule answers 302 or 307. Cloudflare answers 302 when a rule names no status. | `needsDestination`: `true`, so a rule with no destination is left out. With `false`, it fails as a 302. |
|
|
166
|
+
| `headers-noindex` | | `_headers` keeps other hosts and generated files out of the index. | `patterns`: `[]`, each a rule that must send `X-Robots-Tag: noindex`, like `https://www.uxfront.com/*`. `urls`: `[]`, each a URL that must get `noindex`, matched as Cloudflare matches. |
|
|
167
|
+
| `headers-duplicates` | | No two `_headers` rules share a pattern, since Cloudflare applies only the last. | |
|
|
168
|
+
| `headers-markdown` | | Each Markdown copy of a page in `scope` gets `Link: <page>; rel="canonical"` and no `noindex`. | `scope`: `["/docs/*", "/blog/*"]`. |
|
|
169
|
+
| `not-found` | | `dist/404.html` exists. | |
|
|
170
|
+
|
|
171
|
+
### Sources
|
|
172
|
+
|
|
173
|
+
`sitemap-indexable` and `sitemap-coverage` take a list of sources, and a page is out of the index when any one of them says so:
|
|
174
|
+
|
|
175
|
+
| Source | A page is out when |
|
|
176
|
+
| ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
177
|
+
| `{ type: "meta", names, values, word, caseSensitive, property, anyCaseNames, scope }` | a `<meta>` named one of `names` has a `content` that holds one of `values` (`["noindex"]` by default). With `word`, only as a whole word, and with `caseSensitive`, only in that case. With `property`, a tag is found as the profile finds any `<meta>`, by `name` or `property`, and with `anyCaseNames`, its `name` matches in any case. `scope` reads another part of the page than the profile's, like `document`. |
|
|
178
|
+
| `{ type: "refresh" }` | it has a `<meta http-equiv="refresh">`, like the stubs Nuxt writes for redirects. |
|
|
179
|
+
| `{ type: "files", files }` | its file is one of `files`, like `404.html` and `200.html`. |
|
|
180
|
+
| `{ type: "under", paths }` | its file is under one of `paths`, like `raw/`. |
|
|
181
|
+
| `{ type: "redirects" }` | a `_redirects` rule starts at its path. |
|
|
182
|
+
| `{ type: "headers", hosts, values, word }` | a `_headers` rule sends it an `X-Robots-Tag` that holds one of `values`. `hosts` says how rules with a host match: `ignore` them, since `https://www.example.com/*` would match every path, `match` the host as Cloudflare does, or `drop` the host and match the path alone, reading only a rule's last `X-Robots-Tag`. |
|
|
183
|
+
|
|
184
|
+
### Path patterns
|
|
185
|
+
|
|
186
|
+
Options that name pages take patterns: `*` for every page, a path ending in `*` for every page under it, like `/docs/*`, or an exact path, like `/` for the homepage.
|
|
187
|
+
|
|
188
|
+
## Extra rules
|
|
189
|
+
|
|
190
|
+
A check only one site needs can live in its config, and runs on the same parsed pages:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// site-checks.config.mjs
|
|
194
|
+
export default {
|
|
195
|
+
site: "https://opencomponents.dev",
|
|
196
|
+
extraRules: [
|
|
197
|
+
{
|
|
198
|
+
id: "schema-cors",
|
|
199
|
+
check({ site, headersFor, report }) {
|
|
200
|
+
const url = `${site}/schemas/contract.json`;
|
|
201
|
+
const cors = headersFor(url).find(([name]) => name === "access-control-allow-origin");
|
|
202
|
+
if (cors?.[1] !== "*") report(url, "no Access-Control-Allow-Origin: *");
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`check` gets the context below, and its problems print under its `id`.
|
|
210
|
+
|
|
211
|
+
| Property | What it is |
|
|
212
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
213
|
+
| `site` | The origin. |
|
|
214
|
+
| `dist` | The build folder. |
|
|
215
|
+
| `pages` | The checked pages, each with its `loc`, `path`, `file` and `html`, `meta(key)` for the `content` of each `<meta>` named `key`, its `titles` and its JSON-LD `nodes`. |
|
|
216
|
+
| `sitemap` | Each `<url>`'s `loc` and `lastmod`. |
|
|
217
|
+
| `read` | `read(file)` gives a file in `dist` as text, or `undefined`. |
|
|
218
|
+
| `headersFor` | `headersFor(url)` gives the headers `_headers` sends a URL, as `[name, value]` pairs with lower-case names, matched as Cloudflare matches. |
|
|
219
|
+
| `report` | `report(target, message)` reports a problem with a page's path or a file's name. |
|
|
220
|
+
|
|
221
|
+
## The Lighthouse preset
|
|
222
|
+
|
|
223
|
+
`@uxfront/site-checks/lighthouse` gives a whole Lighthouse CI config from the site's `collect` settings, with the thresholds every site shares: three runs, results in `.lighthouseci`, and an error below 0.95 in performance, accessibility and best practices and below 1 in SEO.
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
// lighthouserc.mjs
|
|
227
|
+
import { lighthouseConfig } from "@uxfront/site-checks/lighthouse";
|
|
228
|
+
|
|
229
|
+
export default lighthouseConfig({
|
|
230
|
+
collect: { staticDistDir: "dist", url: ["http://localhost/"] },
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Lighthouse CI loads `lighthouserc.mjs` from version 0.16, so pin the CLI in the script, like `pnpm dlx @lhci/cli@0.16.1 autorun`. `@lhci/cli` isn't a dependency of this package: it stays in the script, so Lighthouse stays out of your lockfile.
|
|
235
|
+
|
|
236
|
+
| Option | What it is |
|
|
237
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
238
|
+
| `collect` | Lighthouse CI's `collect` settings, like `staticDistDir`, `url` or `startServerCommand`. `numberOfRuns` defaults to 3. |
|
|
239
|
+
| `categories` | Changes to a category's assertion: its `level` (`error`, `warn` or `off`) and `minScore`, like `{ seo: { minScore: 0.95 } }` or `{ performance: { level: "warn" } }`. |
|
|
240
|
+
| `matrix` | Asserts categories only on the URLs that match a pattern, as Lighthouse CI's `assertMatrix`, like `[{ matchingUrlPattern: "^http://localhost:8799/$", categories: ["performance"] }]`. |
|
|
241
|
+
|
|
242
|
+
Lighthouse CI's own `extends` can't stand in for the preset, since it merges arrays by index and refuses an `assertMatrix` beside other assertions.
|
|
243
|
+
|
|
244
|
+
## From JavaScript
|
|
245
|
+
|
|
246
|
+
| Export | What it is |
|
|
247
|
+
| --------------- | -------------------------------------------------------------------------------------------- |
|
|
248
|
+
| `checkSeo` | `checkSeo(options)` reads a build and returns a report: each rule that ran and its problems. |
|
|
249
|
+
| `formatReport` | The lines the CLI prints for a report. |
|
|
250
|
+
| `defineConfig` | Returns its argument, typed, for a config file. |
|
|
251
|
+
| `RULE_IDS` | The 51 rule IDs, in the order they run. |
|
|
252
|
+
| `CORE_RULES` | The 20 rules that run when a config doesn't name them. |
|
|
253
|
+
| `DEFAULT_PARSE` | The parsing profile a config gets without `parse`. |
|
|
254
|
+
| `AI_CRAWLERS` | The nine crawlers `robots-crawlers` checks by default, like `GPTBot` and `ClaudeBot`. |
|
|
255
|
+
|
|
256
|
+
`checkSeo` throws on a config it can't use, like an unknown rule ID or an option value it doesn't take, so a typo never turns a check off quietly. A problem in the build is a problem of the rule that finds it, so `checkSeo` returns a report for any build.
|