initial migration

This commit is contained in:
2025-12-28 23:28:31 +01:00
parent 1f99781458
commit 292975299d
284 changed files with 119466 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
import { NextRequest, NextResponse } from 'next/server';
import { Resend } from 'resend';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { name, email, message, locale } = body;
// Validate required fields
if (!name || !email || !message) {
return NextResponse.json(
{ error: 'Missing required fields' },
{ status: 400 }
);
}
// Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
return NextResponse.json(
{ error: 'Invalid email format' },
{ status: 400 }
);
}
// Check if Resend API key is configured
if (!process.env.RESEND_API_KEY) {
return NextResponse.json(
{ error: 'Email service not configured' },
{ status: 500 }
);
}
const resend = new Resend(process.env.RESEND_API_KEY);
// Send email via Resend
const { data, error } = await resend.emails.send({
from: 'KLZ Cables <contact@klz-cables.com>',
to: ['info@klz-cables.com'],
subject: locale === 'de' ? 'Neue Kontaktanfrage' : 'New Contact Inquiry',
html: `
<h2>${locale === 'de' ? 'Neue Kontaktanfrage' : 'New Contact Inquiry'}</h2>
<p><strong>${locale === 'de' ? 'Name' : 'Name'}:</strong> ${name}</p>
<p><strong>${locale === 'de' ? 'E-Mail' : 'Email'}:</strong> ${email}</p>
<p><strong>${locale === 'de' ? 'Nachricht' : 'Message'}:</strong></p>
<p>${message}</p>
<hr>
<p><small>${locale === 'de' ? 'Gesendet über' : 'Sent via'} KLZ Cables Website</small></p>
`,
});
if (error) {
console.error('Resend error:', error);
return NextResponse.json(
{ error: 'Failed to send email' },
{ status: 500 }
);
}
return NextResponse.json(
{ success: true, data },
{ status: 200 }
);
} catch (error) {
console.error('Contact API error:', error);
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,252 @@
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';
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 (
<div className="mt-16 border-t border-gray-200 pt-12">
<h2 className="text-2xl font-bold text-gray-900 mb-6">
{t('blog.relatedPosts', locale as 'en' | 'de')}
</h2>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{relatedPosts.map((post: any) => (
<Link
key={post.slug}
href={getLocalizedPath(`/blog/${post.slug}`, locale as 'en' | 'de')}
className="group block bg-white rounded-lg border border-gray-200 overflow-hidden hover:shadow-md transition-all"
>
{post.featuredImage && (() => {
const media = getMediaById(post.featuredImage);
return media ? (
<div className="h-40 bg-gray-100 overflow-hidden">
<img
src={media.localPath}
alt={post.title}
className="h-full w-full object-cover group-hover:scale-105 transition-transform duration-200"
loading="lazy"
/>
</div>
) : null;
})()}
<div className="p-4">
<h3 className="font-semibold text-gray-900 group-hover:text-blue-600 transition-colors mb-2 line-clamp-2">
{post.title}
</h3>
<p className="text-sm text-gray-600 line-clamp-2 mb-2">
{post.excerptHtml}
</p>
<span className="text-xs text-blue-600 font-medium">
{t('blog.readMore', locale as 'en' | 'de')}
</span>
</div>
</Link>
))}
</div>
</div>
);
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
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 (
<>
<SEO
title={post.title}
description={post.excerptHtml}
locale={locale as 'en' | 'de'}
path={`/blog/${post.slug}`}
type="article"
publishedTime={post.datePublished}
modifiedTime={post.updatedAt}
images={post.featuredImage ? [getMediaById(post.featuredImage)?.localPath].filter(Boolean) : undefined}
/>
<article className="bg-white py-12 sm:py-20">
<div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
{/* Back to blog link */}
<div className="mb-8">
<Link
href={getLocalizedPath('/blog', locale as 'en' | 'de')}
className="inline-flex items-center text-sm text-gray-600 hover:text-gray-900 transition-colors"
>
<svg className="mr-2 h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 19l-7-7 7-7" />
</svg>
{t('blog.backToBlog', locale as 'en' | 'de')}
</Link>
</div>
{/* Article Header */}
<header className="mb-10">
<div className="flex items-center gap-2 mb-4">
<time className="text-sm text-gray-500">
{new Date(post.datePublished).toLocaleDateString(locale as 'en' | 'de', {
year: 'numeric',
month: 'long',
day: 'numeric',
})}
</time>
</div>
<h1 className="text-4xl sm:text-5xl font-bold text-gray-900 mb-6 leading-tight">
{post.title}
</h1>
{post.excerptHtml && (
<p className="text-xl text-gray-600 leading-relaxed">
{post.excerptHtml}
</p>
)}
</header>
{/* Featured Image */}
{post.featuredImage && (() => {
const media = getMediaById(post.featuredImage);
return media ? (
<div className="mb-12 rounded-2xl overflow-hidden bg-gray-100">
<img
src={media.localPath}
alt={post.title}
className="w-full h-auto object-cover"
loading="eager"
/>
</div>
) : null;
})()}
{/* Article Content */}
<div
className="prose prose-lg prose-blue max-w-none mb-12"
dangerouslySetInnerHTML={{ __html: processedContent }}
/>
{/* Article Footer */}
<footer className="border-t border-gray-200 pt-8 mt-12">
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
<div className="flex gap-4">
<Link
href={getLocalizedPath('/blog', locale as 'en' | 'de')}
className="inline-flex items-center px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 transition-colors"
>
{t('blog.backToList', locale as 'en' | 'de')}
</Link>
<Link
href={getLocalizedPath('/contact', locale as 'en' | 'de')}
className="inline-flex items-center px-4 py-2 border border-transparent rounded-md text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 transition-colors"
>
{t('nav.contact', locale as 'en' | 'de')}
</Link>
</div>
</div>
</footer>
{/* Related Posts */}
<RelatedPosts currentSlug={params.slug} locale={locale as 'en' | 'de'} />
</div>
</article>
{/* Locale Switcher */}
<div className="bg-gray-50 py-8">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
<LocaleSwitcher />
</div>
</div>
</>
);
}

257
app/[locale]/blog/page.tsx Normal file
View File

@@ -0,0 +1,257 @@
import { Metadata } from 'next';
import Link from 'next/link';
import { getPostsByLocale, getCategoriesByLocale, getMediaById } from '@/lib/data';
import { getSiteInfo, t, getLocalizedPath } from '@/lib/i18n';
import { SEO } from '@/components/SEO';
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
import { processHTML } from '@/lib/html-compat';
interface PageProps {
params: {
locale?: string;
};
}
export async function generateStaticParams() {
return [
{ locale: 'en' },
{ locale: 'de' },
];
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const locale = (params?.locale as string) || 'en';
const site = getSiteInfo();
const title = t('blog.title', locale as 'en' | 'de');
const description = t('blog.description', locale as 'en' | 'de');
return {
title: `${title} | ${site.title}`,
description,
alternates: {
canonical: getLocalizedPath('/blog', locale as 'en' | 'de'),
languages: {
'en': '/en/blog',
'de': '/de/blog',
},
},
openGraph: {
title: `${title} | ${site.title}`,
description,
type: 'website',
locale,
},
};
}
export default async function BlogPage({ params }: PageProps) {
const locale = (params?.locale as string) || 'en';
const posts = getPostsByLocale(locale as 'en' | 'de');
const categories = getCategoriesByLocale(locale as 'en' | 'de');
const title = t('blog.title', locale as 'en' | 'de');
const description = t('blog.description', locale as 'en' | 'de');
// Get featured posts (first 3)
const featuredPosts = posts.slice(0, 3);
// Get remaining posts
const remainingPosts = posts.slice(3);
return (
<>
<SEO
title={title}
description={description}
locale={locale as 'en' | 'de'}
path="/blog"
/>
<div className="bg-white py-24 sm:py-32">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="max-w-2xl">
<h1 className="text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl mb-6">
{title}
</h1>
<p className="text-xl text-gray-600 mb-8">
{description}
</p>
</div>
{/* Categories */}
{categories.length > 0 && (
<div className="mb-12">
<h2 className="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">
{t('blog.categories', locale as 'en' | 'de')}
</h2>
<div className="flex flex-wrap gap-2">
{categories.map((category) => (
<Link
key={category.slug}
href={getLocalizedPath(`/blog/category/${category.slug}`, locale as 'en' | 'de')}
className="inline-flex items-center px-3 py-1.5 rounded-full text-sm font-medium bg-blue-50 text-blue-700 hover:bg-blue-100 transition-colors"
>
{category.name}
</Link>
))}
</div>
</div>
)}
{/* Featured Posts */}
{featuredPosts.length > 0 && (
<div className="mb-16">
<h2 className="text-2xl font-bold text-gray-900 mb-6">
{t('blog.featured', locale as 'en' | 'de')}
</h2>
<div className="grid gap-8 md:grid-cols-2 lg:grid-cols-3">
{featuredPosts.map((post) => (
<article
key={post.slug}
className="flex flex-col bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden hover:shadow-md transition-shadow"
>
{post.featuredImage && (() => {
const media = getMediaById(post.featuredImage);
return media ? (
<div className="h-48 overflow-hidden bg-gray-100">
<img
src={media.localPath}
alt={post.title}
className="h-full w-full object-cover"
loading="lazy"
/>
</div>
) : null;
})()}
<div className="flex-1 p-6">
<div className="flex items-center gap-2 mb-3">
<time className="text-xs text-gray-500">
{new Date(post.datePublished).toLocaleDateString(locale, {
year: 'numeric',
month: 'short',
day: 'numeric',
})}
</time>
</div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">
<Link
href={getLocalizedPath(`/blog/${post.slug}`, locale as 'en' | 'de')}
className="hover:text-blue-600 transition-colors"
>
{post.title}
</Link>
</h3>
<div
className="text-gray-600 line-clamp-3 text-sm mb-4"
dangerouslySetInnerHTML={{ __html: processHTML(post.excerptHtml) }}
/>
<Link
href={getLocalizedPath(`/blog/${post.slug}`, locale as 'en' | 'de')}
className="inline-flex items-center text-sm font-medium text-blue-600 hover:text-blue-700"
>
{t('blog.readMore', locale as 'en' | 'de')}
<svg className="ml-1 h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
</Link>
</div>
</article>
))}
</div>
</div>
)}
{/* All Posts */}
{remainingPosts.length > 0 && (
<div>
<h2 className="text-2xl font-bold text-gray-900 mb-6">
{t('blog.allPosts', locale as 'en' | 'de')}
</h2>
<div className="space-y-8">
{remainingPosts.map((post) => (
<article
key={post.slug}
className="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden hover:shadow-md transition-shadow"
>
<div className="p-6">
<div className="flex items-center gap-2 mb-3">
<time className="text-xs text-gray-500">
{new Date(post.datePublished).toLocaleDateString(locale, {
year: 'numeric',
month: 'short',
day: 'numeric',
})}
</time>
</div>
<div className="flex gap-6">
{post.featuredImage && (() => {
const media = getMediaById(post.featuredImage);
return media ? (
<div className="w-32 h-32 flex-shrink-0 bg-gray-100 rounded-lg overflow-hidden">
<img
src={media.localPath}
alt={post.title}
className="h-full w-full object-cover"
loading="lazy"
/>
</div>
) : null;
})()}
<div className="flex-1">
<h3 className="text-xl font-semibold text-gray-900 mb-2">
<Link
href={getLocalizedPath(`/blog/${post.slug}`, locale as 'en' | 'de')}
className="hover:text-blue-600 transition-colors"
>
{post.title}
</Link>
</h3>
<div
className="text-gray-600 mb-3"
dangerouslySetInnerHTML={{ __html: processHTML(post.excerptHtml) }}
/>
<Link
href={getLocalizedPath(`/blog/${post.slug}`, locale as 'en' | 'de')}
className="inline-flex items-center text-sm font-medium text-blue-600 hover:text-blue-700"
>
{t('blog.readMore', locale as 'en' | 'de')}
<svg className="ml-1 h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
</svg>
</Link>
</div>
</div>
</div>
</article>
))}
</div>
</div>
)}
{/* Empty State */}
{posts.length === 0 && (
<div className="text-center py-16">
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-gray-100 mb-4">
<svg className="w-8 h-8 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
</div>
<h3 className="text-lg font-semibold text-gray-900 mb-2">
{t('blog.noPosts', locale as 'en' | 'de')}
</h3>
<p className="text-gray-600">
{t('blog.noPostsDescription', locale as 'en' | 'de')}
</p>
</div>
)}
</div>
</div>
{/* Locale Switcher */}
<div className="bg-gray-50 py-8">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
<LocaleSwitcher />
</div>
</div>
</>
);
}

48
app/[locale]/layout.tsx Normal file
View File

@@ -0,0 +1,48 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import '../globals.scss';
import { Navigation } from '@/components/Navigation';
import { CookieConsent } from '@/components/CookieConsent';
const inter = Inter({
subsets: ['latin', 'latin-ext'],
display: 'swap',
});
export const metadata: Metadata = {
title: 'KLZ Cables',
description: 'Professional cable solutions for industrial applications',
metadataBase: new URL('https://klz-cables.com'),
alternates: {
canonical: '/',
languages: {
'en': '/en',
'de': '/de',
},
},
openGraph: {
title: 'KLZ Cables',
description: 'Professional cable solutions for industrial applications',
type: 'website',
locale: 'en',
siteName: 'KLZ Cables',
},
};
export default function LocaleLayout({
children,
params: { locale },
}: {
children: React.ReactNode;
params: { locale: string };
}) {
return (
<>
<Navigation siteName="KLZ Cables" locale={locale} />
<main className="min-h-screen">
{children}
</main>
<CookieConsent />
</>
);
}

173
app/[locale]/page.tsx Normal file
View File

@@ -0,0 +1,173 @@
import { notFound } from 'next/navigation';
import { getPageBySlug, getAllPages, getMediaById } from '@/lib/data';
import { Metadata } from 'next';
import { SEO } from '@/components/SEO';
import { processHTML } from '@/lib/html-compat';
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
import Link from 'next/link';
interface PageProps {
params: {
locale: string;
slug?: string;
};
}
export async function generateStaticParams() {
const pages = await getAllPages();
const params = pages.map((page) => ({
locale: page.locale,
slug: page.slug,
}));
return params;
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const { locale, slug = 'home' } = params;
// Map root path to actual home page slugs
const homeSlugs: Record<string, string> = {
'en': 'corporate-3-landing-2',
'de': 'start'
};
const actualSlug = slug === 'home' ? homeSlugs[locale] || 'home' : slug;
const page = await getPageBySlug(actualSlug, locale);
if (!page) {
return {
title: 'Page Not Found',
};
}
return {
title: page.title,
description: page.excerptHtml || '',
alternates: {
languages: {
de: slug === 'home' ? '/de' : `/de/${slug}`,
en: slug === 'home' ? '/en' : `/en/${slug}`,
},
},
};
}
export default async function Page({ params }: PageProps) {
const { locale, slug = 'home' } = params;
// Map root path to actual home page slugs
const homeSlugs: Record<string, string> = {
'en': 'corporate-3-landing-2',
'de': 'start'
};
const actualSlug = slug === 'home' ? homeSlugs[locale] || 'home' : slug;
const page = await getPageBySlug(actualSlug, locale);
if (!page) {
notFound();
}
// Use contentHtml if available, otherwise use excerptHtml
const contentToDisplay = page.contentHtml && page.contentHtml.trim() !== ''
? page.contentHtml
: page.excerptHtml;
const processedContent = processHTML(contentToDisplay || '');
// Get featured image if available
const featuredImage = page.featuredImage ? getMediaById(page.featuredImage) : null;
return (
<>
<SEO
title={page.title}
description={page.excerptHtml || ''}
/>
{/* Hero Section with Featured Image */}
{featuredImage && (
<div className="relative h-64 md:h-96 bg-gray-200">
<img
src={featuredImage.localPath}
alt={page.title}
className="w-full h-full object-cover"
/>
<div className="absolute inset-0 bg-black bg-opacity-40"></div>
<div className="absolute inset-0 flex items-center justify-center text-center">
<h1 className="text-4xl md:text-6xl font-bold text-white drop-shadow-lg">
{page.title}
</h1>
</div>
</div>
)}
{/* Main Content */}
<main className="container mx-auto px-4 py-8">
{!featuredImage && (
<div className="max-w-4xl mx-auto mb-8">
<h1 className="text-4xl font-bold text-gray-900 mb-4">
{page.title}
</h1>
{page.excerptHtml && (
<div
className="text-xl text-gray-600 leading-relaxed"
dangerouslySetInnerHTML={{ __html: processHTML(page.excerptHtml) }}
/>
)}
</div>
)}
{processedContent && (
<div className="max-w-4xl mx-auto bg-white rounded-lg shadow-sm p-8">
<div
className="prose prose-lg max-w-none"
dangerouslySetInnerHTML={{ __html: processedContent }}
/>
</div>
)}
{/* Navigation Links */}
<div className="max-w-4xl mx-auto mt-12">
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<Link
href={`/${locale}/blog`}
className="p-4 bg-blue-50 hover:bg-blue-100 rounded-lg text-center transition-colors"
>
<div className="font-semibold text-blue-900">Blog</div>
<div className="text-sm text-blue-700">Read our latest posts</div>
</Link>
<Link
href={`/${locale}/products`}
className="p-4 bg-green-50 hover:bg-green-100 rounded-lg text-center transition-colors"
>
<div className="font-semibold text-green-900">Products</div>
<div className="text-sm text-green-700">Browse our catalog</div>
</Link>
<Link
href={`/${locale}/contact`}
className="p-4 bg-orange-50 hover:bg-orange-100 rounded-lg text-center transition-colors"
>
<div className="font-semibold text-orange-900">Contact</div>
<div className="text-sm text-orange-700">Get in touch</div>
</Link>
<Link
href={`/${locale}/blog`}
className="p-4 bg-purple-50 hover:bg-purple-100 rounded-lg text-center transition-colors"
>
<div className="font-semibold text-purple-900">News</div>
<div className="text-sm text-purple-700">Latest updates</div>
</Link>
</div>
</div>
</main>
{/* Locale Switcher */}
<div className="bg-gray-50 py-8">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
<LocaleSwitcher />
</div>
</div>
</>
);
}

View File

@@ -0,0 +1,64 @@
import { notFound } from 'next/navigation'
import { getAllCategories, getProductsByCategory } from '@/lib/data'
import { ProductList } from '@/components/ProductList'
import { Metadata } from 'next'
interface PageProps {
params: {
locale: string
slug: string
}
}
export async function generateStaticParams() {
const categories = getAllCategories()
return categories.map((category) => ({
locale: 'de', // Default locale
slug: category.slug
}))
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const categories = getAllCategories()
const category = categories.find((cat) => cat.slug === params.slug)
if (!category) {
return {
title: 'Category Not Found'
}
}
return {
title: category.name,
description: category.description || `Products in ${category.name}`
}
}
export default async function ProductCategoryPage({ params }: PageProps) {
const categories = getAllCategories()
const category = categories.find((cat) => cat.slug === params.slug)
if (!category) {
notFound()
}
const products = getProductsByCategory(category.id, params.locale)
return (
<div className="container mx-auto px-4 py-8">
<h1 className="text-4xl font-bold mb-6">{category.name}</h1>
{category.description && (
<div
className="mb-8 prose max-w-none"
dangerouslySetInnerHTML={{ __html: category.description }}
/>
)}
{products.length > 0 ? (
<ProductList products={products} />
) : (
<p className="text-gray-500">No products found in this category.</p>
)}
</div>
)
}

View File

@@ -0,0 +1,278 @@
import { Metadata } from 'next';
import Link from 'next/link';
import { notFound } from 'next/navigation';
import { getProductBySlug, getAllProducts, getCategoriesByLocale } from '@/lib/data';
import { getSiteInfo, t, getLocaleFromPath, getLocalizedPath } from '@/lib/i18n';
import { processHTML } from '@/lib/html-compat';
import { SEO } from '@/components/SEO';
import { LocaleSwitcher } from '@/components/LocaleSwitcher';
interface PageProps {
params: {
slug: string;
locale?: string;
};
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
const locale = (params.locale as string) || 'en';
const product = getProductBySlug(params.slug, locale as 'en' | 'de');
if (!product) {
return {
title: 'Product not found',
};
}
const site = getSiteInfo();
return {
title: `${product.name} | ${site.title}`,
description: product.shortDescriptionHtml || product.descriptionHtml.substring(0, 160) || '',
alternates: {
canonical: getLocalizedPath(`/product/${product.slug}`, locale as 'en' | 'de'),
languages: {
'en': `/en/product/${product.slug}`,
'de': `/de/product/${product.slug}`,
},
},
openGraph: {
title: product.name,
description: product.shortDescriptionHtml || product.descriptionHtml.substring(0, 160) || '',
type: 'website',
locale,
...(product.images && product.images.length > 0 && {
images: product.images.map(img => ({ url: img, alt: product.name })),
}),
},
};
}
export async function generateStaticParams() {
const productsEN = getAllProducts();
const productsDE = getAllProducts();
const enParams = productsEN.filter(p => p.locale === 'en').map((product) => ({
slug: product.slug,
locale: 'en',
}));
const deParams = productsDE.filter(p => p.locale === 'de').map((product) => ({
slug: product.slug,
locale: 'de',
}));
return [...enParams, ...deParams];
}
export default async function ProductDetailPage({ params }: PageProps) {
const locale = (params.locale as string) || 'en';
const product = getProductBySlug(params.slug, locale as 'en' | 'de');
if (!product) {
notFound();
}
// Process description HTML with WordPress compatibility
const processedDescription = product.descriptionHtml ?
processHTML(product.descriptionHtml) : '';
// Get related products (same category)
const allProducts = getAllProducts();
const relatedProducts = allProducts
.filter((p: any) =>
p.locale === locale &&
p.slug !== product.slug &&
p.categories?.some((cat: any) => product.categories?.some((pc: any) => pc.slug === cat.slug))
)
.slice(0, 4);
return (
<>
<SEO
title={product.name}
description={product.shortDescriptionHtml || product.descriptionHtml.substring(0, 160) || ''}
locale={locale as 'en' | 'de'}
path={`/product/${product.slug}`}
type="product"
images={product.images}
/>
<div className="bg-white py-12 sm:py-20">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
{/* Back to products link */}
<div className="mb-8">
<Link
href={getLocalizedPath('/products', locale as 'en' | 'de')}
className="inline-flex items-center text-sm text-gray-600 hover:text-gray-900 transition-colors"
>
<svg className="mr-2 h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 19l-7-7 7-7" />
</svg>
{t('products.backToProducts', locale as 'en' | 'de')}
</Link>
</div>
<div className="lg:grid lg:grid-cols-2 lg:gap-x-12 lg:items-start">
{/* Product Images */}
<div className="flex flex-col-reverse">
{product.images && product.images.length > 0 ? (
<>
<div className="hidden lg:grid lg:grid-cols-1 lg:gap-4 mt-4">
{product.images.map((img: string, index: number) => (
<div key={index} className="aspect-square overflow-hidden rounded-lg bg-gray-100">
<img
src={img}
alt={`${product.name} - ${index + 1}`}
className="h-full w-full object-cover object-center"
loading={index === 0 ? 'eager' : 'lazy'}
/>
</div>
))}
</div>
<div className="lg:hidden aspect-square overflow-hidden rounded-lg bg-gray-100 mb-4">
<img
src={product.images[0]}
alt={product.name}
className="h-full w-full object-cover object-center"
loading="eager"
/>
</div>
</>
) : (
<div className="aspect-square overflow-hidden rounded-lg bg-gray-100 flex items-center justify-center">
<svg className="h-24 w-24 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
</div>
)}
</div>
{/* Product Info */}
<div className="mt-10 px-4 sm:px-0 sm:mt-16 lg:mt-0">
{/* Categories */}
{product.categories && product.categories.length > 0 && (
<div className="flex flex-wrap gap-2 mb-4">
{product.categories.map((cat: any) => (
<Link
key={cat.slug}
href={getLocalizedPath(`/product-category/${cat.slug}`, locale as 'en' | 'de')}
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-700 hover:bg-blue-100 transition-colors"
>
{cat.name}
</Link>
))}
</div>
)}
<h1 className="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl mb-4">
{product.name}
</h1>
{product.sku && (
<p className="text-sm text-gray-500 mb-4">
{t('products.sku', locale as 'en' | 'de')}: {product.sku}
</p>
)}
{product.shortDescriptionHtml && (
<p className="text-lg text-gray-600 mb-6">
{product.shortDescriptionHtml}
</p>
)}
{/* Product Description */}
{processedDescription && (
<div className="border-t border-gray-200 pt-6 mb-8">
<h3 className="text-sm font-medium text-gray-900 mb-3">
{t('products.description', locale as 'en' | 'de')}
</h3>
<div
className="prose prose-sm max-w-none text-gray-600"
dangerouslySetInnerHTML={{ __html: processedDescription }}
/>
</div>
)}
{/* Actions */}
<div className="border-t border-gray-200 pt-6">
<div className="flex flex-col sm:flex-row gap-4">
<Link
href={getLocalizedPath('/contact', locale as 'en' | 'de')}
className="flex-1 inline-flex justify-center items-center px-6 py-3 border border-transparent text-base font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 transition-colors shadow-sm"
>
{t('products.inquire', locale as 'en' | 'de')}
<svg className="ml-2 h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
</svg>
</Link>
<Link
href={getLocalizedPath('/products', locale as 'en' | 'de')}
className="flex-1 inline-flex justify-center items-center px-6 py-3 border border-gray-300 text-base font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 transition-colors"
>
{t('products.backToProducts', locale as 'en' | 'de')}
</Link>
</div>
</div>
</div>
</div>
{/* Related Products */}
{relatedProducts.length > 0 && (
<div className="mt-20 border-t border-gray-200 pt-12">
<h2 className="text-2xl font-bold text-gray-900 mb-6">
{t('products.relatedProducts', locale as 'en' | 'de')}
</h2>
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-4">
{relatedProducts.map((relatedProduct: any) => (
<Link
key={relatedProduct.slug}
href={getLocalizedPath(`/product/${relatedProduct.slug}`, locale as 'en' | 'de')}
className="group block bg-white rounded-lg border border-gray-200 overflow-hidden hover:shadow-md transition-all"
>
{relatedProduct.images && relatedProduct.images.length > 0 ? (
<div className="aspect-square bg-gray-100 overflow-hidden">
<img
src={relatedProduct.images[0]}
alt={relatedProduct.name}
className="h-full w-full object-cover group-hover:scale-105 transition-transform duration-200"
loading="lazy"
/>
</div>
) : (
<div className="aspect-square bg-gray-100 flex items-center justify-center">
<svg className="h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
</div>
)}
<div className="p-4">
<h3 className="font-semibold text-gray-900 group-hover:text-blue-600 transition-colors mb-1 line-clamp-2">
{relatedProduct.name}
</h3>
{relatedProduct.shortDescriptionHtml && (
<p className="text-sm text-gray-600 line-clamp-2 mb-2">
{relatedProduct.shortDescriptionHtml}
</p>
)}
<span className="text-xs text-blue-600 font-medium">
{t('products.viewDetails', locale as 'en' | 'de')}
</span>
</div>
</Link>
))}
</div>
</div>
)}
</div>
</div>
{/* Locale Switcher */}
<div className="bg-gray-50 py-8">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
<LocaleSwitcher />
</div>
</div>
</>
);
}

View File

@@ -0,0 +1,61 @@
import { Metadata } from 'next'
import { t } from '@/lib/i18n'
import { ProductList } from '@/components/ProductList'
import { getAllProducts } from '@/lib/data'
import { Locale } from '@/lib/i18n'
import Link from 'next/link'
interface PageProps {
params: {
locale: Locale
}
}
export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
return {
title: t('products.title', params.locale),
description: t('products.description', params.locale),
}
}
export default async function ProductsPage({ params }: PageProps) {
const products = getAllProducts()
// Get unique categories for this locale
const categories = Array.from(
new Set(products
.filter(p => p.locale === params.locale)
.flatMap(p => p.categories || [])
.map(c => c.slug)
)
)
return (
<div className="container mx-auto px-4 py-8">
<h1 className="text-4xl font-bold mb-8">{t('products.title', params.locale)}</h1>
{categories.length > 0 && (
<div className="mb-8">
<h2 className="text-xl font-semibold mb-4">{t('products.categories', params.locale)}</h2>
<div className="flex flex-wrap gap-2">
{categories.map((category) => (
<Link
key={category}
href={`/${params.locale}/product-category/${category}`}
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
>
{category}
</Link>
))}
</div>
</div>
)}
{products.filter(p => p.locale === params.locale).length > 0 ? (
<ProductList products={products.filter(p => p.locale === params.locale)} />
) : (
<p className="text-gray-600">{t('products.noProducts', params.locale)}</p>
)}
</div>
)
}

461
app/globals.scss Normal file
View File

@@ -0,0 +1,461 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
/* Global Styles */
:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}
body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}
/* Navigation Styles */
.navbar {
background: #fff;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 1rem 0;
position: sticky;
top: 0;
z-index: 100;
}
.nav-container {
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-logo {
font-size: 1.5rem;
font-weight: bold;
color: #0070f3;
text-decoration: none;
}
.nav-menu {
display: flex;
gap: 1.5rem;
align-items: center;
}
.nav-link {
color: #333;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
}
.nav-link:hover {
color: #0070f3;
}
/* Contact Form Styles */
.contact-form {
max-width: 600px;
margin: 2rem auto;
padding: 2rem;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.form-group {
margin-bottom: 1rem;
}
.form-group label {
display: block;
margin-bottom: 0.5rem;
font-weight: 500;
color: #333;
}
.form-group input,
.form-group textarea {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.form-group textarea {
min-height: 120px;
resize: vertical;
}
.submit-btn {
background: #0070f3;
color: white;
padding: 0.75rem 1.5rem;
border: none;
border-radius: 4px;
font-size: 1rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
}
.submit-btn:hover {
background: #0051cc;
}
.submit-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.form-message {
margin-top: 1rem;
padding: 0.75rem;
border-radius: 4px;
}
.form-message.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.form-message.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
/* Cookie Consent Styles */
.cookie-consent {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #fff;
box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
padding: 1rem;
z-index: 1000;
}
.cookie-consent-content {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.cookie-consent-text {
flex: 1;
color: #333;
}
.cookie-consent-buttons {
display: flex;
gap: 0.5rem;
}
.cookie-btn {
padding: 0.5rem 1rem;
border: none;
border-radius: 4px;
font-weight: 500;
cursor: pointer;
transition: background 0.2s;
}
.cookie-btn.accept {
background: #0070f3;
color: white;
}
.cookie-btn.accept:hover {
background: #0051cc;
}
.cookie-btn.reject {
background: #e0e0e0;
color: #333;
}
.cookie-btn.reject:hover {
background: #d0d0d0;
}
/* Product List Styles */
.product-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 2rem;
margin: 2rem 0;
}
.product-card {
background: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.product-image {
width: 100%;
height: 200px;
object-fit: cover;
background: #f0f0f0;
}
.product-content {
padding: 1rem;
}
.product-title {
font-size: 1.125rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: #111;
}
.product-excerpt {
font-size: 0.875rem;
color: #666;
line-height: 1.5;
margin-bottom: 0.75rem;
}
.product-meta {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.875rem;
color: #999;
}
.product-price {
font-weight: 600;
color: #0070f3;
}
/* SEO Component Styles */
.site-seo {
margin-bottom: 2rem;
}
/* Locale Switcher Styles */
.locale-switcher {
display: flex;
gap: 0.5rem;
align-items: center;
}
.locale-btn {
padding: 0.5rem 0.75rem;
border: 1px solid #ddd;
background: white;
border-radius: 4px;
cursor: pointer;
font-weight: 500;
transition: all 0.2s;
}
.locale-btn:hover {
border-color: #0070f3;
color: #0070f3;
}
.locale-btn.active {
background: #0070f3;
color: white;
border-color: #0070f3;
}
/* Page Layout */
.page-container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem 1rem;
}
.page-header {
margin-bottom: 2rem;
}
.page-title {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
color: #111;
}
.page-subtitle {
font-size: 1.125rem;
color: #666;
line-height: 1.6;
}
/* Blog Styles */
.blog-grid {
display: grid;
gap: 2rem;
margin: 2rem 0;
}
.blog-card {
background: #fff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: transform 0.2s;
}
.blog-card:hover {
transform: translateX(4px);
}
.blog-card-content {
padding: 1.5rem;
}
.blog-card-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 0.5rem;
color: #111;
}
.blog-card-excerpt {
color: #666;
line-height: 1.6;
margin-bottom: 1rem;
}
.blog-card-meta {
font-size: 0.875rem;
color: #999;
}
/* Content Styles */
.content {
background: #fff;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.content h1,
.content h2,
.content h3,
.content h4 {
margin-top: 1.5rem;
margin-bottom: 1rem;
color: #111;
}
.content p {
margin-bottom: 1rem;
line-height: 1.7;
color: #333;
}
.content a {
color: #0070f3;
text-decoration: underline;
}
.content ul,
.content ol {
margin-bottom: 1rem;
padding-left: 1.5rem;
}
.content li {
margin-bottom: 0.5rem;
}
.content img {
max-width: 100%;
height: auto;
border-radius: 4px;
margin: 1rem 0;
}
/* Loading States */
.loading {
text-align: center;
padding: 2rem;
color: #666;
}
/* Error States */
.error-message {
background: #f8d7da;
color: #721c24;
padding: 1rem;
border-radius: 4px;
border: 1px solid #f5c6cb;
margin: 1rem 0;
}
/* Utility Classes */
.text-center {
text-align: center;
}
.mt-2 {
margin-top: 1rem;
}
.mb-2 {
margin-bottom: 1rem;
}
.grid {
display: grid;
gap: 1rem;
}
.grid-2 {
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
/* Responsive */
@media (max-width: 768px) {
.cookie-consent-content {
flex-direction: column;
align-items: flex-start;
}
.nav-menu {
gap: 1rem;
}
.page-title {
font-size: 2rem;
}
.product-grid {
grid-template-columns: 1fr;
gap: 1rem;
}
.blog-card:hover {
transform: none;
}
}

42
app/layout.tsx Normal file
View File

@@ -0,0 +1,42 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.scss';
const inter = Inter({
subsets: ['latin', 'latin-ext'],
display: 'swap',
});
export const metadata: Metadata = {
title: 'KLZ Cables',
description: 'Professional cable solutions for industrial applications',
metadataBase: new URL('https://klz-cables.com'),
alternates: {
canonical: '/',
languages: {
'en': '/en',
'de': '/de',
},
},
openGraph: {
title: 'KLZ Cables',
description: 'Professional cable solutions for industrial applications',
type: 'website',
locale: 'en',
siteName: 'KLZ Cables',
},
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html>
<body className={inter.className}>
{children}
</body>
</html>
);
}

6
app/page.tsx Normal file
View File

@@ -0,0 +1,6 @@
import { redirect } from 'next/navigation';
export default function RootPage() {
// Redirect root path to default locale
redirect('/en');
}

21
app/robots.ts Normal file
View File

@@ -0,0 +1,21 @@
import { MetadataRoute } from 'next';
export default function robots(): MetadataRoute.Robots {
const baseUrl = process.env.SITE_URL || 'https://klz-cables.com';
return {
rules: {
userAgent: '*',
allow: '/',
disallow: [
'/api/',
'/admin/',
'/private/',
'/wp-admin/',
'/wp-content/',
'/wp-includes/',
],
},
sitemap: `${baseUrl}/sitemap.xml`,
};
}

77
app/sitemap.ts Normal file
View File

@@ -0,0 +1,77 @@
import { MetadataRoute } from 'next';
import { getAllPages, getAllPosts, getAllProducts, getAllCategories } from '../lib/data';
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const baseUrl = process.env.SITE_URL || 'https://klz-cables.com';
const urls: MetadataRoute.Sitemap = [];
// Add homepage
urls.push({
url: baseUrl,
lastModified: new Date(),
changeFrequency: 'daily',
priority: 1,
});
// Add all pages
try {
const pages = await getAllPages();
pages.forEach(page => {
urls.push({
url: `${baseUrl}/${page.slug}`,
lastModified: new Date(page.updatedAt || Date.now()),
changeFrequency: 'weekly',
priority: 0.8,
});
});
} catch (error) {
console.warn('Could not fetch pages for sitemap:', error);
}
// Add blog posts
try {
const posts = await getAllPosts();
posts.forEach(post => {
urls.push({
url: `${baseUrl}/blog/${post.slug}`,
lastModified: new Date(post.updatedAt || Date.now()),
changeFrequency: 'weekly',
priority: 0.6,
});
});
} catch (error) {
console.warn('Could not fetch posts for sitemap:', error);
}
// Add products
try {
const products = await getAllProducts();
products.forEach(product => {
urls.push({
url: `${baseUrl}/product/${product.slug}`,
lastModified: new Date(product.updatedAt || Date.now()),
changeFrequency: 'monthly',
priority: 0.5,
});
});
} catch (error) {
console.warn('Could not fetch products for sitemap:', error);
}
// Add product categories
try {
const categories = await getAllCategories();
categories.forEach(category => {
urls.push({
url: `${baseUrl}/product-category/${category.slug}`,
lastModified: new Date(Date.now()),
changeFrequency: 'monthly',
priority: 0.4,
});
});
} catch (error) {
console.warn('Could not fetch categories for sitemap:', error);
}
return urls;
}