| 1 | import Link from "next/link"; |
| 2 | import { notFound } from "next/navigation"; |
| 3 | import { PageHeader } from "@/components/page-header"; |
| 4 | import { RatatuiExplorer } from "@/components/ratatui/explorer"; |
| 5 | import { RatatuiProjectLinks } from "@/components/ratatui/project-links"; |
| 6 | import { getRatatuiCopy } from "@/lib/content/ratatui"; |
| 7 | import { buildPageMetadata } from "@/lib/page-meta"; |
| 8 | import { readCatalogue } from "@/lib/ratatui/catalogue"; |
| 9 | import { fallbackAttrs } from "@/lib/i18n/fallback"; |
| 10 | |
| 11 | type PageParams = Promise<{ locale: string; component: string }>; |
| 12 | |
| 13 | export const revalidate = 3600; |
| 14 | |
| 15 | // Render component pages on demand instead of expanding every entry across all locales at build time. |
| 16 | export function generateStaticParams() { |
| 17 | return []; |
| 18 | } |
| 19 | |
| 20 | export async function generateMetadata({ params }: { params: PageParams }) { |
| 21 | const { locale, component } = await params; |
| 22 | const catalogue = await readCatalogue(); |
| 23 | const entry = catalogue.entries.find((item) => item.name === component); |
| 24 | if (!entry) notFound(); |
| 25 | |
| 26 | return buildPageMetadata({ |
| 27 | path: `/ratatui/${encodeURIComponent(entry.name)}`, |
| 28 | locale, |
| 29 | title: `${entry.title} · Codewhale Ratatui`, |
| 30 | description: entry.description, |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | export default async function RatatuiComponentPage({ params }: { params: PageParams }) { |
| 35 | const { locale, component } = await params; |
| 36 | const catalogue = await readCatalogue(); |
| 37 | const entry = catalogue.entries.find((item) => item.name === component); |
| 38 | if (!entry) notFound(); |
| 39 | const copy = getRatatuiCopy(locale); |
| 40 | const family = catalogue.families.find((item) => item.id === entry.family); |
| 41 | |
| 42 | return ( |
| 43 | <div className="ratatui-page" {...fallbackAttrs("/ratatui", locale)}> |
| 44 | <PageHeader |
| 45 | title={entry.title} |
| 46 | lede={entry.description} |
| 47 | kicker={family ? <Link href={`/${locale}/ratatui`}>{copy.title} · {family.title}</Link> : copy.title} |
| 48 | actions={ |
| 49 | <> |
| 50 | <Link href={`/${locale}/ratatui`} className="btn btn-secondary">{copy.back}</Link> |
| 51 | <Link href={`/${locale}/ratatui#ratatui-install`} className="section-link">{copy.install} →</Link> |
| 52 | </> |
| 53 | } |
| 54 | /> |
| 55 | <RatatuiExplorer catalogue={catalogue} locale={locale} copy={copy} initialEntry={entry.name} detail /> |
| 56 | <RatatuiProjectLinks revision={catalogue.source.revision} copy={copy} /> |
| 57 | </div> |
| 58 | ); |
| 59 | } |
| 60 |