---
title: "This blog is served as markdown, and here is the whole implementation"
slug: "this-blog-is-served-as-markdown"
canonical: "https://gtm.trykaso.com/blog/this-blog-is-served-as-markdown"
description: "Every article on this site has a plain-Markdown twin at the same URL with .md appended, generated from the same typed blocks that render the HTML — here is the design, the four URLs, and the part of it we cannot prove."
question: "How do I serve a markdown version of my pages to AI agents?"
category: "Engineering"
author: "The Kaso team"
authorRole: "Kaso"
published: "2026-09-08"
---

# This blog is served as markdown, and here is the whole implementation

Serve every page twice from one source of truth: the HTML at its canonical URL, and a plain-Markdown twin at the same path with .md appended. Announce the twin with a rel="alternate" type="text/markdown" link on the HTML page and list it in an /llms.txt index. Keep the canonical URL on the HTML page, so the two representations never compete with each other for the same ranking.

A Markdown twin is the same page serialised as plain Markdown and served at the same path with .md appended. It is not a second copy of the article kept in step by hand. It is a second rendering of one source of truth, which is the only version of this idea that survives contact with an editor. On this site the source of truth is a typed array of content blocks. Two functions read that array: one emits React elements, the other emits Markdown text. Neither is derived from the other.

You can check that claim against the page you are reading. Append .md to this article's URL and the same words come back with the layout removed — no navigation, no footer, no scripts, no styling, no cookie banner. Every article on this site answers on both paths. The HTML path is the canonical one and the Markdown path is a twin of it, a distinction that turns out to matter more than it sounds like it should.

## Why the content model is a typed union and not a folder of Markdown files

The ordinary way to publish articles in a Next.js application is MDX: write Markdown files, run them through remark and rehype at build time, render the tree. Kaso's blog does not do that. An article here is a TypeScript value conforming to a closed union of block kinds, and the Markdown twin is the reason.

Markdown source has to be parsed before it can become HTML, and that parse is effectively one-way. What comes out is a syntax tree shaped by whichever plugins happened to be installed, and recovering clean Markdown from it means serialising a tree that a dozen plugins have already rewritten. A typed union has no such problem. It is already a tree, it was never text, and it projects onto either target with a switch statement. HTML and Markdown end up as two peers of the same data rather than one being a lossy round trip through the other.

```console
$ grep -c '^  | { kind:' src/lib/editorial/types.ts
9
```

_Checked on 2026-09-08._ Nine block kinds: p, h2, h3, list, ordered, quote, measured, table, qa. That is the entire vocabulary an article can use, and it is closed on purpose.

The closedness is what keeps the two renderings honest. Adding a tenth block kind breaks the Markdown serialiser at compile time rather than in production, and rather than silently in the copy that only machines read. The specific failure this design exists to prevent is a page whose HTML shows a comparison table and whose Markdown twin shows nothing at all where the table was — a defect no human would notice, because no human reads the twin.

The second reason is the dependency bill. A Markdown pipeline for a handful of articles is a content platform bought on credit: remark, rehype, their plugin sets, a frontmatter parser, and a build step that now fails for reasons unrelated to anything anyone wrote. The union costs one file and no dependencies.

```console
$ grep -Ec '"(@mdx-js/[a-z-]+|@next/mdx|next-mdx-remote|contentlayer|gray-matter|remark[a-z0-9-]*|rehype[a-z0-9-]*|markdown-it|marked|unified)":' package.json
0
```

_Checked on 2026-09-08._ No Markdown or MDX toolchain is installed. For scale: the same package.json declares 18 runtime and 16 development dependencies in total, counted with node -e 'const p=require("./package.json"); console.log(Object.keys(p.dependencies).length, Object.keys(p.devDependencies).length)'.

## What an agent saves by fetching Markdown instead of HTML

An HTML page is mostly not its content. The bytes are framework payload, inlined styles, serialised component props, analytics, and the navigation that is identical on every page of the site. A model asked to answer a question from that page has to find the article inside the delivery mechanism first, and it pays for every byte it reads while doing so. The size of the gap is easy to measure on any site that publishes both representations of the same document.

```console
$ curl -sSL -o /dev/null -w '%{size_download} %{url_effective}\n' https://ai-sdk.dev/docs/introduction -o /dev/null https://ai-sdk.dev/docs/introduction.md
784332 https://ai-sdk.dev/docs/introduction
22357 https://ai-sdk.dev/docs/introduction.md
```

_Checked on 2026-09-08._ One page on one site, not a benchmark. Vercel's AI SDK documentation was used because it serves both representations of the same document at the same path. The HTML transfer is roughly 35 times the size of the Markdown twin.

Thirty-five to one is a single data point and should not be turned into a rule about the web. What it establishes is the shape of the problem: the ratio is not 1.2 to 1, and the difference between the two numbers is not the article. The command above works unchanged against this page — substitute this article's URL for the AI SDK one.

Bytes are also the smaller half of the argument. The larger half is extraction accuracy. Given HTML, a model has to infer which text is the article and which text is the chrome, and it makes that judgement with no ground truth and no way to signal uncertainty. Given Markdown, the heading hierarchy is unambiguous, the list is a list, the table is a table, and there is nothing on the page that is not the document. A twin removes a guess rather than merely making the guess cheaper.

## The four URLs, exactly

Four URLs answer, and behind them sit three route handlers, one page and one serialiser. Nothing here is novel and nothing here is large, which is the point worth making about it.

- /blog/<slug> renders the article as a page, with FAQPage and Article JSON-LD generated from the same blocks.
- /blog/<slug>.md returns the same article as Markdown: a heading, the standfirst, then the blocks in order.
- /blog/llms.txt returns a section index — every article, its one-line summary, and a link to its .md twin.
- /llms.txt returns a site index: what Kaso is in a sentence, then links to the sections and to the blog's own llms.txt.

```console
$ find src/app -path '*llms.txt/route.ts' -o -path '*blog/\[slug\]/markdown/route.ts' -o -path '*blog/\[slug\]/page.tsx' | sort
src/app/(marketing)/blog/[slug]/markdown/route.ts
src/app/(marketing)/blog/[slug]/page.tsx
src/app/(marketing)/blog/llms.txt/route.ts
src/app/llms.txt/route.ts
```

_Checked on 2026-09-08._ Four URLs, four files, but only three of them are route handlers — the article itself is a page. An earlier draft of this section called all four route handlers, which is the kind of error a reader cannot catch and a one-line command can.

One wrinkle is worth passing on, because it costs an hour to find. The Next.js App Router cannot own a literal .md suffix on a dynamic segment — /blog/[slug].md collides with the page at /blog/[slug] — so the handler is registered at /blog/<slug>/markdown and a rewrite maps the .md spelling onto it. Both spellings answer, and the .md one is the one published, because appending .md is the convention agents already try.

A second rewrite gives the article's own URL two representations. A request carrying Accept: text/markdown reaches the same handler, so a client that prefers Markdown never has to learn the suffix convention — it asks for what it wants in the ordinary HTTP way and gets Markdown back from the canonical URL. One URL with two representations needs Vary: Accept on both of them, because a shared cache told nothing about the negotiation is precisely how the Markdown copy ends up being handed to the next browser that asked for the page. That header is configured for the article URL, and on this site it does not arrive on the HTML representation. The block below is the check, and it fails.

```console
$ U=localhost:3101/blog/this-blog-is-served-as-markdown
curl -s -o /dev/null -w 'no Accept header:      %{content_type}\n' "$U"
curl -s -o /dev/null -w 'Accept: text/markdown: %{content_type}\n' -H 'Accept: text/markdown' "$U"
no Accept header:      text/html; charset=utf-8
Accept: text/markdown: text/markdown; charset=utf-8
```

_Checked on 2026-09-08._ One URL, two representations, chosen by the request. Run against a local dev server (pnpm dev -p 3101), which is why the host is localhost.

```console
$ U=localhost:3101/blog/this-blog-is-served-as-markdown
probe() {
  printf '%-24s ' "$1"
  shift
  curl -sI "$@" | tr -d '\r' | awk '
    tolower($1) == "vary:" { for (i = 2; i <= NF; i++) { gsub(/,/, "", $i); if (tolower($i) == "accept") found = 1 } }
    END { print (found ? "Vary: Accept sent" : "Vary: Accept ABSENT") }'
}
probe "html, no Accept" "$U"
probe "html, Accept: markdown" -H 'Accept: text/markdown' "$U"
probe ".md twin" "$U.md"
printf 'link header on html      '; curl -sI "$U" | tr -d '\r' | grep -i '^link: </blog'
html, no Accept          Vary: Accept ABSENT
html, Accept: markdown   Vary: Accept sent
.md twin                 Vary: Accept sent
link header on html      Link: </blog/this-blog-is-served-as-markdown.md>; rel="alternate"; type="text/markdown"
```

_Checked on 2026-09-08._ A published defect rather than a published feature, kept here because an article arguing that claims should be re-derivable does not get to delete the check that failed. Two of the three representations send the header and the HTML one does not. The configuration entry that sets it is matching, which the fourth line shows: the Link header declared beside it in the same entry does arrive, so the source pattern is right and the Vary value is being replaced downstream by the framework's own Vary on a page response. The consequence is bounded but real: a shared cache in front of this site can serve the Markdown representation of an article URL to a browser. Requires the dev server on port 3101.

The twin itself opens with YAML front matter — nine fields, among them the canonical URL, the target question and the publication date — so a client that reads the file and never looks at a response header still knows which URL is the real one.

```console
$ wc -l src/lib/editorial/markdown.ts && grep -c '^import' src/lib/editorial/markdown.ts
     185 src/lib/editorial/markdown.ts
1
```

_Checked on 2026-09-08._ The entire serialiser is 185 lines, of which 91 are code and 80 are comment. Its one import is an import type, so the module pulls nothing into the runtime graph — deliberate, because the file is reachable from a rendered page and from the route handlers alike, and this repository has already had a shared module drag a server-only renderer into a graph that could not run it.

The two llms.txt files follow the format the proposal specifies: an H1 with the site or section name, a blockquote summary, optional prose, then H2 sections containing lists of links with short descriptions. The nesting is deliberate. The proposal at llmstxt.org allows an llms.txt at any path, covering the URLs beneath it, so /blog/llms.txt is the file an agent should prefer when it is already looking at the blog, and /llms.txt is the one it finds when it has been handed nothing but a domain.

## Why announce the same thing in four places

| Channel | Who reads it | Cost to implement |
| --- | --- | --- |
| link rel="alternate" type="text/markdown" on the article | A client that already has the HTML and wants a cleaner copy of it | One link element and one Link response header; this site sends both |
| link rel="describedby" pointing at the covering llms.txt | A client that has one page and wants the map around it | One link element, alongside the first |
| /blog/llms.txt | A client pointed at the blog that wants the list of articles | One route over the article array |
| /llms.txt | A client that starts from the bare domain with no URL in hand | One route over the site's sections |

_The link relations are the ones named in the llms.txt proposal at llmstxt.org; text/markdown is registered by RFC 7763._

```console
$ curl -s localhost:3101/blog/this-blog-is-served-as-markdown | grep -oE '<link rel="(alternate|describedby)"[^>]*>'
<link rel="alternate" type="text/markdown" href="http://localhost:3101/blog/this-blog-is-served-as-markdown.md"/>
<link rel="describedby" type="text/plain" href="/blog/llms.txt"/>
```

_Checked on 2026-09-08._ The first two rows of the table, in the head of the page you are reading. The pattern is anchored on rel= rather than on the word markdown because this article's slug contains that word, so a looser grep also matches the ordinary rel="canonical" element and reports three. Requires the dev server (pnpm dev -p 3101).

You do all four because each is read by a client standing in a different place, and each costs a few lines. An agent that arrives with a URL already in hand will never fetch /llms.txt. An agent handed only a domain will never see the link element on an article it has not found. Picking one channel is choosing which of those clients to be invisible to, in exchange for saving an afternoon.

The sitemap is a fifth file and a different job, and it is worth being precise about why it is not on that list. sitemap.xml enumerates the indexable, human-readable pages for search crawlers. It does not list the Markdown twins, and it should not: a sitemap carrying both representations of every document asks a crawler to decide which of two identical texts is the real one.

## The canonical URL stays on the HTML page

This is the part that is easy to get backwards, and getting it backwards is expensive. Two URLs returning the same words is textbook duplicate content. If the .md twin declares itself canonical, or declares nothing and gets indexed on its own, a site has split its own signals across two paths for one document and will rank worse than it did before it started.

The rule is one line long. The canonical URL is the HTML URL, always; the Markdown twin declares that same canonical rather than itself, using the Link response header form of the canonical relation registered in RFC 6596; and the twin never appears in the sitemap. A Markdown twin is a representation of a document, not a second document, and every signal the site emits should say so consistently.

```console
$ curl -s -D - -o /dev/null localhost:3101/blog/this-blog-is-served-as-markdown.md | tr -d '\r' | grep -iE '^(content-type|link):'
content-type: text/markdown; charset=utf-8
link: <http://localhost:3101/blog/this-blog-is-served-as-markdown>; rel="canonical"
```

_Checked on 2026-09-08._ The twin points at the article rather than at itself. The front matter repeats the same statement, because a crawler that reads headers does not parse front matter and a model handed the file never sees a header. The tr is load-bearing: response headers are CRLF-terminated, and without it every line here ends in a carriage return that a reader copying this block would never see and could not reproduce. Requires the dev server (pnpm dev -p 3101).

## What is not known about llms.txt

The publishing side of llms.txt is real and checkable. The proposal is authored by Jeremy Howard, published at llmstxt.org on 3 September 2024 and revised on 10 August 2026, and the developer-documentation sites for Claude, OpenAI and Gemini each return one.

```console
$ for h in platform.claude.com developers.openai.com ai.google.dev/gemini-api/docs; do curl -sSL -o /dev/null -w '%{http_code} %{size_download} %{url_effective}\n' "https://$h/llms.txt"; done
200 73533 https://platform.claude.com/llms.txt
200 5853 https://developers.openai.com/llms.txt
200 32545 https://ai.google.dev/gemini-api/docs/llms.txt
```

_Checked on 2026-09-08._ The same check against www.anthropic.com/llms.txt and platform.openai.com/llms.txt returned 404 on the same day, so the files live on the developer-documentation hosts rather than the marketing domains.

Publishing a file is not the same as a model reading it, and that is where the evidence thins out. The adoption numbers in circulation are largely published by the parties with an interest in adoption: the proposal's own site, the documentation platforms that generate the file automatically, and the SEO plugins that sell the feature. What is missing is a crawler operator documenting that the file changes what gets retrieved.

```console
$ curl -sSL https://developers.google.com/search/docs/crawling-indexing/google-common-crawlers -o /tmp/gc.html && grep -c 'llms.txt' /tmp/gc.html
0
```

_Checked on 2026-09-08._ Roughly 89 KB of Google's own crawler documentation, zero occurrences of the string. The exact byte count moves between fetches, which is why it is not quoted here. One page is not proof that nothing reads the file, and it is no evidence at all about any other vendor. It is evidence that the largest crawler operator does not document reading it.

So Kaso publishes llms.txt and makes no claim about what it achieves. It costs one route handler and it is inspectable by anyone, which is a fair price for a bet that might not pay. The Markdown twin is the half of this work that stands on an argument not contingent on any vendor's roadmap: a URL that returns clean text is useful to a crawler, to a model with a fetch tool, to a person pasting a page into a chat window, and to the next engineer here who wants to diff what an article said last month against what it says now.

## The questions this raises for anyone building the same thing

**Do I need MDX or a Markdown pipeline to serve a Markdown version of my pages?**

No. Serving a Markdown twin is a serialisation problem, not a parsing problem. If the content is already structured — a typed array of blocks, a CMS response, rows in a database — a function that walks that structure and emits Markdown text is enough, and a route returns the result with a text/markdown content type. An MDX pipeline solves the opposite problem, turning Markdown source into HTML, and it leaves no clean path back to Markdown once plugins have rewritten the tree.

**Should the .md version of a page be its canonical URL?**

No. The canonical URL should stay on the HTML page. A Markdown twin is a second representation of one document, so declaring the .md URL canonical, or letting it be indexed with no canonical at all, splits ranking signals across two paths carrying identical text. Point the twin's canonical at the HTML URL using a Link response header, keep the twin out of the sitemap, and let the HTML page be the one that is indexed.

**What does an llms.txt file have to contain?**

The format specified at llmstxt.org is a Markdown file whose only required element is an H1 naming the site or section. Convention adds a blockquote summary immediately after it, then any non-heading prose that helps a reader interpret the links, then H2 sections containing Markdown lists of links, each optionally followed by a colon and a short description. The file can sit at the site root or at any path, where it covers the URLs beneath that path, and an agent that finds more than one should use the most specific.

**Is there evidence that models actually read llms.txt?**

Evidence that models read llms.txt is thin, and what exists is mostly published by the parties who benefit from its adoption. The proposal at llmstxt.org reports wide uptake, and the developer-documentation sites for Claude, OpenAI and Gemini each returned an llms.txt file when checked on 8 September 2026. What is missing is documentation from a crawler operator confirming the file changes retrieval: Google's crawler documentation does not mention llms.txt at all. Publish one because it costs almost nothing and can be inspected by anyone, not because a vendor has promised it is read.

## A page only a browser can read has to be reverse-engineered by everything else

The whole implementation is one serialiser, three route handlers, two rewrites, two link elements and two Link response headers. It is a smaller change than the argument around it makes it sound, and it is the rare piece of site engineering a reader can verify without being given access to anything: append .md to this URL, and either the twin is there and matches, or this article is wrong about itself.
