refactor tag counting logic for clarity
This commit is contained in:
parent
8ba5ee800f
commit
80633f89aa
1 changed files with 2 additions and 1 deletions
|
|
@ -6,7 +6,8 @@ const posts = await getCollection("blog");
|
||||||
const tagsMap = new Map<string, number>();
|
const tagsMap = new Map<string, number>();
|
||||||
posts.forEach((post) => {
|
posts.forEach((post) => {
|
||||||
post.data.tags?.forEach((tag) => {
|
post.data.tags?.forEach((tag) => {
|
||||||
tagsMap.set(tag, (tagsMap.get(tag) || 0) + 1);
|
const currentCount = tagsMap.get(tag) || 0;
|
||||||
|
tagsMap.set(tag, currentCount + 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const tags = Array.from(tagsMap.entries()).sort((a, b) =>
|
const tags = Array.from(tagsMap.entries()).sort((a, b) =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue