feat: refactor taxonomy data handling for categories, destinations, and tags

This commit is contained in:
Thuan Bui
2026-03-19 17:27:05 +07:00
parent beac1efd7f
commit 2c1d3b2f7f
9 changed files with 33 additions and 36 deletions
+7 -5
View File
@@ -7,8 +7,8 @@ import Pagination from "@/components/ui/Pagination.astro";
import type { Page } from "astro";
import type { CollectionEntry } from "astro:content";
import {
categoryMap,
getCategoryPath,
getTaxonomyMap,
getTaxonomyPath,
type TaxonomyItem,
} from "@/utils/taxonomy";
@@ -27,8 +27,10 @@ export async function getStaticPaths() {
.filter((post) => post.data.categories?.includes(slug))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
const fullPath = getCategoryPath(slug);
const cat = categoryMap.get(slug) ?? ({ slug, name: slug } as TaxonomyItem);
const fullPath = getTaxonomyPath("category", slug);
const cat =
getTaxonomyMap("category").get(slug) ??
({ slug, name: slug } as TaxonomyItem);
const totalPages = Math.max(1, Math.ceil(catPosts.length / PAGE_SIZE));
return Array.from({ length: totalPages }, (_, i) => {
@@ -65,7 +67,7 @@ const page = {
currentPage,
lastPage,
url: { prev: prevUrl, next: nextUrl },
} as unknown as Page<CollectionEntry<"blog">>;
};
const metadata = {
title: cat.name,