diff --git a/src/app/[...slug]/page.tsx b/src/app/[...slug]/page.tsx index b4c3963fb..e281414e0 100644 --- a/src/app/[...slug]/page.tsx +++ b/src/app/[...slug]/page.tsx @@ -1,51 +1,97 @@ import { notFound } from 'next/navigation'; import Image from 'next/image'; import Link from 'next/link'; -import { productCategories } from '@/data/site-config'; +import { productCategories, portfolioProjects } from '@/data/site-config'; + interface Props { params: { slug: string[] }; } -// Generate all possible paths from product categories +// Generate all possible paths from product categories and portfolio projects export async function generateStaticParams() { const paths: { slug: string[] }[] = []; + // Add product category paths productCategories.forEach((product) => { // Remove leading slash and split the href - const pathParts = product.href.replace(/^\//, '').split('/'); + const pathParts = product.href.replace(/^\//, '').replace(/\/$/, '').split('/'); + paths.push({ slug: pathParts }); + }); + + // Add portfolio project paths + portfolioProjects.forEach((project) => { + const pathParts = project.href.replace(/^\//, '').replace(/\/$/, '').split('/'); paths.push({ slug: pathParts }); }); return paths; } -function findProductBySlug(slug: string[]) { - const fullPath = '/' + slug.join('/'); - return productCategories.find((p) => p.href === fullPath); +type ContentType = 'product' | 'portfolio'; + +function findContentBySlug(slug: string[]): { type: ContentType; data: typeof productCategories[0] | typeof portfolioProjects[0] } | null { + const fullPath = '/' + slug.join('/') + '/'; + + // Check products first + const product = productCategories.find((p) => p.href === fullPath); + if (product) { + return { type: 'product', data: product }; + } + + // Check portfolio projects + const portfolio = portfolioProjects.find((p) => p.href === fullPath); + if (portfolio) { + return { type: 'portfolio', data: portfolio }; + } + + return null; } export async function generateMetadata({ params }: Props) { - const product = findProductBySlug(params.slug); + const content = findContentBySlug(params.slug); - if (!product) { + if (!content) { return { title: 'ไม่พบหน้า' }; } + const { type, data } = content; + + if (type === 'product') { + const product = data as typeof productCategories[0]; + return { + title: `${product.name} - ${product.nameEn}`, + description: product.description, + keywords: product.keywords, + }; + } + return { - title: `${product.name} - ${product.nameEn}`, - description: product.description, - keywords: product.keywords, + title: data.name, + description: data.description, }; } -export default function ProductDetailPage({ params }: Props) { - const product = findProductBySlug(params.slug); +export default function DynamicPage({ params }: Props) { + const content = findContentBySlug(params.slug); - if (!product) { + if (!content) { notFound(); } + + const { type, data } = content; + + // Render portfolio project page + if (type === 'portfolio') { + return ; + } + + // Render product page + return ; +} +// Product Page Component +function ProductPage({ product }: { product: typeof productCategories[0] }) { // Find related products in same category const relatedProducts = productCategories .filter((p) => p.slug === product.slug && p.id !== product.id) @@ -110,18 +156,6 @@ export default function ProductDetailPage({ params }: Props) { - {/* SEO Content */} - {product.seoContent && ( -
-
-
-
-
- )} - {/* Related Products */} {relatedProducts.length > 0 && (
@@ -160,3 +194,94 @@ export default function ProductDetailPage({ params }: Props) {
); } + +// Portfolio Page Component +function PortfolioPage({ project }: { project: typeof portfolioProjects[0] }) { + return ( +
+
+ {/* Breadcrumb */} + + +
+ {/* Project Image */} +
+ {project.name} +
+ + {/* Project Info */} +
+

+ {project.name} +

+

+ {project.description} +

+ + {/* CTA */} +
+ + ติดต่อเรา + + + ดูผลงานอื่นๆ + +
+
+
+ + {/* Other Projects */} +
+

+ ผลงานอื่นๆ +

+
+ {portfolioProjects.filter(p => p.id !== project.id).slice(0, 4).map((other) => ( + +
+ {other.name} +
+
+

+ {other.name} +

+
+ + ))} +
+
+
+
+ ); +} diff --git a/src/types/index.ts b/src/types/index.ts index 0f4a6e208..2fc7556d5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -64,6 +64,14 @@ export interface PortfolioItem { description: string; } +export interface PortfolioProject { + id: string; + name: string; + href: string; + image: string; + description: string; +} + // Contact Form Types export interface ContactFormData { name: string;