import { notFound } from 'next/navigation' import Link from 'next/link' import Image from 'next/image' import { getBlogPosts } from '@/lib/cms' export const revalidate = 60 export async function generateStaticParams() { const posts = await getBlogPosts(50) return posts.map(p => ({ slug: (p.data.slug as string) ?? p.id })) } export default async function BlogPostPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params const posts = await getBlogPosts(50) const post = posts.find(p => (p.data.slug as string) === slug || p.id === slug) if (!post) notFound() const { title, excerpt, body, cover_image, author, category } = post.data as { title?: string; excerpt?: string; body?: string; cover_image?: string; author?: string; category?: string } const paragraphs = (body || excerpt || '').split(/\n\n+/).filter(Boolean) const date = post.publishedAt ? new Date(post.publishedAt).toLocaleDateString('en-ZA', { year: 'numeric', month: 'long', day: 'numeric' }) : '' return (
{cover_image && (
{title
)}
← Back to blog {category && ( {category} )}

{title}

{author && {author}} {author && date && ·} {date && {date}}
{excerpt && paragraphs.length <= 1 && (

{excerpt}

)}
{paragraphs.map((para, i) => (

{para}

))}
) }