Inline subpage critical CSS
This commit is contained in:
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user