Skip to content

Commit

Permalink
Simplify unique tags with set
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieseltzer committed Aug 16, 2023
1 parent 88f07d1 commit 0c792a7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/entities/blog-post/selectors/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { getBlogPostMetadata } from './posts';

export const getAllBlogPostTags = () => {
const posts = getBlogPostMetadata();
const uniqueTags: Record<string, Tag> = {};
const uniqueTags = new Set<string>();

for (const { tags } of posts) {
for (const tag of tags) {
if (!(tag.slug in uniqueTags)) {
uniqueTags[tag.slug] = tag;
}
uniqueTags.add(JSON.stringify(tag));
}
}

return Object.values(uniqueTags);
return Array.from(uniqueTags).map(tag => JSON.parse(tag) as Tag);
};

export const getTagBySlug = (slug: string) =>
Expand Down

1 comment on commit 0c792a7

@vercel
Copy link

@vercel vercel bot commented on 0c792a7 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.