feat: replace slugified title with unslugified tag name (#198)

Update slugified titles to be unslugified in the tag page. This is for better SEO and better a11y. Url and tag elelemnts will still be slugified.

Closes: #179
This commit is contained in:
Sat Naing
2023-12-28 14:16:40 +06:30
committed by GitHub
parent 2827d4e7d8
commit b05b8fb842
5 changed files with 24 additions and 18 deletions
+10 -5
View File
@@ -1,16 +1,21 @@
import { slugifyStr } from "./slugify";
import type { CollectionEntry } from "astro:content";
interface Tag {
tag: string;
tagName: string;
}
const getUniqueTags = (posts: CollectionEntry<"blog">[]) => {
const filteredPosts = posts.filter(({ data }) => !data.draft);
const tags: string[] = filteredPosts
const tags: Tag[] = filteredPosts
.flatMap(post => post.data.tags)
.map(tag => slugifyStr(tag))
.map(tag => ({ tag: slugifyStr(tag), tagName: tag }))
.filter(
(value: string, index: number, self: string[]) =>
self.indexOf(value) === index
(value, index, self) =>
self.findIndex(tag => tag.tag === value.tag) === index
)
.sort((tagA: string, tagB: string) => tagA.localeCompare(tagB));
.sort((tagA, tagB) => tagA.tag.localeCompare(tagB.tag));
return tags;
};