返回 CodeWhale
route.ts
根目录 / web / app / docs-preview / [file] / route.ts
1 import { DOCS_PREVIEW_ENTRIES, DOCS_PREVIEW_LANGUAGES, docsPreviewLlmsFullTxt, docsPreviewLlmsTxt, docsPreviewMarkdown, docsPreviewSearchSections } from "@/lib/docs-preview";
2
3 export const dynamic = "force-static";
4 export const dynamicParams = false;
5
6 const FILES: Record<string, () => { body: string; type: string }> = {
7 "llms.txt": () => ({ body: docsPreviewLlmsTxt(), type: "text/plain" }),
8 "llms-full.txt": () => ({ body: docsPreviewLlmsFullTxt(), type: "text/plain" }),
9 ...Object.fromEntries(DOCS_PREVIEW_LANGUAGES.flatMap((language) => [
10 [`search.${language}.json`, () => ({ body: JSON.stringify({ sections: docsPreviewSearchSections(language) }), type: "application/json" })],
11 ...DOCS_PREVIEW_ENTRIES.map((entry) => [
12 language === "en" ? `${entry.slug}.md` : `${entry.slug}.${language}.md`,
13 () => ({ body: docsPreviewMarkdown(entry.slug, language), type: "text/markdown" }),
14 ]),
15 ])),
16 };
17
18 export function generateStaticParams() {
19 return Object.keys(FILES).map((file) => ({ file }));
20 }
21
22 export async function GET(_request: Request, { params }: { params: Promise<{ file: string }> }) {
23 const { file } = await params;
24 const build = FILES[file];
25 if (!build) return new Response("Not found", { status: 404 });
26 const { body, type } = build();
27 return new Response(body, { headers: { "content-type": `${type}; charset=utf-8`, "cache-control": "public, max-age=3600", "x-robots-tag": "noindex" } });
28 }
29
29 lines TYPESCRIPT