From e6f2e92083be394cec672318bb1d2e1193fa3642 Mon Sep 17 00:00:00 2001 From: mifi Date: Thu, 12 Mar 2026 12:39:50 -0300 Subject: [PATCH] Inline subpage critical CSS --- scripts/beasties.mjs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/scripts/beasties.mjs b/scripts/beasties.mjs index 3054f6a..e5c15ee 100644 --- a/scripts/beasties.mjs +++ b/scripts/beasties.mjs @@ -29,13 +29,35 @@ async function main() { logLevel: 'warn', }); - const files = fs.readdirSync(DIST).filter((f) => f.endsWith('.html')); - for (const file of files) { - const filePath = path.join(DIST, file); + const rootFiles = fs.readdirSync(DIST) + .filter((f) => f.endsWith('.html')) + .map((f) => path.join(DIST, f)); + + const servicesDir = path.join(DIST, 'services'); + const serviceFiles = []; + + if (fs.existsSync(servicesDir)) { + const walk = (dir) => { + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + walk(fullPath); + } else if (entry.isFile() && entry.name.endsWith('.html')) { + serviceFiles.push(fullPath); + } + } + }; + + walk(servicesDir); + } + + const files = [...rootFiles, ...serviceFiles]; + + for (const filePath of files) { let html = fs.readFileSync(filePath, 'utf8'); html = await beasties.process(html); fs.writeFileSync(filePath, html, 'utf8'); - console.log('✓ Critical CSS inlined → dist/' + file); + console.log('✓ Critical CSS inlined → dist/' + path.relative(DIST, filePath)); } console.log('Critical CSS step complete.');