Skip to content

Commit

Permalink
[Docs Site] Improve llms-full.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
KianNH committed Jan 7, 2025
1 parent ef60404 commit fe0ddb4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 2 deletions.
56 changes: 56 additions & 0 deletions src/pages/[area]/llms-full.txt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { APIRoute } from "astro";
import { getCollection } from "astro:content";
import { slug } from "github-slugger";

export async function getStaticPaths() {
const products = await getCollection("products");

const areas = new Set(
products.flatMap((p) => {
if (!p.data.product.group) return [];

return slug(p.data.product.group.toLowerCase());
}),
);

return [...areas].map((area) => {
return {
params: {
area,
},
};
});
}

export const GET: APIRoute = async ({ params }) => {
const products = await getCollection("products", (p) => {
if (!p.data.product.group) return false;

return slug(p.data.product.group.toLowerCase()) === params.area;
});

const markdown = await getCollection("docs", (e) => {
if (!e.body) return false;

return products.some((p) =>
e.slug.startsWith(p.data.product.url.slice(1, -1)),
);
})
.then((entries) =>
entries.map((entry) => {
return [
`# ${entry.data.title}`,
`URL: https://developers.cloudflare.com/${entry.slug}/`,
`${entry.body.trim()}`,
"---",
].join("\n\n");
}),
)
.then((array) => array.join("\n\n"));

return new Response(markdown, {
headers: {
"content-type": "text/plain",
},
});
};
44 changes: 44 additions & 0 deletions src/pages/[product]/llms-full.txt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { APIRoute } from "astro";
import { getCollection } from "astro:content";

export async function getStaticPaths() {
const products = await getCollection("products", (p) => {
return p.data.product.group?.toLowerCase() === "developer platform";
});

return products.map((entry) => {
return {
params: {
product: entry.id,
},
props: {
product: entry,
},
};
});
}

export const GET: APIRoute = async ({ props }) => {
const markdown = await getCollection("docs", (e) => {
return (
e.slug.startsWith(props.product.data.product.url.slice(1, -1)) && e.body
);
})
.then((entries) =>
entries.map((entry) => {
return [
`# ${entry.data.title}`,
`URL: https://developers.cloudflare.com/${entry.slug}/`,
`${entry.body.trim()}`,
"---",
].join("\n\n");
}),
)
.then((array) => array.join("\n\n"));

return new Response(markdown, {
headers: {
"content-type": "text/plain",
},
});
};
13 changes: 11 additions & 2 deletions src/pages/llms-full.txt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import type { APIRoute } from "astro";
import { getCollection } from "astro:content";

export const GET: APIRoute = async () => {
const markdown = await getCollection("docs")
.then((entries) => entries.map((entry) => entry.body))
const markdown = await getCollection("docs", (e) => e.body)
.then((entries) =>
entries.map((entry) => {
return [
`# ${entry.data.title}`,
`URL: https://developers.cloudflare.com/${entry.slug}/`,
`${entry.body.trim()}`,
"---",
].join("\n\n");
}),
)
.then((array) => array.join("\n\n"));

return new Response(markdown, {
Expand Down

0 comments on commit fe0ddb4

Please sign in to comment.