import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const dir = path.join(__dirname, '..', 'content', 'resources'); let fixed = 0; for (const f of fs.readdirSync(dir).filter(f => f.endsWith('.mdx'))) { const filepath = path.join(dir, f); const original = fs.readFileSync(filepath, 'utf8'); let content = original; // Clean excerpts that contain HTML/CSS artifacts const excerptMatch = content.match(/^excerpt: "(.*)"$/m); if (excerptMatch) { let excerpt = excerptMatch[1]; excerpt = excerpt.replace(/#block-[^\s]+ \{[^}]*\}/g, ''); excerpt = excerpt.replace(/!\[[^\]]*\]\([^)]*\)/g, ''); excerpt = excerpt.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1'); excerpt = excerpt.replace(/\*\*/g, ''); excerpt = excerpt.replace(/\s+/g, ' ').trim().substring(0, 250); if (excerpt !== excerptMatch[1]) { content = content.replace(excerptMatch[0], `excerpt: "${excerpt}"`); } } // Remove BACK TO POSTS lines content = content.replace(/\[?\s*\*?\*?BACK TO POSTS\s*\*?\*?\s*\]?\s*\([^)]*\)\s*(\*?\*?\s*\|?\s*\*?\*?\s*\[?\*?\*?OPEN PAGE AS PDF\*?\*?\]?\([^)]*\))?/gi, ''); // Remove --> artifacts content = content.replace(/^-->\s*$/gm, ''); // Remove CSS block definitions content = content.replace(/#block-[a-zA-Z0-9_-]+ \{[^}]*\}/g, ''); // Clean excessive blank lines content = content.replace(/\n{3,}/g, '\n\n'); if (content !== original) { fs.writeFileSync(filepath, content); fixed++; } } console.log(`Cleaned ${fixed} files`);