mirror of
https://github.com/10h30/blog-balodeplao.git
synced 2026-05-12 23:21:16 +09:00
feat: add getDescendantSlugs function and update category/destination filtering logic
This commit is contained in:
@@ -77,3 +77,26 @@ export function getTaxonomyItem(
|
||||
): TaxonomyItem | undefined {
|
||||
return getTaxonomyMap(type).get(slug);
|
||||
}
|
||||
|
||||
export function getDescendantSlugs(
|
||||
taxonomyType: string,
|
||||
slug: string,
|
||||
): string[] {
|
||||
const map = getTaxonomyMap(taxonomyType);
|
||||
const result: string[] = [];
|
||||
|
||||
for (const [key, item] of map.entries()) {
|
||||
if (key === slug) continue;
|
||||
// Đi ngược từ node này lên root, kiểm tra xem có qua slug không
|
||||
let current: TaxonomyItem | undefined = item;
|
||||
while (current?.parent) {
|
||||
if (current.parent === slug) {
|
||||
result.push(key);
|
||||
break;
|
||||
}
|
||||
current = map.get(current.parent);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user