Skip to content

Commit 9b7de28

Browse files
committed
[Docs Site] Use vendored Markdown for llms-full.txt
1 parent 3d4ba98 commit 9b7de28

File tree

8 files changed

+67
-153
lines changed

8 files changed

+67
-153
lines changed

.github/workflows/publish-production.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ jobs:
4141
cd distmd && zip -r markdown.zip .
4242
npx wrangler r2 object put vendored-markdown/markdown.zip --file=markdown.zip --remote
4343
rm markdown.zip
44+
45+
cd distllms
46+
for file in $(find . -type f); do
47+
npx wrangler r2 object put vendored-markdown/$file --file=$file --remote
48+
done
4449
- name: Upload vendored Markdown files to ZT DevDocs bucket
4550
env:
4651
AWS_ACCESS_KEY_ID: ${{ secrets.ZT_DEVDOCS_ACCESS_KEY_ID }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# build output
22
dist/
33
distmd/
4+
distllms/
45
# generated types
56
.astro/
67

bin/generate-index-md.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
1+
import {
2+
readFileSync,
3+
writeFileSync,
4+
mkdirSync,
5+
appendFileSync,
6+
existsSync,
7+
} from "node:fs";
28

39
import glob from "fast-glob";
410
import { parse } from "node-html-parser";
511
import { htmlToMarkdown } from "~/util/markdown";
612

13+
import YAML from "yaml";
14+
715
const files = await glob("dist/**/*.html");
816

917
for (const file of files) {
18+
if (file === "dist/index.html" || file === "dist/404.html") {
19+
continue;
20+
}
21+
1022
const html = readFileSync(file, "utf-8");
1123
const dom = parse(html);
1224

@@ -24,9 +36,42 @@ for (const file of files) {
2436
continue;
2537
}
2638

39+
const product = file.split("/")[1];
2740
const path = file.replace("dist/", "distmd/").replace(".html", ".md");
2841

2942
mkdirSync(path.split("/").slice(0, -1).join("/"), { recursive: true });
30-
3143
writeFileSync(path, markdown);
44+
45+
const llmsFullContent = ["<page>", markdown, "</page>\n\n"].join("\n");
46+
47+
mkdirSync(`distllms/${product}`, { recursive: true });
48+
appendFileSync("distllms/llms-full.txt", llmsFullContent);
49+
appendFileSync(`distllms/${product}/llms-full.txt`, llmsFullContent);
50+
51+
try {
52+
const path = await glob(`src/content/products/${product}.*`).then((arr) =>
53+
arr.at(0),
54+
);
55+
56+
if (!path) {
57+
continue;
58+
}
59+
60+
const yaml = YAML.parse(readFileSync(path, "utf-8"));
61+
const group = yaml.product?.group?.replaceAll(" ", "-").toLowerCase();
62+
63+
if (!group) {
64+
continue;
65+
}
66+
67+
mkdirSync(`distllms/${group}`, { recursive: true });
68+
appendFileSync(`distllms/${group}/llms-full.txt`, llmsFullContent);
69+
} catch (error) {
70+
if (error instanceof Error) {
71+
console.error(
72+
`Failed to find a product group for ${product}:`,
73+
error.message,
74+
);
75+
}
76+
}
3277
}

src/pages/[area]/llms-full.txt.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/pages/[product]/llms-full.txt.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/pages/llms-full.txt.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

worker/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ export default class extends WorkerEntrypoint<Env> {
2222
});
2323
}
2424

25+
if (request.url.endsWith("/llms-full.txt")) {
26+
const { pathname } = new URL(request.url);
27+
const res = await this.env.VENDORED_MARKDOWN.get(pathname.slice(1));
28+
29+
return new Response(res?.body, {
30+
headers: {
31+
"Content-Type": "text/markdown; charset=utf-8",
32+
},
33+
});
34+
}
35+
2536
if (request.url.endsWith("/index.md")) {
2637
const htmlUrl = request.url.replace("index.md", "");
2738
const res = await this.env.ASSETS.fetch(htmlUrl, request);

worker/index.worker.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ describe("Cloudflare Docs", () => {
212212
expect(response.status).toBe(200);
213213

214214
const text = await response.text();
215-
expect(text).toContain("URL: https://developers.cloudflare.com/");
216-
expect(text).toContain('from "~/components"');
215+
expect(text).toContain("<page>");
217216
});
218217

219218
it("product-specific llms-full.txt", async () => {
@@ -223,8 +222,7 @@ describe("Cloudflare Docs", () => {
223222
expect(response.status).toBe(200);
224223

225224
const text = await response.text();
226-
expect(text).toContain("URL: https://developers.cloudflare.com/");
227-
expect(text).toContain('from "~/components"');
225+
expect(text).toContain("<page>");
228226
});
229227

230228
it("area-specific llms-full.txt", async () => {
@@ -236,8 +234,7 @@ describe("Cloudflare Docs", () => {
236234
expect(response.status).toBe(200);
237235

238236
const text = await response.text();
239-
expect(text).toContain("URL: https://developers.cloudflare.com/");
240-
expect(text).toContain('from "~/components"');
237+
expect(text).toContain("<page>");
241238
});
242239
});
243240

0 commit comments

Comments
 (0)