import Link from 'next/link'; import Image from 'next/image'; import { notFound } from 'next/navigation'; import type { Metadata } from 'next'; import { allPosts } from 'contentlayer2/generated'; import { getPostBySlug, getRelatedPosts, getPostNeighbors } from '@/lib/posts'; import { siteConfig } from '@/lib/config'; import { ReadingProgress } from '@/components/reading-progress'; import { ScrollReveal } from '@/components/scroll-reveal'; import { PostLayout } from '@/components/post-layout'; import { PostCard } from '@/components/post-card'; import { PostStorylineNav } from '@/components/post-storyline-nav'; import { SectionDivider } from '@/components/section-divider'; import { FooterCue } from '@/components/footer-cue'; export function generateStaticParams() { return allPosts.map((post) => ({ slug: post.slug || post.flattenedPath })); } interface Props { params: Promise<{ slug: string }>; } export async function generateMetadata({ params }: Props): Promise { const { slug } = await params; const post = getPostBySlug(slug); if (!post) return {}; return { title: post.title, description: post.description || post.title }; } export default async function BlogPostPage({ params }: Props) { const { slug } = await params; const post = getPostBySlug(slug); if (!post) return notFound(); const relatedPosts = getRelatedPosts(post, 3); const neighbors = getPostNeighbors(post); const hasToc = /
{post.published_at && (

{new Date(post.published_at).toLocaleDateString( siteConfig.defaultLocale )}

)}

{post.title}

{post.tags && (
{post.tags.map((t) => ( #{t} ))}
)}
{post.feature_image && (
{post.title}
)}
{relatedPosts.length > 0 && (

相關文章

為你挑選相似主題

{relatedPosts.map((related) => ( ))}
)}
); }