|
| 1 | +import { blogSource } from '@/lib/source'; |
| 2 | +import type { Metadata } from 'next'; |
| 3 | +import { notFound } from 'next/navigation'; |
| 4 | +import defaultMdxComponents from 'fumadocs-ui/mdx'; |
| 5 | +import { HomeLayout } from 'fumadocs-ui/home-layout'; |
| 6 | +import { baseOptions } from '@/app/layout.config'; |
| 7 | +import Link from 'next/link'; |
| 8 | + |
| 9 | +export default async function BlogPostPage({ |
| 10 | + params, |
| 11 | +}: { |
| 12 | + params: { slug?: string[] }; |
| 13 | +}) { |
| 14 | + const page = blogSource.getPage(params.slug); |
| 15 | + if (!page) notFound(); |
| 16 | + |
| 17 | + const MDX = page.data.body; |
| 18 | + |
| 19 | + return ( |
| 20 | + <HomeLayout {...baseOptions}> |
| 21 | + <main className="container py-12 md:py-24"> |
| 22 | + <article className="mx-auto max-w-4xl"> |
| 23 | + <Link |
| 24 | + href="/blog" |
| 25 | + className="inline-flex items-center text-sm text-muted-foreground hover:text-foreground mb-8 transition-colors" |
| 26 | + > |
| 27 | + <svg |
| 28 | + xmlns="http://www.w3.org/2000/svg" |
| 29 | + width="16" |
| 30 | + height="16" |
| 31 | + viewBox="0 0 24 24" |
| 32 | + fill="none" |
| 33 | + stroke="currentColor" |
| 34 | + strokeWidth="2" |
| 35 | + strokeLinecap="round" |
| 36 | + strokeLinejoin="round" |
| 37 | + className="mr-2" |
| 38 | + > |
| 39 | + <polyline points="15 18 9 12 15 6" /> |
| 40 | + </svg> |
| 41 | + Back to Blog |
| 42 | + </Link> |
| 43 | + |
| 44 | + <header className="mb-8"> |
| 45 | + <h1 className="text-4xl font-bold tracking-tight sm:text-5xl mb-4"> |
| 46 | + {page.data.title} |
| 47 | + </h1> |
| 48 | + |
| 49 | + {page.data.description && ( |
| 50 | + <p className="text-xl text-muted-foreground mb-4"> |
| 51 | + {page.data.description} |
| 52 | + </p> |
| 53 | + )} |
| 54 | + |
| 55 | + <div className="flex flex-wrap items-center gap-4 text-sm text-muted-foreground border-t pt-4"> |
| 56 | + {page.data.date && ( |
| 57 | + <time dateTime={page.data.date}> |
| 58 | + {new Date(page.data.date).toLocaleDateString('en-US', { |
| 59 | + year: 'numeric', |
| 60 | + month: 'long', |
| 61 | + day: 'numeric', |
| 62 | + })} |
| 63 | + </time> |
| 64 | + )} |
| 65 | + {page.data.authors && ( |
| 66 | + <span>by {page.data.authors.join(', ')}</span> |
| 67 | + )} |
| 68 | + </div> |
| 69 | + |
| 70 | + {page.data.tags && page.data.tags.length > 0 && ( |
| 71 | + <div className="flex flex-wrap gap-2 mt-4"> |
| 72 | + {page.data.tags.map((tag: string) => ( |
| 73 | + <span |
| 74 | + key={tag} |
| 75 | + className="inline-flex items-center rounded-full bg-primary/10 px-3 py-1 text-xs font-medium text-primary" |
| 76 | + > |
| 77 | + {tag} |
| 78 | + </span> |
| 79 | + ))} |
| 80 | + </div> |
| 81 | + )} |
| 82 | + </header> |
| 83 | + |
| 84 | + <div className="prose prose-slate dark:prose-invert max-w-none"> |
| 85 | + <MDX components={{ ...defaultMdxComponents }} /> |
| 86 | + </div> |
| 87 | + |
| 88 | + <footer className="mt-12 pt-8 border-t"> |
| 89 | + <Link |
| 90 | + href="/blog" |
| 91 | + className="inline-flex items-center text-sm text-primary hover:underline" |
| 92 | + > |
| 93 | + <svg |
| 94 | + xmlns="http://www.w3.org/2000/svg" |
| 95 | + width="16" |
| 96 | + height="16" |
| 97 | + viewBox="0 0 24 24" |
| 98 | + fill="none" |
| 99 | + stroke="currentColor" |
| 100 | + strokeWidth="2" |
| 101 | + strokeLinecap="round" |
| 102 | + strokeLinejoin="round" |
| 103 | + className="mr-2" |
| 104 | + > |
| 105 | + <polyline points="15 18 9 12 15 6" /> |
| 106 | + </svg> |
| 107 | + Back to Blog |
| 108 | + </Link> |
| 109 | + </footer> |
| 110 | + </article> |
| 111 | + </main> |
| 112 | + </HomeLayout> |
| 113 | + ); |
| 114 | +} |
| 115 | + |
| 116 | +export async function generateStaticParams() { |
| 117 | + return blogSource.generateParams(); |
| 118 | +} |
| 119 | + |
| 120 | +export function generateMetadata({ params }: { params: { slug?: string[] } }): Metadata { |
| 121 | + const page = blogSource.getPage(params.slug); |
| 122 | + if (!page) notFound(); |
| 123 | + |
| 124 | + return { |
| 125 | + title: page.data.title, |
| 126 | + description: page.data.description, |
| 127 | + }; |
| 128 | +} |
0 commit comments