This commit is contained in:
2026-02-05 17:22:56 +07:00
parent a499e06b31
commit 52748cb988
30 changed files with 1080 additions and 508 deletions

View File

@@ -1,6 +1,7 @@
// src/lib/articlePage.ts
import { categories } from "@/data/categories";
import { articleList } from "@/data/articles";
import { ArticleDetail } from "@/data/articleDetail"
export type ArticleResult =
| { type: "article_home"; data: any }
@@ -12,28 +13,51 @@ export function resolveArticlePage(slug: string): ArticleResult | null {
// HOME
if (url === "/tin-tuc") {
return { type: "article_home", data: null };
return {
type: "article_home",
data : null
};
}
// CATEGORY
const cats = categories.article.all_category.article;
for (const parent of cats) {
if (parent.url === url) {
return { type: "article_category", data: parent };
return {
type: "article_category",
data: parent
};
}
for (const child of parent.children ?? []) {
if (child.url === url) {
return { type: "article_category", data: child };
return {
type: "article_category",
data: child
};
}
}
}
// DETAIL
const allArticles = articleList.flatMap(article => article.list);
for (const article of allArticles) {
if (article.url === url) {
return { type: "article_detail", data: { slug } };
const detail = articleList
.flatMap(article => article.list)
.find((a: any) => a.url === url);
if(detail) {
const data = {
...detail,
content : ArticleDetail.content,
author : ArticleDetail.author,
image_list : ArticleDetail.image_list,
related : ArticleDetail.related,
tag_list : ArticleDetail.tag_list,
}
}
return {
type: "article_detail",
data
};
}
return null;
}

View File

@@ -1,7 +1,7 @@
// hoanghapc/src/lib/productPage.ts
import { categories } from "@/data/categories";
import { productList } from "@/data/productList";
import { productDetail } from "@/data/productDetail"
import { productList } from "@/data/products/productList";
import { productDetail } from "@/data/products/productDetail"
export type ProductResult =
| { type: "product_category"; data: any }

View File

@@ -15,8 +15,8 @@ export function findBySlug(slug?: string): SlugResult | null {
if (product) return product;
// ARTICLE
const articler = resolveArticlePage(slug);
if (articler) return articler;
const article = resolveArticlePage(slug);
if (article) return article;
// 404
return null;

View File

@@ -1,5 +1,5 @@
// Add tất cả sp trong data product vào 1 mảng
import { productList } from '@/data/productList';
import { productList } from '@/data/products/productList';
export function getAllProducts() {
return productList.flatMap((group: any) => group.list);