import { Metadata } from 'next' import { notFound } from 'next/navigation' import { Container, Typography, Box, Paper, Breadcrumbs, Link, Avatar } from '@mui/material' import { Home as HomeIcon, Article as ArticleIcon, CalendarToday as DateIcon } from '@mui/icons-material' interface PageData { id: string title: string slug: string content: string contentType: 'RICH_TEXT' | 'HTML' | 'MARKDOWN' excerpt?: string featuredImage?: string seoTitle?: string seoDescription?: string publishedAt: string updatedAt: string } interface PageProps { params: Promise<{ locale: string slug: string }> } async function getPageData(slug: string): Promise { try { const response = await fetch(`${process.env.NEXTAUTH_URL || 'http://localhost:3010'}/api/pages/${slug}`, { next: { revalidate: 300 } // Revalidate every 5 minutes }) if (!response.ok) { return null } const data = await response.json() return data.success ? data.data : null } catch (error) { console.error('Failed to fetch page:', error) return null } } export async function generateMetadata({ params }: PageProps): Promise { const resolvedParams = await params const page = await getPageData(resolvedParams.slug) if (!page) { return { title: 'Page Not Found', description: 'The requested page could not be found.' } } return { title: page.seoTitle || page.title, description: page.seoDescription || page.excerpt || `Read ${page.title} on Biblical Guide`, openGraph: { title: page.seoTitle || page.title, description: page.seoDescription || page.excerpt, type: 'article', publishedTime: page.publishedAt, modifiedTime: page.updatedAt, ...(page.featuredImage && { images: [{ url: page.featuredImage, alt: page.title }] }) }, twitter: { card: 'summary_large_image', title: page.seoTitle || page.title, description: page.seoDescription || page.excerpt, ...(page.featuredImage && { images: [page.featuredImage] }) } } } function renderContent(content: string, contentType: string) { switch (contentType) { case 'HTML': return ( ) case 'MARKDOWN': // For now, render as plain text. In the future, you could add a markdown parser return ( {content} ) default: // RICH_TEXT return ( ) } } export default async function PageView({ params }: PageProps) { const resolvedParams = await params const page = await getPageData(resolvedParams.slug) if (!page) { notFound() } const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString(resolvedParams.locale, { year: 'numeric', month: 'long', day: 'numeric' }) } return ( {/* Breadcrumbs */} Home {page.title} {/* Header */} {/* Featured Image */} {page.featuredImage && ( {page.title} )} {/* Title */} {page.title} {/* Excerpt */} {page.excerpt && ( {page.excerpt} )} {/* Meta Information */} Published {formatDate(page.publishedAt)} {page.updatedAt !== page.publishedAt && ( • Updated {formatDate(page.updatedAt)} )} {/* Content */} *:first-of-type': { marginTop: 0 }, '& > *:last-child': { marginBottom: 0 } }}> {renderContent(page.content, page.contentType)} ) }