initial migration
This commit is contained in:
64
app/[locale]/product-category/[slug]/page.tsx
Normal file
64
app/[locale]/product-category/[slug]/page.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user