Skip to content

Commit fe0ddb4

Browse files
committed
[Docs Site] Improve llms-full.txt
1 parent ef60404 commit fe0ddb4

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { APIRoute } from "astro";
2+
import { getCollection } from "astro:content";
3+
import { slug } from "github-slugger";
4+
5+
export async function getStaticPaths() {
6+
const products = await getCollection("products");
7+
8+
const areas = new Set(
9+
products.flatMap((p) => {
10+
if (!p.data.product.group) return [];
11+
12+
return slug(p.data.product.group.toLowerCase());
13+
}),
14+
);
15+
16+
return [...areas].map((area) => {
17+
return {
18+
params: {
19+
area,
20+
},
21+
};
22+
});
23+
}
24+
25+
export const GET: APIRoute = async ({ params }) => {
26+
const products = await getCollection("products", (p) => {
27+
if (!p.data.product.group) return false;
28+
29+
return slug(p.data.product.group.toLowerCase()) === params.area;
30+
});
31+
32+
const markdown = await getCollection("docs", (e) => {
33+
if (!e.body) return false;
34+
35+
return products.some((p) =>
36+
e.slug.startsWith(p.data.product.url.slice(1, -1)),
37+
);
38+
})
39+
.then((entries) =>
40+
entries.map((entry) => {
41+
return [
42+
`# ${entry.data.title}`,
43+
`URL: https://developers.cloudflare.com/${entry.slug}/`,
44+
`${entry.body.trim()}`,
45+
"---",
46+
].join("\n\n");
47+
}),
48+
)
49+
.then((array) => array.join("\n\n"));
50+
51+
return new Response(markdown, {
52+
headers: {
53+
"content-type": "text/plain",
54+
},
55+
});
56+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { APIRoute } from "astro";
2+
import { getCollection } from "astro:content";
3+
4+
export async function getStaticPaths() {
5+
const products = await getCollection("products", (p) => {
6+
return p.data.product.group?.toLowerCase() === "developer platform";
7+
});
8+
9+
return products.map((entry) => {
10+
return {
11+
params: {
12+
product: entry.id,
13+
},
14+
props: {
15+
product: entry,
16+
},
17+
};
18+
});
19+
}
20+
21+
export const GET: APIRoute = async ({ props }) => {
22+
const markdown = await getCollection("docs", (e) => {
23+
return (
24+
e.slug.startsWith(props.product.data.product.url.slice(1, -1)) && e.body
25+
);
26+
})
27+
.then((entries) =>
28+
entries.map((entry) => {
29+
return [
30+
`# ${entry.data.title}`,
31+
`URL: https://developers.cloudflare.com/${entry.slug}/`,
32+
`${entry.body.trim()}`,
33+
"---",
34+
].join("\n\n");
35+
}),
36+
)
37+
.then((array) => array.join("\n\n"));
38+
39+
return new Response(markdown, {
40+
headers: {
41+
"content-type": "text/plain",
42+
},
43+
});
44+
};

src/pages/llms-full.txt.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ import type { APIRoute } from "astro";
22
import { getCollection } from "astro:content";
33

44
export const GET: APIRoute = async () => {
5-
const markdown = await getCollection("docs")
6-
.then((entries) => entries.map((entry) => entry.body))
5+
const markdown = await getCollection("docs", (e) => e.body)
6+
.then((entries) =>
7+
entries.map((entry) => {
8+
return [
9+
`# ${entry.data.title}`,
10+
`URL: https://developers.cloudflare.com/${entry.slug}/`,
11+
`${entry.body.trim()}`,
12+
"---",
13+
].join("\n\n");
14+
}),
15+
)
716
.then((array) => array.join("\n\n"));
817

918
return new Response(markdown, {

0 commit comments

Comments
 (0)