mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user