import fs from "node:fs"; import path from "node:path"; const repoRoot = process.cwd(); const legacyHtmlRoot = path.join(repoRoot, "archive-source"); function walkHtml(dir) { return fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { const fullPath = path.join(dir, entry.name); if (entry.isDirectory()) { return walkHtml(fullPath); } return entry.isFile() && entry.name.endsWith(".html") ? [fullPath] : []; }); } function removeWordPressResidue(html) { const securityMeta = ` `; const bannerPicture = ` Family Federation for World Peace and Unification Ireland `; let cleaned = html .replace(/\n?\s*/g, "\n") .replace( /\n?\s*\n'); } if (!cleaned.includes('http-equiv="Content-Security-Policy"') && cleaned.includes("")) { cleaned = cleaned.replace(/\s*<\/head>/i, `\n${securityMeta}\n`); } return cleaned; } let updated = 0; for (const filePath of walkHtml(legacyHtmlRoot)) { const original = fs.readFileSync(filePath, "utf8"); const cleaned = removeWordPressResidue(original); if (cleaned !== original) { fs.writeFileSync(filePath, cleaned); updated += 1; } } console.log(`Cleaned WordPress residue in ${updated} HTML files.`);