feat: add getDescendantSlugs function and update category/destination filtering logic

This commit is contained in:
Thuan Bui
2026-03-22 09:51:26 +07:00
parent 3cc4f98a19
commit 8c934213eb
3 changed files with 35 additions and 4 deletions
+5 -1
View File
@@ -8,6 +8,7 @@ import Pagination from "@/components/ui/Pagination.astro";
import {
getTaxonomyMap,
getTaxonomyPath,
getDescendantSlugs,
type TaxonomyItem,
} from "@/utils/taxonomy";
import { buildPaginatedPaths } from "@/utils/paginate";
@@ -32,8 +33,11 @@ export async function getStaticPaths() {
);
return Array.from(catSlugs).flatMap((slug) => {
const descendants = getDescendantSlugs("category", slug);
const allSlugs = [slug, ...descendants];
const catPosts = posts
.filter((post) => post.data.categories?.includes(slug))
.filter((post) => post.data.categories?.some((d) => allSlugs.includes(d)))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
const fullPath = getTaxonomyPath("category", slug);
+7 -3
View File
@@ -8,6 +8,7 @@ import Pagination from "@/components/ui/Pagination.astro";
import {
getTaxonomyMap,
getTaxonomyPath,
getDescendantSlugs,
type TaxonomyItem,
} from "@/utils/taxonomy";
import { buildPaginatedPaths } from "@/utils/paginate";
@@ -32,8 +33,13 @@ export async function getStaticPaths() {
);
return Array.from(destSlugs).flatMap((slug) => {
const descendants = getDescendantSlugs("destination", slug);
const allSlugs = [slug, ...descendants];
const destPosts = posts
.filter((post) => post.data.destination?.includes(slug))
.filter((post) =>
post.data.destination?.some((d) => allSlugs.includes(d)),
)
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
const fullPath = getTaxonomyPath("destination", slug);
@@ -88,11 +94,9 @@ const metadata = {
subtitle: "mx-auto max-w-3xl text-xl text-muted-foreground",
}}
/>
<div class="mb-8 text-center">
<a href="/blog" class="text-primary hover:underline">← Quay lại blog</a>
</div>
<div class="grid gap-8 md:grid-cols-2 lg:grid-cols-3">
{posts.map((post) => <PostItem post={post} />)}
</div>