# Markdown twins

https://docs.kleaver.ie/reference/markdown-twins/

Markdown twins — every page also ships as plain Markdown (`scripts/markdown/`)

For AI models and other machines, `prepare-dist.mjs` writes `page.md` beside every built page (`index.md`, `about.md`, `guides/tips.md`) and adds `Link: </page.md>; rel="alternate"; type="text/markdown"` to `_headers` (pretty URLs: `/` and `/page`). A model that fetches `https://site/page.md` gets the page's own content as clean Markdown (title, description, canonical address, then `<main>` and the footer); the site menu, scripts, styles, forms, buttons and anything `hidden` or `aria-hidden` are left out. It is generated from the **built HTML**, so every component, old or new, is covered with nothing to add; a site opts out with `"markdown": false` in `scripts/sites.json` (the owner portal does), a page with `<meta name="robots" content="noindex">` and error pages get none, and `.md` files already in the output (internal notes are deleted first) are never overwritten.
**Rule for every component and module from now on:** the meaning must be in the static HTML. Text, prices, hours and answers belong in the markup (or in a table beside a chart), not only drawn by JavaScript, CSS `content:` or an image. A carousel's slides are all in the page, a chart has its data table, an icon-only link has a text label. Decorative extras take `aria-hidden="true"` so the twin leaves them out. Owner text can never become structure in a twin (a line starting `#`, `-` or `>`, brackets, stars and angle brackets are escaped); `scripts/test/markdown.test.mjs` proves it, and that Forge's real twin carries its prices, FAQ and contact details. **On the page's own address:** the edge function `netlify/edge-functions/markdown.mjs` (decisions in `lib/negotiate.mjs`) serves the twin, as `text/markdown`, to a caller that sends `Accept: text/markdown` (at least as welcome as `text/html`) or is a known AI crawler (GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, Claude-User, anthropic-ai, PerplexityBot, CCBot and a few more; never Googlebot, Bingbot or a browser), with `Vary: Accept, User-Agent`, `X-Robots-Tag: noindex` and `Link: <page>; rel="canonical"`. Everyone else gets the page untouched, and any failure (no twin, a fetch error, a bad request) falls through to the page. It runs only for pages (assets, fonts, scripts and `/book-api/` are excluded) and only on **Git-linked** sites (Forge Hyrox, the sandbox), because Netlify bundles the repo's edge functions into Git builds; sites deployed with `scripts/deploy.sh` (CLI) still serve the twin at `/page.md` and the `Link` header, but do not negotiate.
