#!/usr/bin/env node /** * Fix CSP violations in major HTML files (index.html, architecture.html) */ const fs = require('fs'); const path = require('path'); const replacements = [ // Layout { from: ' style="min-height: 64px;"', to: ' class="min-h-16"' }, // Text shadows { from: ' style="text-shadow: 0 2px 4px rgba(0,0,0,0.1);"', to: ' class="text-shadow-md"' }, { from: ' style="text-shadow: 0 1px 2px rgba(0,0,0,0.1);"', to: ' class="text-shadow-sm"' }, // Gradients { from: ' style="background: linear-gradient(135deg, #64ffda 0%, #448aff 50%, #0ea5e9 100%);"', to: ' class="bg-gradient-tractatus"' }, { from: ' style="background: var(--gradient-btn-validator);"', to: ' class="bg-gradient-service-validator"' }, { from: ' style="background: var(--gradient-btn-instruction);"', to: ' class="bg-gradient-service-instruction"' }, { from: ' style="background: var(--gradient-btn-deliberation);"', to: ' class="bg-gradient-service-deliberation"' }, { from: ' style="background: linear-gradient(135deg, #10b981 0%, #059669 100%);"', to: ' class="bg-gradient-service-boundary"' }, { from: ' style="background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);"', to: ' class="bg-gradient-service-instruction"' }, { from: ' style="background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);"', to: ' class="bg-gradient-service-validator"' }, { from: ' style="background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);"', to: ' class="bg-gradient-service-pressure"' }, { from: ' style="background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);"', to: ' class="bg-gradient-service-metacognitive"' }, { from: ' style="background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);"', to: ' class="bg-gradient-service-deliberation"' }, // Border colors { from: ' style="border-left-color: var(--service-validator-light);"', to: ' class="border-l-service-validator"' }, { from: ' style="border-left-color: var(--service-instruction-light);"', to: ' class="border-l-service-instruction"' }, { from: ' style="border-left-color: var(--service-deliberation-light);"', to: ' class="border-l-service-deliberation"' }, { from: ' style="border-left-color: #10b981;"', to: ' class="border-l-service-boundary"' }, { from: ' style="border-left-color: #6366f1;"', to: ' class="border-l-service-instruction"' }, { from: ' style="border-left-color: #8b5cf6;"', to: ' class="border-l-service-validator"' }, { from: ' style="border-left-color: #f59e0b;"', to: ' class="border-l-service-pressure"' }, { from: ' style="border-left-color: #ec4899;"', to: ' class="border-l-service-metacognitive"' }, { from: ' style="border-left-color: #14b8a6;"', to: ' class="border-l-service-deliberation"' }, // Text colors { from: ' style="color: var(--tractatus-core-end);"', to: ' class="text-tractatus-link"' }, { from: ' style="color: var(--service-validator-light);"', to: ' class="text-service-validator"' }, { from: ' style="color: var(--service-instruction-light);"', to: ' class="text-service-instruction"' }, { from: ' style="color: var(--service-deliberation-light);"', to: ' class="text-service-deliberation"' }, { from: ' style="color: var(--service-validator-dark);"', to: ' class="text-service-validator"' }, { from: ' style="color: var(--service-instruction-dark);"', to: ' class="text-service-instruction"' }, { from: ' style="color: var(--service-deliberation-dark);"', to: ' class="text-service-deliberation"' }, // Badges { from: ' style="color: #065f46; background-color: #d1fae5;"', to: ' class="badge-boundary"' }, { from: ' style="color: #3730a3; background-color: #e0e7ff;"', to: ' class="badge-instruction"' }, { from: ' style="color: #581c87; background-color: #f3e8ff;"', to: ' class="badge-validator"' }, { from: ' style="color: #92400e; background-color: #fef3c7;"', to: ' class="badge-pressure"' }, { from: ' style="color: #831843; background-color: #fce7f3;"', to: ' class="badge-metacognitive"' }, { from: ' style="color: #134e4a; background-color: #ccfbf1;"', to: ' class="badge-deliberation"' } ]; const files = [ 'public/index.html', 'public/architecture.html' ]; let totalFixed = 0; files.forEach(file => { const filePath = path.join(__dirname, '..', file); console.log(`\nProcessing ${file}...`); if (!fs.existsSync(filePath)) { console.log(` āœ— File not found`); return; } let content = fs.readFileSync(filePath, 'utf8'); let fileFixed = 0; replacements.forEach(({ from, to }) => { const occurrences = (content.match(new RegExp(from.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')) || []).length; if (occurrences > 0) { content = content.split(from).join(to); fileFixed += occurrences; } }); if (fileFixed > 0) { fs.writeFileSync(filePath, content); totalFixed += fileFixed; console.log(` āœ“ Fixed ${fileFixed} violation(s)`); } else { console.log(` • No violations found`); } }); console.log(`\nāœ“ Total fixes applied: ${totalFixed}\n`);