import { notFound } from 'next/navigation'; import type { Metadata } from 'next'; import Link from 'next/link'; import { getPostBySlug, getPostsByLocale, getMediaById, getSiteInfo } from '@/lib/data'; import { processHTML } from '@/lib/html-compat'; import { getLocalizedPath } from '@/lib/i18n'; import { t } from '@/lib/i18n'; import { SEO } from '@/components/SEO'; import { LocaleSwitcher } from '@/components/LocaleSwitcher'; import { ContentRenderer } from '@/components/content/ContentRenderer'; interface PageProps { params: { slug: string; locale?: string; }; } function RelatedPosts({ currentSlug, locale }: { currentSlug: string; locale: 'en' | 'de' }) { const allPosts = getPostsByLocale(locale); const currentPost = allPosts.find((p: any) => p.slug === currentSlug); if (!currentPost) return null; // Get recent posts (excluding current) const relatedPosts = allPosts .filter((p: any) => p.slug !== currentSlug) .slice(0, 3); if (relatedPosts.length === 0) return null; return (

{t('blog.relatedPosts', locale as 'en' | 'de')}

{relatedPosts.map((post: any) => ( {post.featuredImage && (() => { const media = getMediaById(post.featuredImage); return media ? (
{post.title}
) : null; })()}

{post.title}

{t('blog.readMore', locale as 'en' | 'de')} →
))}
); } export async function generateMetadata({ params }: PageProps): Promise { const locale = (params.locale as string) || 'en'; const post = getPostBySlug(params.slug, locale as 'en' | 'de'); if (!post) { return { title: 'Post not found', }; } const site = getSiteInfo(); // Get featured image URL if available let featuredImageUrl: string | undefined; if (post.featuredImage) { const media = getMediaById(post.featuredImage); if (media) { featuredImageUrl = media.localPath; } } return { title: `${post.title} | ${site.title}`, description: post.excerptHtml || undefined, alternates: { canonical: getLocalizedPath(`/blog/${post.slug}`, locale as 'en' | 'de'), languages: { 'en': `/en/blog/${post.slug}`, 'de': `/de/blog/${post.slug}`, }, }, openGraph: { title: post.title, description: post.excerptHtml || undefined, type: 'article', locale, publishedTime: post.datePublished, modifiedTime: post.updatedAt, ...(featuredImageUrl && { images: [{ url: featuredImageUrl, alt: post.title }], }), }, }; } export async function generateStaticParams() { const postsEN = getPostsByLocale('en'); const postsDE = getPostsByLocale('de'); const enParams = postsEN.map((post: any) => ({ slug: post.slug, locale: 'en', })); const deParams = postsDE.map((post: any) => ({ slug: post.slug, locale: 'de', })); return [...enParams, ...deParams]; } export default async function BlogDetailPage({ params }: PageProps) { const locale = (params.locale as string) || 'en'; const post = getPostBySlug(params.slug, locale as 'en' | 'de'); if (!post) { notFound(); } // Process HTML content with WordPress compatibility const processedContent = processHTML(post.contentHtml); return ( <>
{/* Back to blog link */}
{t('blog.backToBlog', locale as 'en' | 'de')}
{/* Article Header */}

{post.title}

{post.excerptHtml && (

{post.excerptHtml}

)}
{/* Featured Image */} {post.featuredImage && (() => { const media = getMediaById(post.featuredImage); return media ? (
{post.title}
) : null; })()} {/* Article Content */}
{/* Article Footer */}
{t('blog.backToList', locale as 'en' | 'de')} {t('nav.contact', locale as 'en' | 'de')}
{/* Related Posts */}
{/* Locale Switcher */}
); }