Add blog utilities and tag pages
Introduce formatBlogDate, slugifyTag and getTagHref in src/lib/blog.ts and a reading time helper getReadingTime in src/lib/readingTime.ts. Update blog index and post pages to display ISO dates, reading times and link tags to /blog/tag/<slug>. Add a tag listing page at src/pages/blog/tag/[tag].astro with styles and static paths generation
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
export function formatBlogDate(date: Date) {
|
||||
return date.toISOString().split("T")[0];
|
||||
}
|
||||
|
||||
export function slugifyTag(tag: string) {
|
||||
return tag
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/&/g, " and ")
|
||||
.replace(/[^a-z0-9\s-]/g, "")
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/-+/g, "-");
|
||||
}
|
||||
|
||||
export function getTagHref(tag: string) {
|
||||
return `/blog/tag/${slugifyTag(tag)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user