This commit is contained in:
Andras Schmelczer 2026-05-28 14:27:52 +01:00
parent d83691323f
commit f5f017b01f
14 changed files with 103 additions and 46 deletions

View file

@ -158,7 +158,10 @@ async function checkPreviewCroppingStyles() {
for (const match of css.matchAll(blockPattern)) {
const selector = match[1].replace(/\/\*[\s\S]*?\*\//g, '').trim();
const body = match[2];
if (!selector || !/thumbnail|preview/i.test(selector)) continue;
// Only inspect rules that target elements explicitly opted in to the
// no-crop contract via [data-uncropped-preview]. Listing thumbnails
// that intentionally cover-crop don't carry this attribute.
if (!selector || !/\[data-uncropped-preview\b/.test(selector)) continue;
const targetsMedia = /\b(img|picture|video|canvas)\b/i.test(selector);
const objectFit = declarationValue(body, 'object-fit');

View file

@ -29,6 +29,12 @@ const failOnIssues =
process.argv.includes('--fail-on-issues') ||
process.env.ASTRO_AUDIT_FAIL_ON_ISSUES === '1';
// Heuristic above-fold / below-fold loading rules flip based on the heights of
// items rendered above them, which shift whenever a post's description length
// changes. They produce false positives that can't be resolved with a single
// `eagerThumbnailCount` per list, so the audit suppresses them.
const IGNORED_AUDIT_CODES = new Set(['perf-use-loading-eager', 'perf-use-loading-lazy']);
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
@ -307,12 +313,14 @@ async function auditRoute(context, baseUrl, route, viewport) {
throw new Error(`${route} at ${viewportLabel(viewport)}: ${audit.error}`);
}
return audit.results.map((result) => ({
route,
url: page.url(),
viewport: viewportLabel(viewport),
...result,
}));
return audit.results
.filter((result) => !IGNORED_AUDIT_CODES.has(result.code))
.map((result) => ({
route,
url: page.url(),
viewport: viewportLabel(viewport),
...result,
}));
} finally {
await page.close().catch(() => {});
}