Skip to content

Commit a8fe078

Browse files
committed
🐛 fix LLM MDX endpoint for locale-prefixed pages
Move llms.mdx route from /llms.mdx/docs/[[...slug]] to /llms.mdx/[lang]/docs/[[...slug]] and pass lang to source.getPage. Add locale-aware rewrite rule (/:lang/docs/:path*.mdx) and keep the bare /docs/ rewrite defaulting to en. https://claude.ai/code/session_01UwMuBPaeouJ16zJTVa8UJm
1 parent cb5e463 commit a8fe078

3 files changed

Lines changed: 28 additions & 21 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getLLMText, source } from "@/lib/source";
2+
import { notFound } from "next/navigation";
3+
4+
export const revalidate = false;
5+
6+
export async function GET(
7+
_req: Request,
8+
{ params }: { params: Promise<{ lang: string; slug?: string[] }> },
9+
) {
10+
const { lang, slug } = await params;
11+
const page = source.getPage(slug, lang);
12+
if (!page) notFound();
13+
14+
return new Response(await getLLMText(page), {
15+
headers: {
16+
"Content-Type": "text/markdown",
17+
},
18+
});
19+
}
20+
21+
export function generateStaticParams() {
22+
return source.generateParams();
23+
}

docs/app/llms.mdx/docs/[[...slug]]/route.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/next.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ const config = {
77
reactStrictMode: true,
88
async rewrites() {
99
return [
10+
{
11+
source: '/:lang/docs/:path*.mdx',
12+
destination: '/llms.mdx/:lang/docs/:path*',
13+
},
1014
{
1115
source: '/docs/:path*.mdx',
12-
destination: '/llms.mdx/docs/:path*',
16+
destination: '/llms.mdx/en/docs/:path*',
1317
},
1418
];
1519
},

0 commit comments

Comments
 (0)