app/lib/markdown-twin.ts
37 lines and 5 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| linkToMarkdown | 4 to 6 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| alternateMarkdownLink | 9 to 11 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| canonicalLink | 19 to 21 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| prefersMarkdown | 23 to 25 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| markdownResponse | 32 to 42 | 2 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
Imports
It imports app/lib/negotiate.mjs, app/lib/seo.ts. Imported by app/routes/blog.$slug.tsx, app/routes/blog.$slug[.md].ts, app/routes/content-page[.md].ts, app/routes/cv[.md].ts, app/routes/kb-library[.csv].ts, app/routes/kb-library[.json].ts, app/routes/kb-library[.md].ts, app/routes/lab[.md].ts, app/routes/llms-full[.txt].ts, app/routes/llms.ts, app/routes/procedure.version[.md].ts, app/routes/procedure[.md].ts, app/routes/protocols[.csv].ts, app/routes/protocols[.json].ts, app/routes/protocols[.md].ts, app/routes/publications.$slug[.md].ts, app/routes/systems[.md].ts.
Source
import { prefersType } from "./negotiate.mjs";
import { NO_STORE_CACHE_CONTROL, SITE_ORIGIN } from "./seo";
export function linkToMarkdown(slug: string) {
return alternateMarkdownLink(`/writing/${slug}.md`);
}
/** `path` includes the `.md`. Absolute, so it matches the blog twin and `canonicalLink`. */
function alternateMarkdownLink(path: string) {
return `<${SITE_ORIGIN}${path}>; rel="alternate"; type="text/markdown"`;
}
/**
* The `Link` header a machine-only document carries to name the HTML page it stands for: a post's
* twin names the post, llms.txt and llms-full.txt name the home page. Canonical, not alternate, so a
* crawler that reaches the twin first credits the page instead. The paper twins are assets and set the
* same header from public/_headers, where code cannot reach.
*/
export function canonicalLink(path: string) {
return `<${SITE_ORIGIN}${path}>; rel="canonical"`;
}
export function prefersMarkdown(request: Request) {
return prefersType(request, "text/markdown");
}
/**
* The negotiated `/writing/:slug` variant must never be stored: under `Vary: Accept, Cookie` a second
* stored variant lets a cookie-bearing request HIT the cookieless one, skipping the Worker's
* `private, no-store` downgrade. Do not "optimize" it to `SHARED_CACHE_CONTROL`.
*/
export function markdownResponse(slug: string, body: string, cacheControl: string) {
return new Response(body, {
headers: {
"content-type": "text/markdown; charset=utf-8",
"cache-control": cacheControl,
link: canonicalLink(`/writing/${slug}`),
// Only the never-stored response is the negotiated one, so only it varies on Accept.
...(cacheControl === NO_STORE_CACHE_CONTROL ? { vary: "Accept" } : {}),
},
});
}