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
+ {project.description} +
+ + {/* CTA */} +