Skip to content

Commit 95c1a9e

Browse files
authored
[Docs Site] Improve llms-full.txt (#19040)
* [Docs Site] Improve llms-full.txt * Ignore third-party legal files
1 parent 66c5ae8 commit 95c1a9e

File tree

3 files changed

+133
-2
lines changed

3 files changed

+133
-2
lines changed

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
if (
36+
e.slug === "warp-client/legal/3rdparty" ||
37+
e.slug === "magic-wan/legal/3rdparty"
38+
)
39+
return false;
40+
41+
return products.some((p) =>
42+
e.slug.startsWith(p.data.product.url.slice(1, -1)),
43+
);
44+
})
45+
.then((entries) =>
46+
entries.map((entry) => {
47+
return [
48+
`# ${entry.data.title}`,
49+
`URL: https://developers.cloudflare.com/${entry.slug}/`,
50+
`${entry.body.trim()}`,
51+
"---",
52+
].join("\n\n");
53+
}),
54+
)
55+
.then((array) => array.join("\n\n"));
56+
57+
return new Response(markdown, {
58+
headers: {
59+
"content-type": "text/plain",
60+
},
61+
});
62+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
if (
24+
e.slug === "warp-client/legal/3rdparty" ||
25+
e.slug === "magic-wan/legal/3rdparty"
26+
)
27+
return false;
28+
29+
return (
30+
e.slug.startsWith(props.product.data.product.url.slice(1, -1)) && e.body
31+
);
32+
})
33+
.then((entries) =>
34+
entries.map((entry) => {
35+
return [
36+
`# ${entry.data.title}`,
37+
`URL: https://developers.cloudflare.com/${entry.slug}/`,
38+
`${entry.body.trim()}`,
39+
"---",
40+
].join("\n\n");
41+
}),
42+
)
43+
.then((array) => array.join("\n\n"));
44+
45+
return new Response(markdown, {
46+
headers: {
47+
"content-type": "text/plain",
48+
},
49+
});
50+
};

src/pages/llms-full.txt.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,27 @@ 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) => {
6+
if (!e.body) return false;
7+
8+
if (
9+
e.slug === "warp-client/legal/3rdparty" ||
10+
e.slug === "magic-wan/legal/3rdparty"
11+
)
12+
return false;
13+
14+
return true;
15+
})
16+
.then((entries) =>
17+
entries.map((entry) => {
18+
return [
19+
`# ${entry.data.title}`,
20+
`URL: https://developers.cloudflare.com/${entry.slug}/`,
21+
`${entry.body.trim()}`,
22+
"---",
23+
].join("\n\n");
24+
}),
25+
)
726
.then((array) => array.join("\n\n"));
827

928
return new Response(markdown, {

0 commit comments

Comments
 (0)