initial migration
This commit is contained in:
257
components/ContactForm.tsx
Normal file
257
components/ContactForm.tsx
Normal file
@@ -0,0 +1,257 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { getDictionary } from '@/lib/i18n';
|
||||
|
||||
interface FormData {
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
subject: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function ContactForm() {
|
||||
const pathname = usePathname();
|
||||
const locale = pathname.split('/')[1] || 'en';
|
||||
const [dict, setDict] = useState<any>({});
|
||||
const [formData, setFormData] = useState<FormData>({
|
||||
name: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
subject: '',
|
||||
message: '',
|
||||
});
|
||||
|
||||
const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle');
|
||||
const [errors, setErrors] = useState<Partial<FormData>>({});
|
||||
|
||||
// Load dictionary on component mount and when locale changes
|
||||
useEffect(() => {
|
||||
const loadDict = async () => {
|
||||
try {
|
||||
const loadedDict = await getDictionary(locale as 'en' | 'de');
|
||||
setDict(loadedDict);
|
||||
} catch (error) {
|
||||
console.error('Error loading dictionary:', error);
|
||||
// Set empty dictionary to prevent infinite loading
|
||||
setDict({});
|
||||
}
|
||||
};
|
||||
loadDict();
|
||||
}, [locale]);
|
||||
|
||||
const t = (key: string): string => {
|
||||
if (!dict || Object.keys(dict).length === 0) return key;
|
||||
|
||||
const keys = key.split('.');
|
||||
let value: any = dict;
|
||||
|
||||
for (const k of keys) {
|
||||
value = value?.[k];
|
||||
if (value === undefined) return key;
|
||||
}
|
||||
|
||||
return value || key;
|
||||
};
|
||||
|
||||
const validateForm = (): boolean => {
|
||||
const newErrors: Partial<FormData> = {};
|
||||
|
||||
if (!formData.name.trim()) {
|
||||
newErrors.name = t('contact.errors.nameRequired');
|
||||
}
|
||||
|
||||
if (!formData.email.trim()) {
|
||||
newErrors.email = t('contact.errors.emailRequired');
|
||||
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
|
||||
newErrors.email = t('contact.errors.emailInvalid');
|
||||
}
|
||||
|
||||
if (!formData.message.trim()) {
|
||||
newErrors.message = t('contact.errors.messageRequired');
|
||||
}
|
||||
|
||||
setErrors(newErrors);
|
||||
return Object.keys(newErrors).length === 0;
|
||||
};
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!validateForm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus('loading');
|
||||
|
||||
try {
|
||||
const response = await fetch(`/${locale}/api/contact`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...formData,
|
||||
locale,
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
setStatus('success');
|
||||
setFormData({
|
||||
name: '',
|
||||
email: '',
|
||||
phone: '',
|
||||
subject: '',
|
||||
message: '',
|
||||
});
|
||||
} else {
|
||||
setStatus('error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Contact form error:', error);
|
||||
setStatus('error');
|
||||
}
|
||||
};
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[name]: value,
|
||||
}));
|
||||
|
||||
// Clear error when user starts typing
|
||||
if (errors[name as keyof FormData]) {
|
||||
setErrors(prev => ({
|
||||
...prev,
|
||||
[name]: undefined,
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
|
||||
{status === 'success' && (
|
||||
<div className="mb-6 p-4 bg-green-50 border border-green-200 rounded-md text-green-800">
|
||||
{t('contact.success')}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{status === 'error' && (
|
||||
<div className="mb-6 p-4 bg-red-50 border border-red-200 rounded-md text-red-800">
|
||||
{t('contact.error')}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<label htmlFor="name" className="block text-sm font-medium text-gray-700 mb-2">
|
||||
{t('contact.name')} *
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="name"
|
||||
name="name"
|
||||
value={formData.name}
|
||||
onChange={handleChange}
|
||||
className={`w-full px-4 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 ${
|
||||
errors.name ? 'border-red-500' : 'border-gray-300'
|
||||
}`}
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
{errors.name && (
|
||||
<p className="mt-1 text-sm text-red-600">{errors.name}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700 mb-2">
|
||||
{t('contact.email')} *
|
||||
</label>
|
||||
<input
|
||||
type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
value={formData.email}
|
||||
onChange={handleChange}
|
||||
className={`w-full px-4 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 ${
|
||||
errors.email ? 'border-red-500' : 'border-gray-300'
|
||||
}`}
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
{errors.email && (
|
||||
<p className="mt-1 text-sm text-red-600">{errors.email}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="phone" className="block text-sm font-medium text-gray-700 mb-2">
|
||||
{t('contact.phone')}
|
||||
</label>
|
||||
<input
|
||||
type="tel"
|
||||
id="phone"
|
||||
name="phone"
|
||||
value={formData.phone}
|
||||
onChange={handleChange}
|
||||
className="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="subject" className="block text-sm font-medium text-gray-700 mb-2">
|
||||
{t('contact.subject')}
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="subject"
|
||||
name="subject"
|
||||
value={formData.subject}
|
||||
onChange={handleChange}
|
||||
className="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="message" className="block text-sm font-medium text-gray-700 mb-2">
|
||||
{t('contact.message')} *
|
||||
</label>
|
||||
<textarea
|
||||
id="message"
|
||||
name="message"
|
||||
rows={6}
|
||||
value={formData.message}
|
||||
onChange={handleChange}
|
||||
className={`w-full px-4 py-2 border rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 ${
|
||||
errors.message ? 'border-red-500' : 'border-gray-300'
|
||||
}`}
|
||||
disabled={status === 'loading'}
|
||||
/>
|
||||
{errors.message && (
|
||||
<p className="mt-1 text-sm text-red-600">{errors.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-sm text-gray-500">
|
||||
{t('contact.requiredFields')}
|
||||
</p>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={status === 'loading'}
|
||||
className="px-6 py-3 bg-blue-600 text-white font-medium rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
{status === 'loading' ? t('contact.sending') : t('contact.submit')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
68
components/CookieConsent.tsx
Normal file
68
components/CookieConsent.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect } from 'react';
|
||||
import { t, getLocaleFromPath } from '@/lib/i18n';
|
||||
import { usePathname } from 'next/navigation';
|
||||
|
||||
export function CookieConsent() {
|
||||
const [showBanner, setShowBanner] = useState(false);
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
const pathname = usePathname();
|
||||
const locale = getLocaleFromPath(pathname);
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true);
|
||||
const consent = localStorage.getItem('cookie-consent');
|
||||
if (!consent) {
|
||||
setShowBanner(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleAccept = () => {
|
||||
localStorage.setItem('cookie-consent', 'accepted');
|
||||
setShowBanner(false);
|
||||
};
|
||||
|
||||
const handleDecline = () => {
|
||||
localStorage.setItem('cookie-consent', 'declined');
|
||||
setShowBanner(false);
|
||||
};
|
||||
|
||||
if (!isMounted || !showBanner) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed bottom-0 left-0 right-0 z-50 bg-white border-t border-gray-200 shadow-lg">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-4">
|
||||
<div className="flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
|
||||
<div className="flex-1">
|
||||
<p className="text-sm text-gray-700">
|
||||
{t('cookieConsent.message', locale)}
|
||||
<a
|
||||
href="/privacy-policy"
|
||||
className="text-blue-600 hover:text-blue-700 underline ml-1"
|
||||
>
|
||||
{t('cookieConsent.privacyPolicy', locale)}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
onClick={handleDecline}
|
||||
className="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-md transition-colors"
|
||||
>
|
||||
{t('cookieConsent.decline', locale)}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleAccept}
|
||||
className="px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md transition-colors"
|
||||
>
|
||||
{t('cookieConsent.accept', locale)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
45
components/LocaleSwitcher.tsx
Normal file
45
components/LocaleSwitcher.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { getLocaleFromPath, getLocalizedPath, t, type Locale } from '@/lib/i18n';
|
||||
|
||||
export function LocaleSwitcher() {
|
||||
const pathname = usePathname();
|
||||
const currentLocale = getLocaleFromPath(pathname);
|
||||
|
||||
const locales: Locale[] = ['en', 'de'];
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center gap-2 bg-white rounded-lg border border-gray-200 p-1 shadow-sm">
|
||||
{locales.map((locale) => {
|
||||
const isActive = currentLocale === locale;
|
||||
const label = locale === 'en' ? 'English' : 'Deutsch';
|
||||
const flag = locale === 'en' ? '🇺🇸' : '🇩🇪';
|
||||
|
||||
// Get the current path without locale
|
||||
const currentPath = pathname.replace(/^\/(de|en)/, '') || '/';
|
||||
const href = getLocalizedPath(currentPath, locale);
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={locale}
|
||||
href={href}
|
||||
className={`px-4 py-2 text-sm font-medium rounded-md transition-all ${
|
||||
isActive
|
||||
? 'bg-blue-600 text-white shadow-sm'
|
||||
: 'text-gray-700 hover:bg-gray-50 hover:text-gray-900'
|
||||
}`}
|
||||
aria-label={`Switch to ${label}`}
|
||||
locale={locale}
|
||||
>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
<span className="text-base">{flag}</span>
|
||||
<span>{label}</span>
|
||||
</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
104
components/Navigation.css
Normal file
104
components/Navigation.css
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Navigation Styles */
|
||||
.nav {
|
||||
background: #ffffff;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.navContainer {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 0 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 4rem;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.navMenu {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navLink {
|
||||
color: #4b5563;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: color 0.2s;
|
||||
padding: 0.5rem 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.navLink:hover {
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.navLink.active {
|
||||
color: #1f2937;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.navLink.active::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
background: #3b82f6;
|
||||
}
|
||||
|
||||
.langSwitcher {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.langButton {
|
||||
background: transparent;
|
||||
border: 1px solid #d1d5db;
|
||||
padding: 0.375rem 0.75rem;
|
||||
border-radius: 0.375rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: #4b5563;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.langButton:hover {
|
||||
background: #f3f4f6;
|
||||
border-color: #9ca3af;
|
||||
}
|
||||
|
||||
.langButton.active {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.navContainer {
|
||||
flex-direction: column;
|
||||
height: auto;
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.navMenu {
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
40
components/Navigation.module.css
Normal file
40
components/Navigation.module.css
Normal file
@@ -0,0 +1,40 @@
|
||||
.navbar {
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
padding: 1rem 0;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.navContainer {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 1rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navLogo {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
color: #0070f3;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.navMenu {
|
||||
display: flex;
|
||||
gap: 1.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navLink {
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.navLink:hover {
|
||||
color: #0070f3;
|
||||
}
|
||||
39
components/Navigation.tsx
Normal file
39
components/Navigation.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
import Link from 'next/link'
|
||||
|
||||
interface NavigationProps {
|
||||
logo?: string
|
||||
siteName: string
|
||||
locale: string
|
||||
}
|
||||
|
||||
export function Navigation({ logo, siteName, locale }: NavigationProps) {
|
||||
// Static menu for now - can be made dynamic later
|
||||
const mainMenu = [
|
||||
{ title: 'Home', path: `/${locale}` },
|
||||
{ title: 'Blog', path: `/${locale}/blog` },
|
||||
{ title: 'Products', path: `/${locale}/products` },
|
||||
{ title: 'Contact', path: `/${locale}/contact` }
|
||||
]
|
||||
|
||||
return (
|
||||
<nav className="navbar">
|
||||
<div className="nav-container">
|
||||
<Link href={`/${locale}`} className="nav-logo">
|
||||
{logo || siteName}
|
||||
</Link>
|
||||
|
||||
<div className="nav-menu">
|
||||
{mainMenu.map((item) => (
|
||||
<Link
|
||||
key={item.path}
|
||||
href={item.path}
|
||||
className="nav-link"
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
78
components/ProductList.tsx
Normal file
78
components/ProductList.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { Product } from '@/lib/data';
|
||||
|
||||
interface ProductListProps {
|
||||
products: Product[];
|
||||
locale?: 'de' | 'en';
|
||||
}
|
||||
|
||||
export function ProductList({ products, locale = 'de' }: ProductListProps) {
|
||||
if (products.length === 0) {
|
||||
return (
|
||||
<div className="text-center py-8 text-gray-500">
|
||||
{locale === 'de' ? 'Keine Produkte gefunden' : 'No products found'}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{products.map((product) => (
|
||||
<Link
|
||||
key={product.id}
|
||||
href={product.path}
|
||||
className="group block bg-white rounded-lg border border-gray-200 overflow-hidden hover:shadow-lg transition-shadow"
|
||||
>
|
||||
{product.featuredImage && (
|
||||
<div className="aspect-video bg-gray-100 overflow-hidden">
|
||||
<img
|
||||
src={product.featuredImage}
|
||||
alt={product.name}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-200"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="p-4">
|
||||
<h3 className="font-semibold text-lg mb-2 text-gray-900 group-hover:text-blue-600 transition-colors">
|
||||
{product.name}
|
||||
</h3>
|
||||
{product.shortDescriptionHtml && (
|
||||
<div
|
||||
className="text-sm text-gray-600 mb-3 line-clamp-2"
|
||||
dangerouslySetInnerHTML={{ __html: product.shortDescriptionHtml }}
|
||||
/>
|
||||
)}
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex gap-2">
|
||||
{product.regularPrice && (
|
||||
<span className={`font-bold ${product.salePrice ? 'text-gray-400 line-through text-sm' : 'text-blue-600'}`}>
|
||||
{product.regularPrice}
|
||||
</span>
|
||||
)}
|
||||
{product.salePrice && (
|
||||
<span className="font-bold text-red-600">
|
||||
{product.salePrice}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{product.stockStatus && (
|
||||
<span className={`text-xs px-2 py-1 rounded ${
|
||||
product.stockStatus === 'instock'
|
||||
? 'bg-green-100 text-green-800'
|
||||
: 'bg-red-100 text-red-800'
|
||||
}`}>
|
||||
{product.stockStatus === 'instock'
|
||||
? (locale === 'de' ? 'Auf Lager' : 'In Stock')
|
||||
: (locale === 'de' ? 'Nicht auf Lager' : 'Out of Stock')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
144
components/SEO.tsx
Normal file
144
components/SEO.tsx
Normal file
@@ -0,0 +1,144 @@
|
||||
import { getSiteInfo } from '@/lib/i18n';
|
||||
import { ReactElement } from 'react';
|
||||
|
||||
interface SEOProps {
|
||||
title: string;
|
||||
description?: string;
|
||||
locale?: 'en' | 'de';
|
||||
path?: string;
|
||||
type?: 'website' | 'article' | 'product';
|
||||
publishedTime?: string;
|
||||
modifiedTime?: string;
|
||||
authors?: string[];
|
||||
images?: string[];
|
||||
}
|
||||
|
||||
export function SEO({
|
||||
title,
|
||||
description,
|
||||
locale = 'en',
|
||||
path = '/',
|
||||
type = 'website',
|
||||
publishedTime,
|
||||
modifiedTime,
|
||||
authors,
|
||||
images
|
||||
}: SEOProps): ReactElement {
|
||||
const site = getSiteInfo();
|
||||
const fullTitle = title === 'Home' ? site.title : `${title} | ${site.title}`;
|
||||
const fullDescription = description || site.description;
|
||||
const canonicalUrl = `${site.baseUrl}${path}`;
|
||||
|
||||
// Generate alternate URLs
|
||||
const alternateLocale = locale === 'en' ? 'de' : 'en';
|
||||
const alternatePath = path === '/' ? '' : path;
|
||||
const alternateUrl = `${site.baseUrl}/${alternateLocale}${alternatePath}`;
|
||||
|
||||
// Open Graph images
|
||||
const ogImages = images && images.length > 0
|
||||
? images
|
||||
: [`${site.baseUrl}/og-image.jpg`];
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Basic Meta Tags */}
|
||||
<title>{fullTitle}</title>
|
||||
<meta name="description" content={fullDescription} />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="robots" content="index, follow" />
|
||||
|
||||
{/* Canonical URL */}
|
||||
<link rel="canonical" href={canonicalUrl} />
|
||||
|
||||
{/* Alternate Languages */}
|
||||
<link rel="alternate" hrefLang={locale} href={canonicalUrl} />
|
||||
<link rel="alternate" hrefLang={alternateLocale} href={alternateUrl} />
|
||||
<link rel="alternate" hrefLang="x-default" href={`${site.baseUrl}${alternatePath}`} />
|
||||
|
||||
{/* Open Graph */}
|
||||
<meta property="og:type" content={type} />
|
||||
<meta property="og:title" content={fullTitle} />
|
||||
<meta property="og:description" content={fullDescription} />
|
||||
<meta property="og:url" content={canonicalUrl} />
|
||||
<meta property="og:locale" content={locale === 'en' ? 'en_US' : 'de_DE'} />
|
||||
<meta property="og:site_name" content={site.title} />
|
||||
|
||||
{ogImages.map((image, index) => (
|
||||
<meta key={index} property="og:image" content={image} />
|
||||
))}
|
||||
|
||||
{publishedTime && (
|
||||
<meta property="article:published_time" content={publishedTime} />
|
||||
)}
|
||||
|
||||
{modifiedTime && (
|
||||
<meta property="article:modified_time" content={modifiedTime} />
|
||||
)}
|
||||
|
||||
{authors && authors.length > 0 && (
|
||||
<meta property="article:author" content={authors.join(', ')} />
|
||||
)}
|
||||
|
||||
{/* Twitter Card */}
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content={fullTitle} />
|
||||
<meta name="twitter:description" content={fullDescription} />
|
||||
{ogImages[0] && (
|
||||
<meta name="twitter:image" content={ogImages[0]} />
|
||||
)}
|
||||
|
||||
{/* Site Info */}
|
||||
<meta name="author" content="KLZ Kabelwerke" />
|
||||
<meta name="copyright" content="KLZ Kabelwerke" />
|
||||
|
||||
{/* Favicon (placeholder) */}
|
||||
<link rel="icon" href="/favicon.ico" sizes="any" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function generateSEOMetadata(props: SEOProps) {
|
||||
const site = getSiteInfo();
|
||||
const fullTitle = props.title === 'Home' ? site.title : `${props.title} | ${site.title}`;
|
||||
const description = props.description || site.description;
|
||||
const canonicalUrl = `${site.baseUrl}${props.path || '/'}`;
|
||||
|
||||
const alternateLocale = props.locale === 'en' ? 'de' : 'en';
|
||||
const alternatePath = props.path && props.path !== '/' ? props.path : '';
|
||||
const alternateUrl = `${site.baseUrl}/${alternateLocale}${alternatePath}`;
|
||||
|
||||
return {
|
||||
title: fullTitle,
|
||||
description,
|
||||
metadataBase: new URL(site.baseUrl),
|
||||
alternates: {
|
||||
canonical: canonicalUrl,
|
||||
languages: {
|
||||
[props.locale || 'en']: canonicalUrl,
|
||||
[alternateLocale]: alternateUrl,
|
||||
},
|
||||
},
|
||||
openGraph: {
|
||||
title: fullTitle,
|
||||
description,
|
||||
type: props.type || 'website',
|
||||
locale: props.locale || 'en',
|
||||
siteName: site.title,
|
||||
url: canonicalUrl,
|
||||
...(props.images && props.images.length > 0 && {
|
||||
images: props.images.map(img => ({ url: img, alt: fullTitle })),
|
||||
}),
|
||||
...(props.publishedTime && { publishedTime: props.publishedTime }),
|
||||
...(props.modifiedTime && { modifiedTime: props.modifiedTime }),
|
||||
...(props.authors && { authors: props.authors }),
|
||||
},
|
||||
twitter: {
|
||||
card: 'summary_large_image',
|
||||
title: fullTitle,
|
||||
description,
|
||||
...(props.images && props.images[0] && { images: [props.images[0]] }),
|
||||
},
|
||||
authors: props.authors ? props.authors.map(name => ({ name })) : undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user