fix tag pages

This commit is contained in:
2025-11-24 17:36:32 -05:00
parent 87a9a7206e
commit e85f8b5c3e
4 changed files with 53 additions and 23 deletions
+40
View File
@@ -0,0 +1,40 @@
import { getCollection } from 'astro:content';
export function getSlug(input: string): string {
return input
.toLowerCase()
.replace(/[^\w\s-]/g, '')
.replace(/[\s_]+/g, '-')
.replace(/^-+|-+$/g, '');
}
export interface Tag {
value: string;
slug: string;
}
export async function getTags(): Promise<Tag[]> {
const posts = await getCollection('blog');
const tags: Tag[] = [
{
value: 'All',
slug: 'all',
},
];
posts.forEach((post) => {
post.data.tags.forEach((tag) => {
const tagToAdd = {
value: tag,
slug: getSlug(tag),
};
if (!tags.includes(tagToAdd)) {
tags.push(tagToAdd);
}
});
});
return tags;
}