refactor(tags): centralize tag slug logic in client-safe util

This commit is contained in:
kbot
2026-07-06 20:15:54 -05:00
parent 7c8a4d8c52
commit ff58dd000c
5 changed files with 21 additions and 37 deletions

View File

@@ -2,6 +2,9 @@ import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
import { cache } from 'react'
import { tagToSlug } from '@/lib/tags'
export { tagToSlug } from '@/lib/tags'
const postsDirectory = path.join(process.cwd(), 'content/posts')
@@ -61,18 +64,6 @@ export const normalizePostData = (
readingTime,
})
export const tagToSlug = (tag: string): string =>
tag
.normalize('NFKD')
.toLowerCase()
.replace(/[\u0300-\u036f]/g, '')
.replace(/\+/g, ' plus ')
.replace(/#/g, ' sharp ')
.replace(/[\\/]+/g, ' ')
.replace(/[^\p{L}\p{N}]+/gu, '-')
.replace(/-{2,}/g, '-')
.replace(/^-|-$/g, '')
const getMdxFiles = cache(async () => {
try {
const files = await fs.promises.readdir(postsDirectory)