All notes

An SEO audit that fails CI, run on the built HTML

SEOCIAstroNode.js

The first time I ran an SEO audit over the built HTML of Buying Costs and Coparent Math, it found 30 problems on one and 72 on the other. It’s a Node script that reads every page in dist/, so it runs before the deploy, not after. Both sites now deploy only when it passes, and a second step tests the checker itself on pages built to break each rule.

Both are static Astro sites. They already had a check that fails on broken links, missing titles or a page without an H1. It said nothing about a title too long for Google to show, a description of 60 characters, or a guide no other page links to. Online audit tools catch some of that, but they crawl the live site, after the deploy, and they don’t know rules that only make sense for these sites, such as “each state’s calculator links to that state’s guides”.

What the first run found

Each problem is reported under its rule’s id:

check-seo: 30 problem(s) in 94 pages (92 indexed): title-length 14, description-length 11, llms-missing 3, inbound 2.
check-seo: 72 problem(s) in 98 indexed pages: title-length 9, state-title 2, description-length 16, og:image 3, schema 1, headings 35, anchor 3, inbound 1, llms.txt 2.

The first line is Buying Costs, the second Coparent Math. What the ids check:

  • title-length: the title as rendered is 65 characters or fewer;
  • description-length: 120 to 165 characters;
  • headings: no heading level skipped;
  • inbound: at least two indexed pages link to the page from their content;
  • llms.txt (llms-missing on Buying Costs): every indexed page is listed in llms.txt;
  • og:image: the share image exists in the build, at 1200 by 630.

Coparent Math has 30 rules in all, Buying Costs 28. The rest check canonicals, structured data against what the page shows, the sitemap, link text and so on. Five came from reading OpenSEO, an MIT-licensed SEO tool: duplicate pages, thin pages, images without alt text, pages too many clicks from home, and pages that link nowhere. So did the idea of testing the rules on planted pages.

The titles were my own fault. Buying Costs’ content schema let a guide’s title run to 80 characters and Coparent Math’s to 70, and both allowed 170 for a description, so the build accepted what the audit refused. The schemas now use the audit’s limits.

Coparent Math’s 35 heading skips came from one component. The worked example in its guides rendered its steps as h4 under an h2. One line made them h3, and 35 problems went. Three more were share images that didn’t exist.

I didn’t put it in CI until both counts were zero. With 72 problems, a failing step would have stopped every deploy.

Test the checker

A rule that never fires looks exactly like a rule that passes. So the script has a --self-test mode, run on a folder of small fixture pages. Each fixture plants one defect, and expected.json says which rule it must trigger:

<!-- Planted: an h3 follows the h1 (rule headings). -->
<h1>Fixture: headings</h1>
<h3>A skipped level</h3>

Every other rule has to pass on that page, so any other finding is a bug in the checker. Fixtures write <!--words--> where real text would go, and the test fills in 150 words so they don’t trip the thin-page rule. A few fixtures plant nothing and must stay clean, and a rule without a fixture fails the self-test too.

On Coparent Math that’s 32 fixtures with a defect and 7 clean pages:

check-seo self-test: OK. Each of the 30 rules caught exactly its planted defects on 32 fixtures, and the other 7 pages came out clean.

Both steps run in CI after the build:

- run: npm run check-seo --prefix site
- run: npm run check-seo:self-test --prefix site

The deploy job waits for that job, so a failure in either step stops the deploy.