Since 0.25.0
negotiateMarkdown
Answer a request with page Markdown when it asks for Markdown, or with null so the page renders.
Answers a request that wants page Markdown, and returns null for one that wants HTML, so your route renders the page. It takes a Web Request, so it works in any framework that uses them, such as TanStack Start route handlers and middleware, or Next.js route handlers.
import { negotiateMarkdown } from "@qino/cms";
const response = await negotiateMarkdown(request, () =>
postCollection.getPageMarkdown(slug),
);
return response ?? next();
Signature
function negotiateMarkdown(
request: Request,
load: LoadPageMarkdown,
): Promise<Response | null>;
type LoadPageMarkdown = () => string | null | Promise<string | null>;
Parameters
load usually calls a primitive's getPageMarkdown, but any string works, so the homepage or a middleware can use it too. LoadPageMarkdown is exported from @qino/cms.
When it serves Markdown
A request wants Markdown when its path ends in .md, whatever its Accept header says. Otherwise it reads the Accept header:
- Types and parameter names are case-insensitive.
- A
,or;inside a quoted parameter value, such asnote="a,b", is part of the value. - A range whose q-value doesn't follow RFC 9110, such as
q=1.5orq=oops, is ignored. - It never answers
406 Not Acceptable. A request that accepts neither type getsnull, and so HTML.
On a prerendered page, a host rewrite picks the answer before negotiateMarkdown runs, and its regex can disagree with this table. See Known limits.
Returns
Promise<Response | null>:
nullwhen the request wants HTML.loadisn't called.- A
200with the page Markdown whenloadresolves to a string. - A
404whenloadresolves tonull, with a short Markdown body that links to/llms.txton the request's origin:
# Not found
This page doesn't exist. See [llms.txt](https://example.com/llms.txt) for the pages that do.
Both responses carry Content-Type: text/markdown; charset=utf-8 and Vary: Accept. A HEAD request gets the same status and headers, with no body.
It adds no Link header: add one to your HTML responses, with the URL from getMarkdownUrl.
Throws
Whatever load throws.