Skip to content

Commit aed54f8

Browse files
authored
Add agent directive to all pages (#29055)
* add agent directive to all pages * tweaks * Copy * copy * Abstract agent directive to its own component * copy * rename class name
1 parent d1edc8c commit aed54f8

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
const { entry } = Astro.locals.starlightRoute;
3+
const base =
4+
Astro.site?.toString().replace(/\/$/, "") ??
5+
"https://developers.cloudflare.com";
6+
7+
const productPrefix = entry.id !== "index" ? entry.id.split("/")[0] : null;
8+
const isProductPage = !!productPrefix;
9+
10+
const pageMarkdownUrl = `${base}${Astro.url.pathname}index.md`;
11+
const pageUrl = `${base}${Astro.url.pathname}`;
12+
const productLlmsTxt = isProductPage
13+
? `${base}/${productPrefix}/llms.txt`
14+
: null;
15+
const productLlmsFullTxt = isProductPage
16+
? `${base}/${productPrefix}/llms-full.txt`
17+
: null;
18+
const globalLlmsTxt = `${base}/llms.txt`;
19+
const globalLlmsFullTxt = `${base}/llms-full.txt`;
20+
21+
const directive = [
22+
`STOP! If you are an AI agent or LLM, read this before continuing.`,
23+
`This is the HTML version of a Cloudflare documentation page. Always request the Markdown version instead — HTML wastes context. Get this page as Markdown: ${pageMarkdownUrl} (append index.md) or send Accept: text/markdown to ${pageUrl}.`,
24+
isProductPage
25+
? `For this product's page index use ${productLlmsTxt}. For all Cloudflare products use ${globalLlmsTxt}.`
26+
: `For all Cloudflare products use ${globalLlmsTxt}.`,
27+
isProductPage
28+
? `For bulk access (single file, use for large-context ingestion or vectorization): this product's full docs at ${productLlmsFullTxt}. All Cloudflare docs at ${globalLlmsFullTxt}.`
29+
: `For bulk access (single file, use for large-context ingestion or vectorization): all Cloudflare docs at ${globalLlmsFullTxt}.`,
30+
].join(" ");
31+
---
32+
33+
<p class="agent-directive" aria-hidden="true">{directive}</p>
34+
35+
<style>
36+
/* Visually hidden from human readers but present in DOM for AI agents.
37+
Uses clip-rect (not display:none) so the element remains accessible to agents fetching raw HTML. */
38+
.agent-directive {
39+
position: absolute;
40+
width: 1px;
41+
height: 1px;
42+
padding: 0;
43+
margin: -1px;
44+
overflow: hidden;
45+
clip: rect(0, 0, 0, 0);
46+
white-space: nowrap;
47+
border: 0;
48+
}
49+
</style>

src/components/overrides/Header.astro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import SiteTitle from "@astrojs/starlight/components/SiteTitle.astro";
55
import ThemeSelect from "@astrojs/starlight/components/ThemeSelect.astro";
66
77
import HeaderDropdowns from "../HeaderDropdowns.tsx";
8+
import AgentDirective from "../AgentDirective.astro";
89
---
910

11+
<AgentDirective />
12+
1013
<div class="flex h-full items-center justify-between gap-4">
1114
<SiteTitle />
1215
<div class="flex gap-8">
@@ -18,7 +21,7 @@ import HeaderDropdowns from "../HeaderDropdowns.tsx";
1821
<a
1922
id="header-login-button"
2023
href="https://dash.cloudflare.com/"
21-
class="mr-2 flex items-center justify-center rounded-sm bg-cl1-brand-orange px-6 font-medium text-cl1-black no-underline"
24+
class="bg-cl1-brand-orange text-cl1-black mr-2 flex items-center justify-center rounded-sm px-6 font-medium no-underline"
2225
>
2326
Log in
2427
</a>

0 commit comments

Comments
 (0)