Skip to content

Commit

Permalink
[Docs Site] Add llms-full.txt and index.html.md endpoints (#18419)
Browse files Browse the repository at this point in the history
  • Loading branch information
KianNH authored Dec 12, 2024
1 parent 63a2f96 commit 21069dc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/pages/[...entry]/index.html.md.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { APIRoute } from "astro";
import type { InferGetStaticPropsType, GetStaticPaths } from "astro";

import { getCollection } from "astro:content";

export const getStaticPaths = (async () => {
const entries = await getCollection("docs");

return entries.map((entry) => {
return {
params: {
// https://llmstxt.org/: (URLs without file names should append index.html.md instead.)
entry: entry.slug + "/index",
},
props: {
entry,
},
};
});
}) satisfies GetStaticPaths;

type Props = InferGetStaticPropsType<typeof getStaticPaths>;

export const GET: APIRoute<Props> = (context) => {
return new Response(context.props.entry.body, {
headers: {
"content-type": "text/markdown",
},
});
};
14 changes: 14 additions & 0 deletions src/pages/llms-full.txt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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))
.then((array) => array.join("\n\n"));

return new Response(markdown, {
headers: {
"content-type": "text/plain",
},
});
};

0 comments on commit 21069dc

Please sign in to comment.