diff --git a/src/utils/getUniqueTags.ts b/src/utils/getUniqueTags.ts new file mode 100644 index 0000000..b83bb13 --- /dev/null +++ b/src/utils/getUniqueTags.ts @@ -0,0 +1,18 @@ +import slugify from "./slugify"; +import type { MarkdownInstance } from "astro"; +import type { Frontmatter } from "./types"; + +const getUniqueTags = (posts: MarkdownInstance[]) => { + let tags: string[] = []; + posts.forEach((post) => { + tags = [...tags, ...post.frontmatter.tags] + .map((tag) => slugify(tag)) + .filter( + (value: string, index: number, self: string[]) => + self.indexOf(value) === index + ); + }); + return tags; +}; + +export default getUniqueTags;