Beacon · SEO & discoverability
canonical-beacon
Check canonical tags and hreflang clusters in your built static site.
npm i -D @mrlouiswright/canonical-beaconPublished to GitHub Packages: add @mrlouiswright:registry=https://npm.pkg.github.com to .npmrc first (installing needs a token with read:packages).
What it checks
- Canonical tagsmissing, more than one, empty or invalid, relative, outside
<head>, tracking parameters or#fragment,og:urlandLinkheader disagreements. - Canonical targetsthe target page must exist in the build, must not be a 404 page or meta-refresh stub, must not be
noindex, and must not canonicalise somewhere else again (chains)… - Mixed signalsa
noindexpage that also canonicalises to another URL. - hreflang codesISO 639-1 language with optional script and ISO 3166-1 / UN M.49 region (
en-GB,zh-Hant-TW,es-419) orx-default; catchesen-UK,en_GBand region-only codes. - hreflang clustersself-reference, return links (reciprocity), duplicate codes, relative hrefs, alternates that are missing,
noindexor non-canonical, hreflang on non-canonical pages,x-defaultpresence…
Quick usage
CLI
npx canonical-beacon dist
npx canonical-beacon dist --base-url https://example.com --fail-on medium
npx canonical-beacon out --clean-urls --exclude "/drafts/**"
npx canonical-beacon public --allow-cross-domain --format sarif > canonical.sarif
API
import { check, validHreflang } from "canonical-beacon";
const report = check("dist", { baseUrl: "https://example.com" });
console.log(report.counts, report.findings[0]);
validHreflang("en-UK"); // { ok: false, reason: ... }
Every option is documented in the canonical-beacon docs.
CI / GitHub Action
permissions:
contents: read
security-events: write # only needed for the SARIF upload
jobs:
canonical-beacon:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with: { persist-credentials: false }
- run: npm ci && npm run build # produce the static site first
- uses: MrLouisWright/canonical-beacon@v1
with:
path: dist
fail-on: high
sarif: canonical-beacon.sarif
- uses: github/codeql-action/upload-sarif@v3
if: always()
with: { sarif_file: canonical-beacon.sarif }