Linty fresh

This commit is contained in:
2026-02-01 00:22:52 -03:00
parent c9e32fa352
commit f39b90c41e

View File

@@ -20,23 +20,23 @@ const DIST = path.join(ROOT, 'dist');
* Critters leaves rel="stylesheet" on swap links; change to rel="preload" as="style" * Critters leaves rel="stylesheet" on swap links; change to rel="preload" as="style"
* so the full CSS loads async and only applies on load (non-blocking). * so the full CSS loads async and only applies on load (non-blocking).
*/ */
function postProcessSwapLinks(html) { // function postProcessSwapLinks(html) {
return html.replace(/<link\s+([^>]*)>/gi, (full, attrs) => { // return html.replace(/<link\s+([^>]*)>/gi, (full, attrs) => {
if ( // if (
!/rel="stylesheet"/i.test(attrs) || // !/rel="stylesheet"/i.test(attrs) ||
!/onload="this\.rel='stylesheet'"/i.test(attrs) // !/onload="this\.rel='stylesheet'"/i.test(attrs)
) { // ) {
return full; // return full;
} // }
const fixed = attrs // const fixed = attrs
.replace(/\brel="stylesheet"\s*/i, 'rel="preload" as="style" ') // .replace(/\brel="stylesheet"\s*/i, 'rel="preload" as="style" ')
.replace( // .replace(
/\bonload="this\.rel='stylesheet'"/i, // /\bonload="this\.rel='stylesheet'"/i,
'onload="this.onload=null;this.rel=\'stylesheet\'"', // 'onload="this.onload=null;this.rel=\'stylesheet\'"',
); // );
return `<link ${fixed}>`; // return `<link ${fixed}>`;
}); // });
} // }
async function main() { async function main() {
if (!fs.existsSync(DIST)) { if (!fs.existsSync(DIST)) {