|
| 1 | +import { getAllPosts, getPostBySlug } from "@/lib/posts"; |
| 2 | +import { remark } from "remark"; |
| 3 | +import html from "remark-html"; |
| 4 | +import Link from "next/link"; |
| 5 | +import { notFound } from 'next/navigation'; |
| 6 | + |
| 7 | +type Props = { |
| 8 | + params: Promise<{ slug: string }>; |
| 9 | +}; |
| 10 | + |
| 11 | +export async function generateStaticParams() { |
| 12 | + const posts = getAllPosts(); |
| 13 | + return posts.map((post) => ({ slug: post.slug })); |
| 14 | +} |
| 15 | + |
| 16 | +export default async function PostPage({ params }: Props) { |
| 17 | + const { slug } = await params; |
| 18 | + |
| 19 | + try { |
| 20 | + const post = getPostBySlug(slug); |
| 21 | + const processedContent = await remark().use(html).process(post.content); |
| 22 | + const contentHtml = processedContent.toString(); |
| 23 | + |
| 24 | + return ( |
| 25 | + <div className="min-h-screen text-neutral-100 py-20 px-6"> |
| 26 | + <article className="max-w-5xl mx-auto bg-neutral-900/80 border border-neutral-800 backdrop-blur-md rounded-2xl shadow-md overflow-hidden p-10"> |
| 27 | + <header className="border-b border-neutral-800 pb-6 mb-10"> |
| 28 | + <p className="text-sm text-green-400 tracking-wide uppercase"> |
| 29 | + {new Date(post.meta.date).toLocaleDateString("ja-JP", { |
| 30 | + year: "numeric", |
| 31 | + month: "long", |
| 32 | + day: "numeric", |
| 33 | + })} |
| 34 | + </p> |
| 35 | + <h1 className="mt-3 text-3xl font-bold text-white">{post.meta.title}</h1> |
| 36 | + {post.meta.description && ( |
| 37 | + <p className="mt-3 text-neutral-400 text-sm leading-relaxed"> |
| 38 | + {post.meta.description} |
| 39 | + </p> |
| 40 | + )} |
| 41 | + </header> |
| 42 | + |
| 43 | + <div |
| 44 | + className="prose prose-invert lg:prose-xl max-w-none" |
| 45 | + dangerouslySetInnerHTML={{ __html: contentHtml }} |
| 46 | + /> |
| 47 | + |
| 48 | + <footer className="border-t border-neutral-800 pt-6 mt-10"> |
| 49 | + <Link href="/blog" className="mt-6 text-sm font-bold text-green-400 tracking-wide uppercase"> |
| 50 | + → Back |
| 51 | + </Link> |
| 52 | + </footer> |
| 53 | + </article> |
| 54 | + </div> |
| 55 | + ); |
| 56 | + } catch (error) { |
| 57 | + console.error(`Failed to load post ${slug}:`, error); |
| 58 | + notFound(); |
| 59 | + } |
| 60 | +} |
0 commit comments