05/02
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user