src/pages — sitemap eligibility, robots meta, gated routes and site-report hooks

This file covers how a page’s own source decides its sitemap and indexing status, brand-gated redirects, and the markup the site report depends on. It loads when files in src/pages/ are read.

The sitemap is derived from the pages

@astrojs/sitemap discovers routes from the build, and which of them are eligible is derived from the pages themselves by src/lib/sitemapRoutes.ts — a route is listed only if this brand renders it (no brand-gated Astro.redirect in the frontmatter) and it does not pass robots="noindex,…" to the layout. Both the sitemap filter and the Lighthouse URL list read that one module, so neither carries a route list to keep in step. See ADR 0015.

⚠️ It refuses what it cannot read, by design — an unmodelled brand-guard term, a || in a brand condition, a computed robots={…}, an indexable={…} on a route with no per-path rule to match it, a page passing both robots and indexable, or an Astro.redirect written in some other shape all throw and name the file, failing yarn verify before the build. Defaulting to “public” on an unreadable page is how 498 noindex URLs reached Google (DEV-1414). If a new page needs a guard shape the parser doesn’t model, extend guardRedirects() rather than working around it.

Adding a private page also adds a row to the pinned matrix in src/lib/sitemapRoutes.test.ts — that diff is where a reviewer confirms the page really is meant to be withheld from search engines.

demoBank gets no sitemap at all — astro.config.mjs skips the integration for that brand, matching its Disallow: / in src/pages/robots.txt.ts and the unconditional noindex,nofollow in BrandLayout.astro. That is deliberate.

A page never slots its own robots meta

BrandLayout emits one unconditionally, so a second is always a second, and on production the layout’s default is index,follow,… — the document then says “index this” and “do not index this” together, while staging shows nothing wrong because both halves say noindex there. Instead pass one of:

indexable is legal only on a route whose URLs the sitemap filter can drop individually, i.e. one named in PER_PATH_OFFER_COLLECTIONS. That single declaration drives all three parts — which routes may claim it, which URLs the filter recognises, and where astro.config.mjs looks for the withdrawn ones — so a per-path noindex cannot ship without the matching per-path exclusion.

⚠️ src/lib/robotsAndCanonical.test.ts asserts no .astro file under src/ slots one, and it greps source text — so the literal tag inside a comment fails it too. See ADR 0019.

Brand-gated routes

ADR 0011 withholds ~17 corporate/legal routes from the bank brands with if (brand.id !== "driveNinja") return Astro.redirect("/", 307); account pages are withheld the same way by a brand flag — /my-account/favorites was until DEV-1733, which made it a route every brand serves (the page picks the device-backed or the server-backed view in its template body, so its guard stays a literal). Write the guard in that shape — sitemapRoutes.ts reads it to keep the route out of sitemap.xml, and throws on one it cannot parse.

The guard does not stop a nav surface linking the route. Gating a page means adding its href to BRAND_GATED_ROUTES in src/lib/brandRoutes.ts, which src/lib/brandRoutes.test.ts checks against this guard (ADR 0016). See src/lib/CLAUDE.md for the nav side.

⚠️ Retiring a route is not done with a page. A src/pages/<dim>/ stub calling Astro.redirect() is still type: "page", so the sitemap integration discovers it and it leaks back in. Redirect retired URLs from the top-level redirects key in astro.config.mjs, with literal paths — see src/lib/CLAUDE.md and ADR 0015.

Markup the site report reads

The site report (site-report:*, ADR 0034, ADR 0037) reads the served HTML, not cardb and not a browser, so some attributes exist only for it.

⚠️ data-gallery-source / data-gallery-count on the model and trim pages are not decoration. The trim template falls back to the model’s images when the trim has none, and the two render identically — so counting <img> cannot tell “this trim has five images” from “this trim has none”, which is one of the conditions the report is commissioned to flag. Same for data-testid="offer-provider-row", which exists on all three offer routes rather than buy-new alone. Removing any of them silently degrades the report rather than breaking a test. If a future column needs something only an island renders, render that fact into the server HTML as these do — do not reinstate a browser.

⚠️ data-gallery-images is what keeps images 2 to N checked. The trim page and the three offer pages show one gallery image, through MediaGalleryTrigger.astro, so the served HTML holds a single <img> for a gallery of any size (the viewer renders the rest in the browser). The component writes every image src as a JSON array into data-gallery-images on its wrapper, and e2e/report/parse.ts reads it. A page that shows a gallery any other way, or a change that drops the attribute, silently stops the report from finding broken images after the first. The trigger also carries data-gallery (only when there is media), written "" or undefined and never as a boolean: Astro prints a boolean data-* attribute as the string "true" or "false", so data-gallery={hasMedia} gave an empty gallery data-gallery="false", which still matches [data-gallery] and which the raw-HTML probe in e2e/astro/gallery-probe.ts read as no gallery on any page (e2e/astro/gallery-probe.test.ts renders the expression through Astro’s addAttribute). Only the first image is given a width ladder and sizes — the viewer draws the rest from src and the thumbnail — so a page builds its gallery items with isFirst decided before the request. Its button carries data-gallery-expand, which the viewer cases locate it by (ADR 0052). The model page keeps its own carousel (MediaGallery.tsx).