Skip to content

Commit e8243a7

Browse files
committed
docs: better .md handling
1 parent 18a3fff commit e8243a7

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

docs/app/llms.txt/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Important Notes:
1919
for (const page of source.getPages()) {
2020
const dir = page.slugs[0];
2121
const list = map.get(dir) ?? [];
22-
list.push(`- [${page.data.title}](${page.url}): ${page.data.description}`);
22+
list.push(
23+
`- [${page.data.title}](${page.url}.md): ${page.data.description}`,
24+
);
2325
map.set(dir, list);
2426
}
2527

docs/proxy.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { getLLMText, source } from "@/lib/source/docs";
2+
import type { NextRequest } from "next/server";
3+
4+
export async function proxy(request: NextRequest) {
5+
const { pathname } = request.nextUrl;
6+
7+
if (!pathname.endsWith(".md")) {
8+
return;
9+
}
10+
11+
const slug = pathname.slice(0, -3).split("/").filter(Boolean).slice(1);
12+
13+
const page = source.getPage(slug);
14+
if (!page) {
15+
return new Response("Not Found", { status: 404 });
16+
}
17+
18+
const markdown = await getLLMText(page);
19+
20+
return new Response(markdown, {
21+
headers: {
22+
"Content-Type": "text/markdown; charset=utf-8",
23+
},
24+
});
25+
}
26+
27+
export const config = {
28+
matcher: ["/docs/:path*", "/docs", "/docs.md"],
29+
};

0 commit comments

Comments
 (0)