Files
hoanghapc_nextJs/src/lib/slug/slugMap.ts

23 lines
586 B
TypeScript
Raw Normal View History

2025-12-30 18:05:53 +07:00
import { resolveArticlePage } from "./resolveArticlePage";
import { resolveProductPage } from "./resolveProductPage";
2025-12-29 17:43:31 +07:00
export type SlugResult =
2025-12-30 18:05:53 +07:00
| ReturnType<typeof resolveArticlePage>
| ReturnType<typeof resolveProductPage>;
2025-12-29 17:43:31 +07:00
2025-12-30 18:05:53 +07:00
export function findBySlug(slug?: string): SlugResult | null {
2026-01-15 17:30:04 +07:00
if (!slug || slug.trim() === '') {
return null;
}
2025-12-29 17:43:31 +07:00
2025-12-30 18:05:53 +07:00
// PRODUCT
const product = resolveProductPage(slug);
if (product) return product;
2025-12-29 17:43:31 +07:00
2025-12-30 18:05:53 +07:00
// ARTICLE
2026-01-15 17:30:04 +07:00
const articler = resolveArticlePage(slug);
if (articler) return articler;
// 404
return null;
2025-12-30 18:05:53 +07:00
}