Create getUniqueTags function

This commit is contained in:
Sat Naing
2022-09-11 14:08:04 +06:30
parent 26e737f2c9
commit 5632b9bcf8
+18
View File
@@ -0,0 +1,18 @@
import slugify from "./slugify";
import type { MarkdownInstance } from "astro";
import type { Frontmatter } from "./types";
const getUniqueTags = (posts: MarkdownInstance<Frontmatter>[]) => {
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;