Skip to content

Commit 88b4e92

Browse files
committed
docs: llms.txt
1 parent 06558be commit 88b4e92

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

apps/docs/src/server/+app.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ app.notFound = (c) => {
3535
);
3636
};
3737

38+
const docPrerender = docs.getSlugs().map((slug) => "/" + slug);
39+
3840
app.prerender = [
3941
home.page.pathname(),
40-
...docs.getSlugs().map((slug) => "/" + slug),
42+
docs.llms.pathname(),
43+
...docPrerender,
44+
...docPrerender.map((p) => p + ".md"),
4145
];
4246

4347
app.use(
@@ -87,6 +91,6 @@ if (import.meta.env.DEV) {
8791
});
8892
}
8993

90-
app.add(home, docs.page, demo);
94+
app.add(home, docs.page, docs.llms, demo);
9195

9296
export default app;

apps/docs/src/server/docs/index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { FrontmatterSchema } from "@/lib/md";
2+
import * as homeResult from "@/server/home/index.md";
23
import { Head } from "@/ui/head";
34
import type { Result } from "@robino/md";
45
import clsx from "clsx";
@@ -20,11 +21,38 @@ export const getSlugs = () => {
2021

2122
export const getContent = (slug: string) => content[`/server/docs/${slug}.md`];
2223

24+
const getMd = (result: Result<typeof FrontmatterSchema>) => {
25+
return `# ${result.frontmatter.title}\n\n${
26+
result.frontmatter.description
27+
}${result.article}`;
28+
};
29+
30+
export const llms = new Get("/llms.txt", (c) =>
31+
c.text(
32+
[homeResult, ...Object.values(content)]
33+
.map((result) => getMd(result))
34+
.join("\n"),
35+
),
36+
);
37+
2338
export const page = new Get("/:slug", (c) => {
39+
let md = false;
40+
41+
if (c.params.slug.endsWith(".md")) {
42+
md = true;
43+
c.params.slug = c.params.slug.slice(0, -3);
44+
}
45+
2446
const result = getContent(c.params.slug);
2547

2648
if (!result) return;
2749

50+
if (md) {
51+
return c.res(getMd(result), {
52+
headers: { "Content-Type": "text/markdown; charset=UTF-8" },
53+
});
54+
}
55+
2856
c.head(<Head {...result.frontmatter} />);
2957

3058
return (

apps/docs/src/server/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const NavList = () => {
115115
{docs.getSlugs().map((slug) => {
116116
return <NavLink slug={slug} />;
117117
})}
118+
<NavLink slug={docs.llms.pathname().slice(1)} />
118119
</ul>
119120

120121
<hr />
@@ -174,7 +175,7 @@ const NavLink = (props: { slug?: string; anchor?: JSX.Element }) => {
174175
)}
175176
href={href}
176177
>
177-
{props.slug.split("-").slice(1).join(" ")}
178+
{props.slug.split("-").slice(1).join(" ") || props.slug}
178179
</a>
179180
</li>
180181
);

0 commit comments

Comments
 (0)