update 27/01
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// src/lib/articlePage.ts
|
||||
import { categories } from "@/data/categories";
|
||||
import { articleList } from "@/data/articles";
|
||||
|
||||
export type ArticleResult =
|
||||
| { type: "article_home"; data: any }
|
||||
@@ -29,8 +30,10 @@ export function resolveArticlePage(slug: string): ArticleResult | null {
|
||||
}
|
||||
|
||||
// DETAIL
|
||||
const isValidSlugFormat = slug.includes('-') && slug.length > 5;
|
||||
if (!isValidSlugFormat) {
|
||||
return null;
|
||||
}
|
||||
const allArticles = articleList.flatMap(article => article.list);
|
||||
for (const article of allArticles) {
|
||||
if (article.url === url) {
|
||||
return { type: "article_detail", data: { slug } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { resolveArticlePage } from "./resolveArticlePage";
|
||||
import { resolveProductPage } from "./resolveProductPage";
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
|
||||
// Add tất cả sp trong data product vào 1 mảng
|
||||
import { productList } from '@/data/products';
|
||||
|
||||
@@ -55,4 +52,24 @@ export function calculateDiscount(
|
||||
) {
|
||||
if (price <= 0 || marketPrice <= price) return 0;
|
||||
return Math.ceil(((marketPrice - price) / marketPrice) * 100);
|
||||
}
|
||||
}
|
||||
|
||||
export function formatArticleTime(article_time:string) {
|
||||
let day: string;
|
||||
let month: string;
|
||||
let year: string;
|
||||
|
||||
if (article_time.toLowerCase().includes('hôm nay')) {
|
||||
const time = new Date();
|
||||
day = (time.getDate() <= 9) ? '0' + time.getDate() : String(time.getDate());
|
||||
month = (time.getMonth()+1 <= 9) ? '0' + (time.getMonth()+1) : String(time.getMonth()+1);
|
||||
year = String(time.getFullYear());
|
||||
} else {
|
||||
day = article_time.substring(0,2);
|
||||
month = article_time.substring(3,5);
|
||||
year = article_time.substring(6,10);
|
||||
}
|
||||
return `${day}/${month}/${year}`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user