Skip to content

Commit 21069dc

Browse files
authored
[Docs Site] Add llms-full.txt and index.html.md endpoints (#18419)
1 parent 63a2f96 commit 21069dc

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { APIRoute } from "astro";
2+
import type { InferGetStaticPropsType, GetStaticPaths } from "astro";
3+
4+
import { getCollection } from "astro:content";
5+
6+
export const getStaticPaths = (async () => {
7+
const entries = await getCollection("docs");
8+
9+
return entries.map((entry) => {
10+
return {
11+
params: {
12+
// https://llmstxt.org/: (URLs without file names should append index.html.md instead.)
13+
entry: entry.slug + "/index",
14+
},
15+
props: {
16+
entry,
17+
},
18+
};
19+
});
20+
}) satisfies GetStaticPaths;
21+
22+
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
23+
24+
export const GET: APIRoute<Props> = (context) => {
25+
return new Response(context.props.entry.body, {
26+
headers: {
27+
"content-type": "text/markdown",
28+
},
29+
});
30+
};

src/pages/llms-full.txt.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { APIRoute } from "astro";
2+
import { getCollection } from "astro:content";
3+
4+
export const GET: APIRoute = async () => {
5+
const markdown = await getCollection("docs")
6+
.then((entries) => entries.map((entry) => entry.body))
7+
.then((array) => array.join("\n\n"));
8+
9+
return new Response(markdown, {
10+
headers: {
11+
"content-type": "text/plain",
12+
},
13+
});
14+
};

0 commit comments

Comments
 (0)