mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
Create getUniqueTags function
This commit is contained in:
@@ -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;
|
||||||
Reference in New Issue
Block a user