-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs Site] Add llms-full.txt and index.html.md endpoints (#18419)
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); | ||
}; |