import Link from 'next/link'; import Image from 'next/image'; import { getAllPosts } from '@/lib/blog'; import { Section, Container, Heading, Card, Badge, Button } from '@/components/ui'; import Reveal from '@/components/Reveal'; import { Metadata } from 'next'; import { getTranslations, setRequestLocale } from 'next-intl/server'; import { SITE_URL } from '@/lib/schema'; import { BlogPaginationKeyboardObserver } from '@/components/blog/BlogPaginationKeyboardObserver'; interface BlogIndexProps { params: Promise<{ locale: string; }>; } export async function generateMetadata({ params }: BlogIndexProps) { const { locale } = await params; const t = await getTranslations({ locale, namespace: 'Blog.meta' }); return { title: t('title'), description: t('description'), alternates: { canonical: `${SITE_URL}/${locale}/blog`, languages: { de: `${SITE_URL}/de/blog`, en: `${SITE_URL}/en/blog`, 'x-default': `${SITE_URL}/en/blog`, }, }, openGraph: { title: `${t('title')} | KLZ Cables`, description: t('description'), url: `${SITE_URL}/${locale}/blog`, }, twitter: { card: 'summary_large_image', title: `${t('title')} | KLZ Cables`, description: t('description'), }, }; } export default async function BlogIndex({ params }: BlogIndexProps) { const { locale } = await params; setRequestLocale(locale); const t = await getTranslations('Blog'); const posts = await getAllPosts(locale); // Sort posts by date descending const sortedPosts = [...posts].sort( (a, b) => new Date(b.frontmatter.date).getTime() - new Date(a.frontmatter.date).getTime(), ); const featuredPost = sortedPosts[0]; const remainingPosts = sortedPosts.slice(1); return (
{/* Hero Section - Immersive Magazine Feel */}
{featuredPost && featuredPost.frontmatter.featuredImage && ( <> {featuredPost.frontmatter.title}
)}
{t('featuredPost')} {featuredPost && (new Date(featuredPost.frontmatter.date) > new Date() || featuredPost.frontmatter.public === false) && ( Draft Preview )}
{featuredPost && ( <> {featuredPost.frontmatter.title}

{featuredPost.frontmatter.excerpt}

)}
{t('allArticles')}
{/* Category filters could go here */} {t('categories.all')} {t('categories.industry')} {t('categories.technical')} {t('categories.sustainability')}
{/* Grid for remaining posts */}
{remainingPosts.map((post, idx) => ( {post.frontmatter.featuredImage && (
{post.frontmatter.title}
{post.frontmatter.category && ( {post.frontmatter.category} )}
)}
{new Date(post.frontmatter.date).toLocaleDateString(locale, { year: 'numeric', month: 'long', day: 'numeric', })} {(new Date(post.frontmatter.date) > new Date() || post.frontmatter.public === false) && ( Draft )}

{post.frontmatter.title}

{post.frontmatter.excerpt}

{t('readMore')}
))}
{/* Pagination */}
); }