Skip to content

feat(site): serve Markdown to clients that ask for it on Netlify - #16

Open
pimlock wants to merge 2 commits into
mainfrom
feat/markdown-negotiation/pimlock
Open

pimlock wants to merge 2 commits into
mainfrom
feat/markdown-negotiation/pimlock

Conversation

@pimlock

@pimlock pimlock commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Serve each page's Markdown copy at the page's own URL to clients that send Accept: text/markdown, so agents can fetch /about/overview/ and get Markdown without knowing about the .md suffix. Browsers keep getting HTML.

Changes

  • netlify/edge-functions/markdown.js: fetches <path>.md (/index.md for the root page) and returns it with Content-Type: text/markdown, Content-Location and Vary: Accept. It serves Markdown only when text/markdown is named and weighted at least as high as text/html. Paths without a Markdown copy, such as redirect pages, fall back to the normal response.
  • The function's config limits it to requests whose Accept header mentions text/markdown, and skips paths with a file extension. The handler serves Markdown only for GET and HEAD (Netlify's method filter rejects HEAD). Browser traffic never invokes it, so it adds no edge function usage for normal page views.
  • netlify.toml adds Vary: Accept to static responses.
  • scripts/serve.mjs negotiates the same way, so mise run serve matches Netlify.
  • README describes the behavior.

Testing

  • mise run test: 46 of 46 pass, including new tests for Accept parsing, Markdown paths, the header rule, and the handler (served, root page, browser, fallback, other methods).
  • mise run lint is clean.
  • Local server against a built site: curl -H 'Accept: text/markdown' /0.1.9/about/overview/ returns Markdown; a browser Accept returns HTML.

To check on the deploy preview:

  • curl -sI -H 'Accept: text/markdown' <preview>/about/overview/ returns text/markdown, and without the header returns HTML.
  • Netlify accepts the header config, and a normal page view doesn't count as an edge function invocation.

A Netlify edge function serves each page's Markdown copy (<path>.md) at the
page's own URL when the request's Accept header prefers text/markdown. It runs
only for GET and HEAD requests whose Accept mentions text/markdown, so browser
traffic never invokes it. netlify.toml adds Vary: Accept to static responses.
scripts/serve.mjs negotiates the same way locally.

Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
@netlify

netlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for ai-openshell-docs ready!

Name Link
🔨 Latest commit 18e5ec6
🔍 Latest deploy log https://app.netlify.com/projects/ai-openshell-docs/deploys/6b0491ae7a65c4d2b31f3caa
😎 Deploy Preview https://deploy-preview-16--ai-openshell-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

TaylorMutch
TaylorMutch previously approved these changes Nov 23, 2026
Netlify's manifest accepts only GET, POST, PUT, PATCH, DELETE and OPTIONS, so
listing HEAD failed the bundle. The Accept header rule already limits the
function to Markdown requests, and the handler checks the method itself.

Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>

This branch has not been deployed

No deployments
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.

2 participants