This commit is contained in:
2026-01-17 16:40:41 +01:00
parent 0f3eecbc48
commit 013049e631
7 changed files with 502 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import Image from 'next/image';
import { getTranslations } from 'next-intl/server';
import { Section, Container, Heading, Badge, Button } from '@/components/ui';
import Scribble from '@/components/Scribble';
import { Metadata } from 'next';
interface ProductPageProps {
params: {
@@ -18,6 +19,49 @@ interface ProductPageProps {
};
}
export async function generateMetadata({ params }: ProductPageProps): Promise<Metadata> {
const { locale, slug } = params;
const productSlug = slug[slug.length - 1];
const t = await getTranslations('Products');
// Check if it's a category page
const categories = ['low-voltage-cables', 'medium-voltage-cables', 'high-voltage-cables', 'solar-cables'];
if (categories.includes(productSlug)) {
const categoryKey = productSlug.replace(/-cables$/, '').replace(/-([a-z])/g, (g) => g[1].toUpperCase());
const categoryTitle = t(`categories.${categoryKey}.title`);
const categoryDesc = t(`categories.${categoryKey}.description`);
return {
title: categoryTitle,
description: categoryDesc,
openGraph: {
title: categoryTitle,
description: categoryDesc,
url: `https://klz-cables.com/${locale}/products/${productSlug}`,
}
};
}
const product = await getProductBySlug(productSlug, locale);
if (!product) return {};
return {
title: product.frontmatter.title,
description: product.frontmatter.description,
openGraph: {
title: product.frontmatter.title,
description: product.frontmatter.description,
type: 'website',
url: `https://klz-cables.com/${locale}/products/${slug.join('/')}`,
},
twitter: {
card: 'summary_large_image',
title: product.frontmatter.title,
description: product.frontmatter.description,
},
};
}
const components = {
ProductTechnicalData,
ProductTabs,
@@ -223,6 +267,31 @@ export default async function ProductPage({ params }: ProductPageProps) {
<div className="prose prose-lg md:prose-xl prose-slate max-w-none prose-headings:text-primary prose-headings:font-extrabold prose-a:text-primary prose-strong:text-primary prose-img:rounded-3xl prose-img:shadow-2xl">
<MDXRemote source={product.content} components={components} />
</div>
{/* Structured Data */}
<script
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify({
'@context': 'https://schema.org',
'@type': 'Product',
name: product.frontmatter.title,
description: product.frontmatter.description,
sku: product.frontmatter.sku,
image: product.frontmatter.images?.[0] ? `https://klz-cables.com${product.frontmatter.images[0]}` : undefined,
brand: {
'@type': 'Brand',
name: 'KLZ Cables',
},
offers: {
'@type': 'Offer',
availability: 'https://schema.org/InStock',
priceCurrency: 'EUR',
url: `https://klz-cables.com/${locale}/products/${slug.join('/')}`,
},
}),
}}
/>
{/* Related Products */}
<RelatedProducts