FIx timeout
All checks were successful
Check & deploy / validate (push) Successful in 30m51s
Check & deploy / deploy (push) Successful in 5m57s

This commit is contained in:
Andras Schmelczer 2026-05-31 15:44:32 +01:00
parent 2e2b7dc850
commit 3193c509a7

View file

@ -169,10 +169,17 @@ const generate = async () => {
})); }));
await assertCatalogMatchesFiles(catalog); await assertCatalogMatchesFiles(catalog);
await rm(publicPhotoDir, { recursive: true, force: true });
await mkdir(publicPhotoDir, { recursive: true }); await mkdir(publicPhotoDir, { recursive: true });
await mkdir(generatedDir, { recursive: true }); await mkdir(generatedDir, { recursive: true });
// Variant filenames embed a hash of their source image, so any file that
// already exists is already up to date. Skip re-encoding those and prune
// only the ones no longer referenced. Regenerating every variant from
// scratch takes minutes and would blow the Playwright preview server's
// startup timeout.
const existingFiles = new Set(await readdir(publicPhotoDir));
const expectedFiles = new Set();
const photos = []; const photos = [];
for (const entry of catalog) { for (const entry of catalog) {
@ -192,8 +199,10 @@ const generate = async () => {
const variants = outputWidths.map((width) => { const variants = outputWidths.map((width) => {
const height = Math.round((width / metadata.width) * metadata.height); const height = Math.round((width / metadata.width) * metadata.height);
const filename = `${entry.id}-${hash}-${width}.${format.extension}`; const filename = `${entry.id}-${hash}-${width}.${format.extension}`;
expectedFiles.add(filename);
return { return {
filename,
outputPath: path.join(publicPhotoDir, filename), outputPath: path.join(publicPhotoDir, filename),
src: `static/photos/${filename}`, src: `static/photos/${filename}`,
width, width,
@ -202,20 +211,22 @@ const generate = async () => {
}); });
await Promise.all( await Promise.all(
variants.map(async ({ outputPath, width }) => { variants
const pipeline = sharp(input).rotate().resize({ .filter(({ filename }) => !existingFiles.has(filename))
width, .map(async ({ outputPath, width }) => {
withoutEnlargement: true, const pipeline = sharp(input).rotate().resize({
}); width,
withoutEnlargement: true,
});
if (format.extension === 'avif') { if (format.extension === 'avif') {
await pipeline.avif(format.options).toFile(outputPath); await pipeline.avif(format.options).toFile(outputPath);
} else if (format.extension === 'webp') { } else if (format.extension === 'webp') {
await pipeline.webp(format.options).toFile(outputPath); await pipeline.webp(format.options).toFile(outputPath);
} else { } else {
await pipeline.jpeg(format.options).toFile(outputPath); await pipeline.jpeg(format.options).toFile(outputPath);
} }
}) })
); );
sources.push({ sources.push({
@ -249,6 +260,16 @@ const generate = async () => {
}); });
} }
// Drop variants that are no longer referenced: deleted photos, or sources
// whose content changed (and so produced a new hash in their filename).
await Promise.all(
[...existingFiles]
.filter((filename) => !expectedFiles.has(filename))
.map((filename) =>
rm(path.join(publicPhotoDir, filename), { force: true })
)
);
const firstPhoto = photos[0]; const firstPhoto = photos[0];
const portraits = photos const portraits = photos
.filter((photo) => photo.orientation === 'portrait') .filter((photo) => photo.orientation === 'portrait')