Repository navigation
feat: Serve Markdown versions of docs pages for AI agents - #19
Merged
Merged
Conversation
- Serve every page as plain Markdown at `<path>.md` (`/index.md` for the home page), converting Markdoc tags to standard Markdown - Serve the same Markdown at the regular URL for `Accept: text/markdown` - Generate `/llms.txt` from the navigation and add `/llms-full.txt`, replacing the hand-written `public/llms.txt` - Add a "View as Markdown" button and a `rel="alternate"` link to each page
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the docs easy for AI agents to read by serving each page as plain Markdown.
<path>.mdendpoints: every page is available as Markdown, e.g./start-guide/how-to-write-markdown-notes.md(/index.mdfor the home page).src/lib/markdown.tsconverts Markdoc tags to standard Markdown:kbd→ inline code,callout→ blockquote,img/video/carousel-item→ images and links,thumb-links→ a list built from the navigation. Site-relative links become absolute URLs. Code is left untouched, and the build fails on a Markdoc tag that has no conversion, so content is never dropped silently. Pages are prerendered by a static route handler (/raw-md/...) that the*.mdrewrites point to.src/proxy.tsserves the Markdown at the regular URL whenAcceptpreferstext/markdown. Its matcher only runs for requests mentioningtext/markdown, so normal page views and prefetches skip it./llms.txtis generated fromnavigation.tsand links to the.mdpages. Pages missing from the navigation go under## Optional./llms-full.txtjoins all pages into one file. Both leave outexamples/**, like the search index. This replaces the hand-writtenpublic/llms.txt, which had gone stale.<link rel="alternate" type="text/markdown">in the page head.Notes
Vary: Accept, because Next overrides the header on pages. On Vercel the proxy runs before the CDN cache and Markdown is cached under its own path, so this only matters for third-party shared caches.xlwidths and up, like the rest of the table of contents column.Test plan
npm run lintandnpm run buildpass.mdlink in/llms.txtreturns 200 onnext start; an unknown.mdpath returns 404Accept: text/markdown(with or without lower-qtext/html) returns Markdown; browserAcceptandtext/markdown;q=0return HTML{%tags inllms-full.txtapart from a documented{% uuid %}example in inline code.mdoutput on the Vercel preview