-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetUniqueTags.ts
More file actions
23 lines (20 loc) · 618 Bytes
/
Copy pathgetUniqueTags.ts
File metadata and controls
23 lines (20 loc) · 618 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type { CollectionEntry } from "astro:content";
import { slugifyStr } from "./slugify";
import postFilter from "./postFilter";
interface Tag {
tag: string;
tagName: string;
}
const getUniqueTags = (posts: CollectionEntry<"blog">[]) => {
const tags: Tag[] = posts
.filter(postFilter)
.flatMap(post => post.data.tags)
.map(tag => ({ tag: slugifyStr(tag), tagName: tag }))
.filter(
(value, index, self) =>
self.findIndex(tag => tag.tag === value.tag) === index
)
.sort((tagA, tagB) => tagA.tag.localeCompare(tagB.tag));
return tags;
};
export default getUniqueTags;