Skip to content

Commit e7bd8a2

Browse files
committed
[Style Guide] AI consumability in How we docs
1 parent d5a19de commit e7bd8a2

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
pcx_content_type: how-to
3+
title: AI consumability
4+
meta:
5+
title: AI consumability | How we docs
6+
---
7+
8+
import { Details, GitHubCode, Tabs, TabItem } from "~/components";
9+
10+
We have various approaches for making our content visible to AI as well as making sure it's easily consumed in a plain-text format.
11+
12+
## AI discoverability
13+
14+
The primary proposal in this space is [`llms.txt`](https://llmstxt.org/), offering a well-known path for a Markdown list of all your pages.
15+
16+
We have implemented `llms.txt`, `llms-full.txt` and also created per-page Markdown links as follows:
17+
18+
- [`llms.txt`](/llms.txt)
19+
- [`llms-full.txt`](/llms-full.txt)
20+
- We also provide a `llms-full.txt` file on a per-product basis, i.e [`/workers/llms-full.txt`](/workers/llms-full.txt)
21+
- [`/$page/index.md`](index.md)
22+
- Add `/index.md` to the end of any page to get the Markdown version, i.e [`/style-guide/index.md`](/style-guide/index.md)
23+
- [`/markdown.zip`](/markdown.zip)
24+
- An export of all of our documentation in the aforementioned `index.md` format.
25+
26+
In the top right of this page, you will see a `Page options` button where you can copy the current page as Markdown that can be given to your LLM of choice.
27+
28+
## Textual representation of interactive elements
29+
30+
HTML is easily parsed - after all, the browser has to parse it to decide how to render the page you're reading now - it tends to not be very _portable_.
31+
32+
For example, given our [`Tabs`](/style-guide/components/tabs/), the panels are hidden until the tab itself is clicked:
33+
34+
<Tabs>
35+
<TabItem label="One">One Content</TabItem>
36+
<TabItem label="Two">Two Content</TabItem>
37+
</Tabs>
38+
39+
If we run the resulting HTML from this component through a solution like [`turndown`](https://www.npmjs.com/package/turndown):
40+
41+
```md
42+
- [One](#tab-panel-6)
43+
- [Two](#tab-panel-7)
44+
45+
One Content
46+
47+
Two Content
48+
```
49+
50+
The references to the panels `id`, usually handled by JavaScript, are visible but non-functional.
51+
52+
### Turning our components into "Markdownable" HTML
53+
54+
To solve this, we created a [`rehype plugin`](https://github.com/cloudflare/cloudflare-docs/blob/d5a19deded110bce6a7c5d45e702d36527da0a4e/src/plugins/rehype/filter-elements.ts) for:
55+
56+
- Removing non-content tags (`script`, `style`, `link`, etc) via a [tags allowlist](https://github.com/cloudflare/cloudflare-docs/blob/d5a19deded110bce6a7c5d45e702d36527da0a4e/src/plugins/rehype/filter-elements.ts#L19-L104)
57+
- [Transforming custom elements](https://github.com/cloudflare/cloudflare-docs/blob/d5a19deded110bce6a7c5d45e702d36527da0a4e/src/plugins/rehype/filter-elements.ts#L189-L227) like `starlight-tabs` into standard unordered lists
58+
- [Adapting our Expressive Code codeblocks HTML](https://github.com/cloudflare/cloudflare-docs/blob/d5a19deded110bce6a7c5d45e702d36527da0a4e/src/plugins/rehype/filter-elements.ts#L143-L178) to the [HTML that CommonMark expects](https://spec.commonmark.org/0.31.2/#example-142)
59+
60+
Taking the `Tabs` example from the previous section and running it through our plugin will now give us a normal unordered list with the content properly associated with a given list item:
61+
62+
```md
63+
- One
64+
65+
One Content
66+
67+
- Two
68+
69+
Two Content
70+
```
71+
72+
For example, take a look at our Markdown test fixture (or any page by appending `/index.md` to the URL):
73+
74+
- [`/style-guide/fixtures/markdown/`](/style-guide/fixtures/markdown/)
75+
- [`/style-guide/fixtures/markdown/index.md`](/style-guide/fixtures/markdown/index.md)

0 commit comments

Comments
 (0)