From bb9e02da9a7acbc5b4a32dee58eb34e7c9ebb132 Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Thu, 30 Apr 2026 17:49:29 +0200 Subject: [PATCH] fix(infra): add llms.txt directive to markdown endpoints and set Content-Type header Addresses two failures from the afdocs spec v0.5.0 compliance check (issue #181): - Inject `> For the complete documentation index, see [llms.txt](/llms.txt)` near the top of every generated .md file (llms-txt-directive-md check). New mandatory requirement in spec v0.5.0. - Add public/_headers to serve .md files as `text/markdown; charset=utf-8` (content-negotiation check). Fixing this should also resolve the content-start-position failures as a side effect: once the checker receives text/markdown responses it will use the clean .md files (which start with content immediately) instead of converting Starlight's nav-heavy HTML. --- plugins/astro-agent-docs.mjs | 5 ++++- public/_headers | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 public/_headers diff --git a/plugins/astro-agent-docs.mjs b/plugins/astro-agent-docs.mjs index 90f9686..637ed4d 100644 --- a/plugins/astro-agent-docs.mjs +++ b/plugins/astro-agent-docs.mjs @@ -87,6 +87,9 @@ const SECTIONS = deriveSections(sidebar); // a charset=utf-8 in the Content-Type header. const BOM = "\uFEFF"; +const LLMS_TXT_DIRECTIVE = + "> For the complete documentation index, see [llms.txt](/llms.txt)\n\n"; + /** Strip YAML frontmatter, HTML comments, and MDX artifacts; prepend title heading. */ function cleanMarkdown(raw, isMdx = false) { const { data, content } = matter(raw); @@ -96,7 +99,7 @@ function cleanMarkdown(raw, isMdx = false) { } body = body.replace(/\n{3,}/g, "\n\n").trim(); const title = data.title ? `# ${data.title}\n\n` : ""; - return BOM + title + body + "\n"; + return BOM + title + LLMS_TXT_DIRECTIVE + body + "\n"; } /** diff --git a/public/_headers b/public/_headers new file mode 100644 index 0000000..73888bd --- /dev/null +++ b/public/_headers @@ -0,0 +1,2 @@ +/*.md + Content-Type: text/markdown; charset=utf-8