Skip to content

Phase 1: AI crawler tokens in robots.txt and a real-lastmod sitemap - #290

Merged
neuromechanist merged 7 commits into
feature/issue-284-epic-agent-readinessfrom
feature/issue-285-phase1-robots-sitemap
Sep 3, 2026
Merged

neuromechanist merged 7 commits into
feature/issue-284-epic-agent-readinessfrom
feature/issue-285-phase1-robots-sitemap

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Adds a pure src/lib/robots.ts builder that allow-lists twelve named AI crawler tokens (GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, Claude-SearchBot, Claude-User, PerplexityBot, Google-Extended, Applebot, Applebot-Extended, meta-externalagent, CCBot) on production hosts, sharing a single Allow: / rule group, followed by the existing User-agent: * allow and a Sitemap: line. src/pages/robots.txt.ts is now a thin route over that builder. Non-production hosts keep the exact byte-identical disallow-all body they always served.

Adds a pure src/lib/sitemap.ts with sitemapLastmod (parses the catalog's space-separated UTC timestamp into a W3C datetime, returning null rather than guessing when it does not parse), an entry builder that keeps only active/public rows with a managed nm*/on* id, a small fixed list of marketing routes with no lastmod, and buildSitemapXml which XML-escapes every value.

Adds src/pages/sitemap.xml.ts, an SSR route that pages the live catalog through the existing listAllDatasets client, builds the XML on every request so lastmod tracks each dataset's own updated_at, and responds with Content-Type: application/xml; charset=utf-8 and a public, max-age=300, s-maxage=3600, stale-while-revalidate=86400 cache policy. A catalog fetch failure returns 503 with Cache-Control: no-store and a logged error, never an empty urlset.

This is an SSR route rather than @astrojs/sitemap by design: the plugin freezes every lastmod at build time, and both routes are API-driven with no new dependency added.

Test plan

  • bun run lint -- clean, no findings
  • bun run typecheck -- 0 errors (242 files; pre-existing unrelated hints only)
  • bun run test -- 1546/1546 passed, including 28 new robots.txt tests and 17 new sitemap tests
  • NEMAR_SKIP_OG_GENERATE=1 bun run build -- completed; both OG-generation scripts already honor NEMAR_SKIP_OG_GENERATE=1 (no change needed there)

Test coverage includes: every AI crawler token present exactly once and in the prescribed order; the wildcard Allow: / still present on production; the exact non-production disallow-all body string; the Sitemap line present on app.nemar.org/nemar.org/ww2.nemar.org and absent on test.nemar.org, a *.pages.dev host, and localhost; sitemap lastmod matching a row's own updated_at; exclusion of a private row, a non-active row, and a ds-prefixed row; XML escaping of &/<; no output containing openneuro.org; and a row with an unparseable timestamp yielding an entry with no <lastmod>.

The sitemap test fixture (test/fixtures/sitemap-catalog.json) is a real capture from curl -s "https://api.nemar.org/datasets?limit=5", following the precedent of the existing jsonld-catalog-* fixtures. All five captured rows are active/public managed datasets, so the private/non-active/ds-prefixed exclusion tests clone a real row and override only the field under test.

Closes #285
Part of epic #284

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review addressed. All findings acted on; nothing carried forward.

Moderate, the crawler-block contiguity test. Fixed in c383e51. The old assertion checked only that the last token was followed by Allow: /, which the reviewer showed passes even when the group is split, because both halves carry the same rule today. The test now asserts the whole block as one contiguous string and adds a second assertion that exactly two Allow: / rule groups exist. I re-ran the reviewer's exact mutation (give GPTBot its own group, leave the other eleven sharing a second one) and it now fails six test cases across all three production hosts; restoring the file returns 31 green.

Suggestion, the duplicated managed-id regex. Fixed in 852a400. datasetSitemapEntries now calls isManagedDatasetId from lib/api.ts instead of declaring a second copy of /^(nm|on)\d{6}$/.

Suggestion, escapeXml living in the OG-card module. Fixed in e0eaa28. Moved to a neutral src/lib/xml.ts with no re-export shim, and all three consumers (og-image.ts, site-og-image.ts, sitemap.ts) now import from there. The docstring records why it moved, so the next person does not put it back.

Nice-to-have, no host gate on the sitemap route. Fixed in 3c8e7fe, gated on isNoindexHost rather than isProductionHost. A real non-production deploy has no use for a sitemap (its robots.txt never advertises one, the middleware stamps X-Robots-Tag: noindex, and its catalog is nemar-db-dev), so a stray probe there was paying a full multi-page catalog fan-out for a document nothing should read. Local dev is deliberately still served, which is the distinction isNoindexHost already exists to draw, and it is the only place this route is verifiable against the real catalog before it ships. Confirmed localhost still returns the full document after the change.

Nice-to-have, the ~10s worst-case timeout when a slow first page stacks on a slow parallel page. Accepted as-is, deliberately. The response is edge-cacheable and confirmed to pass isPublicCacheable, so the cost is paid at most once per five minutes per PoP, and a slow correct sitemap is better than a spurious 503 that tells a crawler the sitemap is broken. Tightening the deadline would trade a rare slow response for a rare wrong one.

Out-of-scope note acknowledged: the "never canonicalize to openneuro.org" requirement is a policy this PR does not touch, satisfied by canonicalOriginFor in the existing head logic. I verified independently that the rendered sitemap contains zero openneuro.org references.

Gates after the fixes: lint clean, typecheck 0 errors, 1549 tests green across 64 files (up from 1546, the three new host-parameterized cases), and NEMAR_SKIP_OG_GENERATE=1 bun run build completes. Live check against a dev server on the real catalog: 761 URLs (6 static plus all 755 datasets), 755 <lastmod> values, valid XML per xmllint, and lastmod for nm000281 is 2026-08-31T11:09:05.000Z against the API's own updated_at of 2026-08-31 11:09:05.

@neuromechanist
neuromechanist merged commit 8be4174 into feature/issue-284-epic-agent-readiness Sep 3, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-285-phase1-robots-sitemap branch September 3, 2026 10:36
neuromechanist added a commit that referenced this pull request Sep 3, 2026
…lms.txt (#294)

* Phase 1: AI crawler tokens in robots.txt and a real-lastmod sitemap (#290)

* Allow AI crawlers in robots.txt

* Add real-lastmod sitemap.xml route

* Add tests and fixture for robots/sitemap

* Move escapeXml to a neutral xml module

* Assert the crawler block stays contiguous

* Reuse isManagedDatasetId in the sitemap filter

* Skip the sitemap on noindex hosts

* Phase 2: server-rendered Use-this-data section and .md mirror (#291)

* lib: export license helpers from jsonld

* types: add zarr status fields to Dataset

* lib: add use-this-data model and tests

* add UseThisData section component

* layout: add generic headLinks to Base

* dataset: render Use this data section

* dataset: add markdown mirror endpoint

* fix: render Use this data outside unpublished ternary

* fix: make page unpublished flag authoritative

* fix: mark up commands and URLs, not sentences

* Phase 6: nemar.org llms.txt and a footer link (#293)

* Add /llms.txt endpoint with tests

* Link llms.txt from the footer

* Fix llms.txt license claim, was off by 10x

* Give llms.txt search link a working q example

* Require v prefix on llms.txt version placeholder

* Un-link llms.txt dataset-page placeholder

* Phase 3: Signposting Link headers and link elements (#292)

* lib: add signposting link model and tests

* dataset: emit Signposting Link header and tags

* Rewrite Zarr recipe to be index-agnostic

* Correct the download facts and add a cd step

* Check value/note discipline in every section

* Cite the published version, not the selected one

* Number both references; soften sparse access

* Escape interpolated text in the .md mirror

* Validate ORCIDs and reject unsafe Link hrefs

* Strip a trailing slash from the .md alternate

* Split Applebot out and pin robots groups

* Cache robots and llms.txt; noindex the mirror

* Add route tests for the four new routes

* Cite sources for the routing and ORCID notes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant