|
| 1 | +import { getLLMText } from '@/lib/get-llm-txt'; |
| 2 | +import { source, scriptsSource, selfHostingSource, changelogSource, legalDocsSource } from '@/lib/source'; |
| 3 | +import { notFound } from 'next/navigation'; |
| 4 | + |
| 5 | +export const revalidate = false; |
| 6 | + |
| 7 | +export async function GET( |
| 8 | + _req: Request, |
| 9 | + props: { params: Promise<{ slug?: string[] }> }, |
| 10 | +) { |
| 11 | + const params = await props.params; |
| 12 | + const slug = params.slug || []; |
| 13 | + |
| 14 | + // Determine which source to use based on the path |
| 15 | + let page = null; |
| 16 | + |
| 17 | + if (slug[0] === 'product-docs') { |
| 18 | + page = source.getPage(slug.slice(1)); |
| 19 | + } else if (slug[0] === 'scripts') { |
| 20 | + page = scriptsSource.getPage(slug.slice(1)); |
| 21 | + } else if (slug[0] === 'self-hosting') { |
| 22 | + page = selfHostingSource.getPage(slug.slice(1)); |
| 23 | + } else if (slug[0] === 'changelog') { |
| 24 | + page = changelogSource.getPage(slug.slice(1)); |
| 25 | + } else if (slug[0] === 'legal') { |
| 26 | + page = legalDocsSource.getPage(slug.slice(1)); |
| 27 | + } |
| 28 | + |
| 29 | + if (!page) notFound(); |
| 30 | + |
| 31 | + try { |
| 32 | + return new Response(await getLLMText(page), { |
| 33 | + headers: { |
| 34 | + 'Content-Type': 'text/markdown', |
| 35 | + }, |
| 36 | + }); |
| 37 | + } catch (error) { |
| 38 | + console.error('Failed to generate LLM text:', error); |
| 39 | + return new Response('Error generating markdown content', { status: 500 }); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +export function generateStaticParams() { |
| 44 | + return [ |
| 45 | + ...source.generateParams().map(param => ({ slug: ['product-docs', ...(param.slug || [])] })), |
| 46 | + ...scriptsSource.generateParams().map(param => ({ slug: ['scripts', ...(param.slug || [])] })), |
| 47 | + ...selfHostingSource.generateParams().map(param => ({ slug: ['self-hosting', ...(param.slug || [])] })), |
| 48 | + ...changelogSource.generateParams().map(param => ({ slug: ['changelog', ...(param.slug || [])] })), |
| 49 | + ...legalDocsSource.generateParams().map(param => ({ slug: ['legal', ...(param.slug || [])] })), |
| 50 | + ]; |
| 51 | +} |
0 commit comments