// Stamp the theme head script (themehead.js) into every static page under public/, before the first stylesheet, and
// put data-theme-base on the tag (dark for site.css pages, light for cr.css / pub.css pages). Re-runnable: an
// existing copy between the markers is replaced. Run after changing AUTO_DEFAULT in themehead.js:
// node tools/stamp-theme-head.cjs
const fs = require('fs'), path = require('path');
const themehead = require(path.join(__dirname, '..', 'themehead.js'));
const dir = path.join(__dirname, '..', 'public');
const OPEN = '', CLOSE = '';
let n = 0;
for (const f of fs.readdirSync(dir).filter(f => f.endsWith('.html'))) {
const p = path.join(dir, f);
let html = fs.readFileSync(p, 'utf8');
if (!//, (m, a) => '');
const block = OPEN + themehead.tag() + CLOSE;
if (html.includes(OPEN)) html = html.replace(new RegExp(OPEN + '[\\s\\S]*?' + CLOSE), block);
else html = html.replace(/