Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ go 1.25.1
// docs-theme-extras declares the hextra import itself (pinned to v0.12.3), so
// hextra is a transitive dependency and is not listed here — matching
// agentgateway / kgateway / ambientmesh. Its checksums stay in go.sum.
require github.com/solo-io/docs-theme-extras v0.5.2 // indirect
require github.com/solo-io/docs-theme-extras v0.6.0 // indirect
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/solo-io/docs-theme-extras v0.5.0 h1:O2Z0O5UvVN/pCQE1rOpY5QxxnAgcnhxuzFX2A9xopDg=
github.com/solo-io/docs-theme-extras v0.5.0/go.mod h1:jjjYu/QoD+vMu30zgcpfEuTEGuJOJWs5qai/K18kltg=
github.com/solo-io/docs-theme-extras v0.5.2 h1:a1a14AydRIsWBdmNjJtEmhLEZrRroZqrJUEkLq+Tp08=
github.com/solo-io/docs-theme-extras v0.5.2/go.mod h1:jjjYu/QoD+vMu30zgcpfEuTEGuJOJWs5qai/K18kltg=
github.com/solo-io/docs-theme-extras v0.6.0 h1:gMgzPDxg8el4CRheHQ4ezmmV5PVAAWRmZzKWe/tasj8=
github.com/solo-io/docs-theme-extras v0.6.0/go.mod h1:jjjYu/QoD+vMu30zgcpfEuTEGuJOJWs5qai/K18kltg=
20 changes: 11 additions & 9 deletions hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
"border-t",
"border-white/10",
"border-white/8",
"cell-list",
"cell-prose",
"cell-short",
"chroma",
"col-start-1",
"content",
Expand Down Expand Up @@ -187,7 +190,6 @@
"hextra-copy-icon",
"hextra-hamburger-menu",
"hextra-max-content-width",
"hextra-max-navbar-width",
"hextra-max-page-width",
"hextra-nav-container",
"hextra-nav-container-blur",
Expand Down Expand Up @@ -230,6 +232,7 @@
"hx:bg-blue-100",
"hx:bg-green-100",
"hx:bg-primary-700/5",
"hx:bg-purple-100",
"hx:bg-transparent",
"hx:bg-white",
"hx:block",
Expand All @@ -242,6 +245,7 @@
"hx:border-blue-200",
"hx:border-gray-200",
"hx:border-green-200",
"hx:border-purple-200",
"hx:border-t",
"hx:border-transparent",
"hx:break-words",
Expand All @@ -268,13 +272,15 @@
"hx:dark:bg-green-900/30",
"hx:dark:bg-neutral-900",
"hx:dark:bg-primary-300/10",
"hx:dark:bg-purple-900/30",
"hx:dark:block",
"hx:dark:border-amber-200/30",
"hx:dark:border-blue-200/30",
"hx:dark:border-gray-100/20",
"hx:dark:border-green-200/30",
"hx:dark:border-neutral-700",
"hx:dark:border-neutral-800",
"hx:dark:border-purple-200/30",
"hx:dark:border-white/10",
"hx:dark:contrast-more:border-neutral-400",
"hx:dark:focus-visible:bg-dark",
Expand All @@ -293,6 +299,7 @@
"hx:dark:text-gray-300",
"hx:dark:text-gray-400",
"hx:dark:text-green-200",
"hx:dark:text-purple-200",
"hx:dark:text-slate-100",
"hx:data-[state=selected]:block",
"hx:data-[state=selected]:border-primary-500",
Expand Down Expand Up @@ -369,6 +376,7 @@
"hx:max-h-[min(calc(50vh-11rem-env(safe-area-inset-bottom)),400px)]",
"hx:max-md:hidden",
"hx:max-w-[50%]",
"hx:max-w-[90rem]",
"hx:max-w-[min(calc(100vw-2rem),calc(100%+20rem))]",
"hx:max-xl:hidden",
"hx:mb-0",
Expand Down Expand Up @@ -469,6 +477,7 @@
"hx:text-gray-900",
"hx:text-green-900",
"hx:text-left",
"hx:text-purple-900",
"hx:text-slate-900",
"hx:text-sm",
"hx:top-0",
Expand Down Expand Up @@ -765,6 +774,7 @@
"next-steps",
"plugins",
"pnf-home",
"pnf-home-line",
"pnf-lede",
"pnf-status",
"pnf-suggestion-list",
Expand Down Expand Up @@ -801,22 +811,14 @@
"supported-clients",
"supported-tools",
"swagger-ui",
"tabs-panel-tabs-00-0",
"tabs-panel-tabs-00-1",
"tabs-panel-tabs-01-0",
"tabs-panel-tabs-01-1",
"tabs-panel-tabs-02-0",
"tabs-panel-tabs-02-1",
"tabs-panel-tabs-03-0",
"tabs-panel-tabs-03-1",
"tabs-tab-tabs-00-0",
"tabs-tab-tabs-00-1",
"tabs-tab-tabs-01-0",
"tabs-tab-tabs-01-1",
"tabs-tab-tabs-02-0",
"tabs-tab-tabs-02-1",
"tabs-tab-tabs-03-0",
"tabs-tab-tabs-03-1",
"test-the-deployed-server",
"theme-toggle",
"top",
Expand Down
101 changes: 101 additions & 0 deletions static/_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Cloudflare Pages Worker: HTTP content negotiation for text/markdown
*
* Background
* ----------
* HTTP content negotiation (RFC 7231) lets a client declare what response
* format it prefers via the Accept request header. AI agents and developer
* tools such as Claude Code, Cursor, and OpenCode send "Accept: text/markdown"
* when fetching documentation so they receive clean, structured markdown
* instead of a full HTML page with navigation, sidebars, and scripts.
*
* How it works
* ------------
* Hugo pre-builds a .md file alongside every HTML page. For example:
* /docs/quickstart/index.html (HTML page)
* /docs/quickstart.md (markdown twin)
*
* This Worker intercepts every request before it reaches the static assets.
* When the Accept header includes "text/markdown" and the URL looks like a
* page (no file extension), the Worker tries to serve the markdown twin:
*
* 1. Strip the trailing slash and append .md
* /docs/foo/bar/ → /docs/foo/bar.md (regular doc pages)
*
* 2. If that file doesn't exist, try index.md inside the directory
* /docs/foo/ → /docs/foo/index.md (section landing pages)
*
* 3. If neither exists, fall through to the normal static asset response.
*
* URLs with file extensions (JS, CSS, images, etc.) are always passed through
* unchanged so this Worker does not affect any non-page assets.
*
* The response includes:
* Content-Type: text/markdown; charset=utf-8
* Vary: Accept — tells CDN caches to store HTML and markdown separately
*
* Origin
* ------
* Copied from agentgateway.dev (agentgateway-oss-website/static/_worker.js),
* which has served markdown this way in production. Its _redirects rules kept
* working after the Worker was added, so the same holds here. Keep the copies
* in sync if one changes.
*
* Testing
* -------
* This Worker only runs in Cloudflare Pages, not in the local Hugo dev server.
* There is no supported local emulator; the only way to test is to deploy to a
* Cloudflare Pages preview or production environment and then run:
* curl -H "Accept: text/markdown" https://aregistry.ai/docs/quickstart/
* or re-run the afdocs scorecard against the live site after deploying.
*/

export default {
async fetch(request, env) {
const url = new URL(request.url);
const accept = request.headers.get('Accept') || '';
const path = url.pathname;

// Only intercept page-like URLs (no file extension) when markdown is preferred
const hasExtension = /\.[a-zA-Z0-9]{1,5}$/.test(path);
const wantsMarkdown = accept.includes('text/markdown');

if (wantsMarkdown && !hasExtension) {
const base = path.replace(/\/$/, '');

// Pages: /docs/foo/bar/ → /docs/foo/bar.md
if (base) {
const mdUrl = new URL(url);
mdUrl.pathname = base + '.md';
const mdResp = await env.ASSETS.fetch(new Request(mdUrl.href));
if (mdResp.ok) {
return new Response(mdResp.body, {
status: 200,
headers: {
'Content-Type': 'text/markdown; charset=utf-8',
'Cache-Control': 'public, max-age=3600',
'Vary': 'Accept',
},
});
}
}

// Sections: /docs/foo/ → /docs/foo/index.md
const idxUrl = new URL(url);
idxUrl.pathname = (base || '') + '/index.md';
const idxResp = await env.ASSETS.fetch(new Request(idxUrl.href));
if (idxResp.ok) {
return new Response(idxResp.body, {
status: 200,
headers: {
'Content-Type': 'text/markdown; charset=utf-8',
'Cache-Control': 'public, max-age=3600',
'Vary': 'Accept',
},
});
}
}

return env.ASSETS.fetch(request);
},
};
Loading