import { notFound } from 'next/navigation'; import type { Metadata } from 'next'; import { allPosts } from 'contentlayer/generated'; import { getPostBySlug } from '@/lib/posts'; export function generateStaticParams() { return allPosts.map((post) => ({ slug: post.slug || post.flattenedPath })); } interface Props { params: { slug: string }; } export function generateMetadata({ params }: Props): Metadata { const slug = params.slug; const post = getPostBySlug(slug); if (!post) return {}; return { title: post.title, description: post.description || post.title }; } export default function BlogPostPage({ params }: Props) { const slug = params.slug; const post = getPostBySlug(slug); if (!post) return notFound(); return (

{post.title}

{post.feature_image && ( // feature_image is stored as "../assets/xyz", serve from "/assets/xyz" // eslint-disable-next-line @next/next/no-img-element {post.title} )} {post.published_at && (

{new Date(post.published_at).toLocaleDateString('zh-TW')}

)} {post.tags && (

{post.tags.map((t) => ( #{t} ))}

)}
); }