seo-graph icon indicating copy to clipboard operation
seo-graph copied to clipboard

feat(astro-seo-graph): incremental IndexNow via published content-hash manifest

Open schlessera opened this issue 5 months ago • 0 comments

Problem

The indexNow integration submits every eligible URL on every build (integration.ts, astro:build:done). That's off-spec and can backfire:

What this adds

Opt-in indexNow.incremental (true or an options object). On each build:

  1. Hash every eligible page into a { url: hash } manifest.
  2. GET <siteUrl>/indexnow-manifest.json — the manifest the previous deploy published.
  3. Diff → submit only added ∪ updated ∪ deleted.
  4. Write the new manifest into the build output, so it ships with this deploy and becomes the next baseline.

Default behavior is unchanged: without incremental, it still submits the full set. Pure helpers (buildUrlManifest, diffManifests, changedUrls, hashContent, serializeManifest, parseManifest) are exported and unit-tested (12 tests); the build:done glue mirrors the existing full-submit path.

Design decisions & alternatives considered

Where the previous state lives → on the live site (not local disk, not a KV store). The diff needs last-deploy state. Options weighed:

  • Local manifest file — breaks the moment you build from a different machine or CI.
  • CI cache / committed manifest — ties it to one CI provider, or adds noisy bot commits.
  • Cloudflare KV/R2 — infra + cost for a build-time concern; rejected (a key goal here was no extra hosting cost — and IndexNow submission is already a build-time POST, so nothing needs request-time compute).
  • Published manifest fetched at build (chosen) — portable across local and CI, zero infra, one GET at build time. The manifest is a static asset; the only "store" is your own site. Tradeoff: first build submits everything (baseline), and the manifest is public — but it only lists URLs your sitemap already exposes, plus opaque hashes.

Change signal → content hash, not sitemap <lastmod>. I checked whether a standard file already fits before inventing one:

  • No standard "content-hash per URL" file exists (RFC 8615 .well-known has no such registration; web-app manifest.json is unrelated PWA metadata; IndexNow itself only standardizes the key file, never a published URL list).
  • The standard change signal is sitemap <lastmod> — but it's a poor fit on the Astro/static stack this integration targets: @astrojs/sitemap emits no lastmod by default, there's an open bug where lastmod never reaches sitemap-index.xml entries (astro#16838), it's date-granular, and it's weak for aggregated/listing pages whose content derives from many sources. A content hash is precise, self-contained, and doesn't couple this feature to a second integration's config.
  • Escape hatch for stacks that do maintain accurate lastmod: the exported pure helpers let a caller compute the changed set however they like and call submitToIndexNow directly.

onError: 'skip' default. A clean 404 means "first run" → submit all once. Any other fetch/parse failure (network blip, 5xx, malformed body) defaults to skip — submitting nothing rather than risk an accidental full resubmit (the exact 429 problem this feature exists to avoid). 'full' is available for callers who prefer completeness over caution.

Deletions included. deleted = prev ∖ curr is submitted too (IndexNow accepts removed URLs so engines recrawl and drop them). Self-cleaning: a deleted URL is absent from the new manifest, so it won't resurface next build.

Hash stability. Default hashes the full built HTML. Astro's content-hashed asset names only change with real content, but per-build volatile markup (CSP nonces, timestamps, build ids) would cause false "updated" diffs — so a normalize(html, url) hook is provided and documented.

Opt-in, not default. Keeps existing users' behavior identical; no migration needed.

Sub-options

manifestPath (build path + served URL path; default indexnow-manifest.json), manifestUrl (override the fetch URL; default <siteUrl>/<manifestPath>), normalize, onError ('skip' | 'full').

Verification

pnpm build && pnpm typecheck && pnpm test && pnpm format:check all green locally — astro-seo-graph 274 tests (+12 new). Docs added under "Incremental IndexNow submission". minor changeset.

Independent of #54/#55 (touches indexnow/integration, not pieces); README change is in a section distinct from #51/#53.

schlessera avatar Jun 16 '26 03:06 schlessera