|
| 1 | +import type { Metadata } from 'next' |
| 2 | +import { notFound } from 'next/navigation' |
| 3 | +import { DocsArticle } from '@/components/docs/docs-article' |
| 4 | +import { |
| 5 | + getAdjacentDocs, |
| 6 | + getDocsStaticParams, |
| 7 | + loadDoc, |
| 8 | +} from '@/lib/docs/load' |
| 9 | +import { extractToc } from '@/lib/docs/toc' |
| 10 | +import { docsMdxComponents } from '@/lib/mdx/docs-components' |
| 11 | +import { renderMdx } from '@/lib/mdx/render' |
| 12 | + |
| 13 | +export function generateStaticParams() { |
| 14 | + return getDocsStaticParams() |
| 15 | +} |
| 16 | + |
| 17 | +export async function generateMetadata({ |
| 18 | + params, |
| 19 | +}: { |
| 20 | + params: Promise<{ slug: string[] }> |
| 21 | +}): Promise<Metadata> { |
| 22 | + const { slug: slugParts } = await params |
| 23 | + const slug = slugParts.join('/') |
| 24 | + const doc = loadDoc(slug) |
| 25 | + if (!doc) return { title: 'Not found — Tawny' } |
| 26 | + |
| 27 | + return { |
| 28 | + title: `${doc.title} — Tawny`, |
| 29 | + description: doc.description, |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +export default async function DocsSlugPage({ |
| 34 | + params, |
| 35 | +}: { |
| 36 | + params: Promise<{ slug: string[] }> |
| 37 | +}) { |
| 38 | + const { slug: slugParts } = await params |
| 39 | + const slug = slugParts.join('/') |
| 40 | + const doc = loadDoc(slug) |
| 41 | + if (!doc) notFound() |
| 42 | + |
| 43 | + const { content, error } = await renderMdx(doc.body, docsMdxComponents) |
| 44 | + if (error) { |
| 45 | + console.error('Docs MDX render failed:', error) |
| 46 | + notFound() |
| 47 | + } |
| 48 | + |
| 49 | + const { prev, next } = getAdjacentDocs(slug) |
| 50 | + const toc = extractToc(doc.body) |
| 51 | + |
| 52 | + return ( |
| 53 | + <DocsArticle |
| 54 | + breadcrumbs={[ |
| 55 | + { label: 'Docs', href: '/docs' }, |
| 56 | + { label: doc.title }, |
| 57 | + ]} |
| 58 | + toc={toc} |
| 59 | + content={content} |
| 60 | + prev={prev} |
| 61 | + next={next} |
| 62 | + /> |
| 63 | + ) |
| 64 | +} |
0 commit comments