|
| 1 | +import { notFound } from "next/navigation"; |
| 2 | +import Link from "next/link"; |
| 3 | +import { getDocPage, getAllDocPages } from "@/lib/content/loader"; |
| 4 | +import MarkdownContent from "@/components/MarkdownContent"; |
| 5 | +import type { Metadata } from "next"; |
| 6 | + |
| 7 | +interface DocPageProps { |
| 8 | + params: Promise<{ slug: string }>; |
| 9 | +} |
| 10 | + |
| 11 | +export async function generateStaticParams() { |
| 12 | + const docs = getAllDocPages(); |
| 13 | + return docs.map((doc) => ({ |
| 14 | + slug: doc.metadata.slug, |
| 15 | + })); |
| 16 | +} |
| 17 | + |
| 18 | +export async function generateMetadata({ |
| 19 | + params, |
| 20 | +}: DocPageProps): Promise<Metadata> { |
| 21 | + const { slug } = await params; |
| 22 | + const doc = getDocPage(slug); |
| 23 | + |
| 24 | + if (!doc) { |
| 25 | + return { |
| 26 | + title: "Page Not Found", |
| 27 | + }; |
| 28 | + } |
| 29 | + |
| 30 | + return { |
| 31 | + title: `${doc.metadata.title} | AI DevKit Documentation`, |
| 32 | + description: doc.metadata.description, |
| 33 | + }; |
| 34 | +} |
| 35 | + |
| 36 | +export default async function DocPage({ params }: DocPageProps) { |
| 37 | + const { slug } = await params; |
| 38 | + const doc = getDocPage(slug); |
| 39 | + |
| 40 | + if (!doc) { |
| 41 | + notFound(); |
| 42 | + } |
| 43 | + |
| 44 | + const allDocs = getAllDocPages(); |
| 45 | + const currentIndex = allDocs.findIndex((d) => d.metadata.slug === slug); |
| 46 | + const prevDoc = currentIndex > 0 ? allDocs[currentIndex - 1] : null; |
| 47 | + const nextDoc = |
| 48 | + currentIndex < allDocs.length - 1 ? allDocs[currentIndex + 1] : null; |
| 49 | + |
| 50 | + return ( |
| 51 | + <div className="bg-white py-16"> |
| 52 | + <article className="mx-auto max-w-4xl px-4 sm:px-6 lg:px-8"> |
| 53 | + <nav className="mb-8 text-sm text-gray-600"> |
| 54 | + <Link href="/docs" className="hover:text-black transition-colors"> |
| 55 | + Documentation |
| 56 | + </Link> |
| 57 | + <span className="mx-2">/</span> |
| 58 | + <span className="text-black">{doc.metadata.title}</span> |
| 59 | + </nav> |
| 60 | + |
| 61 | + <h1 className="text-4xl md:text-5xl font-bold mb-4"> |
| 62 | + {doc.metadata.title} |
| 63 | + </h1> |
| 64 | + |
| 65 | + {doc.metadata.description && ( |
| 66 | + <p className="text-xl text-gray-600 mb-12"> |
| 67 | + {doc.metadata.description} |
| 68 | + </p> |
| 69 | + )} |
| 70 | + |
| 71 | + <MarkdownContent content={doc.content} /> |
| 72 | + </article> |
| 73 | + <nav className="mt-16 pt-8 border-t border-gray-200 mx-auto max-w-4xl px-4 sm:px-6 lg:px-8"> |
| 74 | + <div className="grid grid-cols-1 md:grid-cols-2 gap-4"> |
| 75 | + {prevDoc ? ( |
| 76 | + <Link |
| 77 | + href={`/docs/${prevDoc.metadata.slug}`} |
| 78 | + className="p-4 border border-gray-200 rounded-lg hover:border-black transition-colors no-underline group" |
| 79 | + > |
| 80 | + <div className="text-sm text-gray-600 mb-1">Previous</div> |
| 81 | + <div className="font-bold group-hover:opacity-70 transition-opacity"> |
| 82 | + ← {prevDoc.metadata.title} |
| 83 | + </div> |
| 84 | + </Link> |
| 85 | + ) : ( |
| 86 | + <div /> |
| 87 | + )} |
| 88 | + {nextDoc && ( |
| 89 | + <Link |
| 90 | + href={`/docs/${nextDoc.metadata.slug}`} |
| 91 | + className="p-4 border border-gray-200 rounded-lg hover:border-black transition-colors no-underline text-right group" |
| 92 | + > |
| 93 | + <div className="text-sm text-gray-600 mb-1">Next</div> |
| 94 | + <div className="font-bold group-hover:opacity-70 transition-opacity"> |
| 95 | + {nextDoc.metadata.title} → |
| 96 | + </div> |
| 97 | + </Link> |
| 98 | + )} |
| 99 | + </div> |
| 100 | + </nav> |
| 101 | + </div> |
| 102 | + ); |
| 103 | +} |
0 commit comments