SvelteKit
SvelteKit
Serve Markdown from SvelteKit routes with accept-md hooks and a generated +server handler.
accept-md supports SvelteKit projects with routes/ or src/routes/.
Install
npx --yes accept-md@latest init
pnpm install
The CLI generates a route handler at src/routes/api/accept-md/[...path]/+server.js or .ts and wires src/hooks.server so Markdown requests are rewritten to that handler.
Request flow
- A client sends
Accept: text/markdown. hooks.serverdetects the request and rewrites it to the accept-md route.- The handler fetches the original SvelteKit page as HTML.
- accept-md converts the HTML to Markdown and returns it with Markdown headers.
Test locally
curl -s -H "Accept: text/markdown" http://localhost:5173/
Deploying
SvelteKit deployments need a stable baseUrl when the runtime fetches the HTML version of a page. On Vercel, use VERCEL_URL:
module.exports = {
baseUrl: process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : undefined,
};
If you use another adapter, set baseUrl to the deployed origin when needed.