Skip to content

Commit 5689790

Browse files
committed
fix: categories duplication
1 parent 1992259 commit 5689790

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/posts/api.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ export async function getPostSlugs() {
7373
export async function getPostsCategories() {
7474
const posts = await getPosts();
7575

76-
return [...new Set(posts.flatMap((post) => post.data.categories))];
76+
const uniqueCategories = posts.reduce((acc, post) => {
77+
post.data.categories.forEach((category) => {
78+
acc.add(category.trim().toLowerCase());
79+
});
80+
return acc;
81+
}, new Set());
82+
83+
return [...uniqueCategories];
7784
}
7885

7986
export function filterPostsByCategory(posts: Post[], category: string): Post[] {

0 commit comments

Comments
 (0)