|
| 1 | +import { blog } from '@/.source/server'; |
| 2 | +import { notFound } from 'next/navigation'; |
| 3 | +import { HomeLayout } from 'fumadocs-ui/layouts/home'; |
| 4 | +import { Logo } from '../../components/Logo'; |
| 5 | +import defaultMdxComponents from 'fumadocs-ui/mdx'; |
| 6 | + |
| 7 | +export default async function BlogPost({ |
| 8 | + params, |
| 9 | +}: { |
| 10 | + params: Promise<{ slug: string }>; |
| 11 | +}) { |
| 12 | + const { slug } = await params; |
| 13 | + const post = blog.find((post: any) => post.slug === slug); |
| 14 | + |
| 15 | + if (!post) notFound(); |
| 16 | + |
| 17 | + const MDX = post.data.body; |
| 18 | + |
| 19 | + return ( |
| 20 | + <HomeLayout |
| 21 | + nav={{ title: <Logo />, url: '/' }} |
| 22 | + links={[ |
| 23 | + { |
| 24 | + text: 'Documentation', |
| 25 | + url: '/docs', |
| 26 | + active: 'nested-url', |
| 27 | + }, |
| 28 | + { |
| 29 | + text: 'Blog', |
| 30 | + url: '/blog', |
| 31 | + active: 'nested-url', |
| 32 | + }, |
| 33 | + ]} |
| 34 | + > |
| 35 | + <article className="container mx-auto max-w-3xl px-6 py-12"> |
| 36 | + <header className="mb-12 text-center"> |
| 37 | + <div className="mb-4 text-sm text-fd-muted-foreground"> |
| 38 | + <time>{new Date(post.data.date).toLocaleDateString()}</time> |
| 39 | + {post.data.author && <span> • {post.data.author}</span>} |
| 40 | + </div> |
| 41 | + <h1 className="text-4xl font-bold leading-tight md:text-5xl"> |
| 42 | + {post.data.title} |
| 43 | + </h1> |
| 44 | + {post.data.description && ( |
| 45 | + <p className="mt-6 text-xl text-fd-muted-foreground"> |
| 46 | + {post.data.description} |
| 47 | + </p> |
| 48 | + )} |
| 49 | + </header> |
| 50 | + |
| 51 | + <div className="prose prose-zinc dark:prose-invert max-w-none"> |
| 52 | + <MDX components={defaultMdxComponents} /> |
| 53 | + </div> |
| 54 | + </article> |
| 55 | + </HomeLayout> |
| 56 | + ); |
| 57 | +} |
| 58 | + |
| 59 | +export function generateStaticParams() { |
| 60 | + return blog.map((post) => ({ |
| 61 | + slug: post.slug, |
| 62 | + })); |
| 63 | +} |
| 64 | + |
| 65 | +export async function generateMetadata({ |
| 66 | + params |
| 67 | +}: { |
| 68 | + params: Promise<{ slug: string }> |
| 69 | +}) { |
| 70 | + const { slug } = await params; |
| 71 | + const post = blog.find((post) => post.slug === slug); |
| 72 | + if (!post) return; |
| 73 | + return { |
| 74 | + title: post.data.title, |
| 75 | + description: post.data.description, |
| 76 | + }; |
| 77 | +} |
0 commit comments