const fs = require('fs'); const path = require('path'); const dir = 'templates'; const files = fs.readdirSync(dir).filter((f) => f.endsWith('.html')); for (const f of files) { const p = path.join(dir, f); let c = fs.readFileSync(p, 'utf8'); const before = c; // 1. theme.config.X. → theme.config.X?. (分组级安全导航,防止分组为 null 时 NPE) c = c.replace(/theme\.config\.([a-z_]+)\./g, 'theme.config.$1?.'); // 2. nav_use_guide / nav_dev_guide 的 th:href 兜底,避免 @{null} c = c.replace( /\$\{theme\.config\.nav\?\.nav_use_guide\}/g, "${theme.config.nav?.nav_use_guide ?: '/'}" ); c = c.replace( /\$\{theme\.config\.nav\?\.nav_dev_guide\}/g, "${theme.config.nav?.nav_dev_guide ?: '/'}" ); if (c !== before) { fs.writeFileSync(p, c); console.log('✓', f); } } console.log('done');