import fs from 'fs' import path from 'path' import matter from 'gray-matter' const CONTENT_DIR = path.join(process.cwd(), 'content') const KNIEPUNKT_DIR = path.join(CONTENT_DIR, 'kniepunkt') const POSTS_DIR = path.join(CONTENT_DIR, 'posts') function getFiles(dir) { return fs.readdirSync(dir).map(f => path.join(dir, f)).filter(f => f.endsWith('.md')) } const allFiles = [...getFiles(KNIEPUNKT_DIR), ...getFiles(POSTS_DIR)] function decodeEntities(str) { if (!str) return str return str .replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/'/g, "'") .replace(/'/g, "'") .replace(/ /g, ' ') } allFiles.forEach(file => { if (fs.existsSync(file)) { const raw = fs.readFileSync(file, 'utf8') // Fast check if (raw.includes('&#') || raw.includes('"') || raw.includes('&')) { const data = matter(raw) let changed = false if (data.data.title && (data.data.title.includes('&#') || data.data.title.includes('"'))) { data.data.title = decodeEntities(data.data.title) changed = true } const newContent = decodeEntities(data.content) if (newContent !== data.content) { data.content = newContent changed = true } if (changed) { fs.writeFileSync(file, matter.stringify(data.content, data.data)) console.log(`📝 Fixed entities in ${path.basename(file)}`) } } } })