Inline subpage critical CSS
This commit is contained in:
@@ -29,13 +29,35 @@ async function main() {
|
|||||||
logLevel: 'warn',
|
logLevel: 'warn',
|
||||||
});
|
});
|
||||||
|
|
||||||
const files = fs.readdirSync(DIST).filter((f) => f.endsWith('.html'));
|
const rootFiles = fs.readdirSync(DIST)
|
||||||
for (const file of files) {
|
.filter((f) => f.endsWith('.html'))
|
||||||
const filePath = path.join(DIST, file);
|
.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');
|
let html = fs.readFileSync(filePath, 'utf8');
|
||||||
html = await beasties.process(html);
|
html = await beasties.process(html);
|
||||||
fs.writeFileSync(filePath, html, 'utf8');
|
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.');
|
console.log('Critical CSS step complete.');
|
||||||
|
|||||||
Reference in New Issue
Block a user