All checks were successful
Publish static bundles / publish (push) Successful in 3m19s
44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import sharp from "sharp";
|
|
|
|
const images = [
|
|
["assets/uploads/2013/10/BannerFamilyFed_23_10c1.jpg", [480, 768, 1050]],
|
|
["assets/uploads/2013/10/TrueParentsSlider.jpg", [640, 1050]],
|
|
["assets/uploads/2013/10/Little-Angels-Presentationlight1.jpg", [640, 1050]],
|
|
["assets/uploads/2013/10/father-Seung-Hwa_Presentation.jpg", [640, 1050]],
|
|
["assets/uploads/2013/10/True_Parents.jpg", [336, 483]],
|
|
["assets/uploads/2013/10/DP-Screenshot.jpg", [336, 672, 900]],
|
|
["assets/uploads/2013/10/UPF-Prayer-Evening.jpg", [336, 656]],
|
|
["assets/uploads/2013/10/Logo_IRFF_Fit3.png", [130]],
|
|
["assets/uploads/2013/10/Logo_UC_Fit31.png", [130]],
|
|
["assets/uploads/2013/10/Logo_UPF_fit3.png", [130]],
|
|
["assets/uploads/2013/10/Logo_WFWP_Fit3.png", [130]],
|
|
["assets/uploads/2015/08/Fathers-3rd-SeongHwa-flier.png", [320, 640, 724]],
|
|
["assets/uploads/2019/04/Blessing-PDF-for-BJD-June-2019.png", [320, 640, 875]],
|
|
];
|
|
|
|
async function renderVariant(source, width, format) {
|
|
const parsed = path.parse(source);
|
|
const destination = path.join(parsed.dir, `${parsed.name}-${width}.${format}`);
|
|
const pipeline = sharp(source).rotate().resize({ width, withoutEnlargement: true });
|
|
|
|
if (format === "avif") {
|
|
await pipeline.avif({ quality: 50, effort: 5 }).toFile(destination);
|
|
} else {
|
|
await pipeline.webp({ quality: 80, effort: 5 }).toFile(destination);
|
|
}
|
|
|
|
return destination;
|
|
}
|
|
|
|
const outputs = [];
|
|
for (const [source, widths] of images) {
|
|
await fs.access(source);
|
|
for (const width of widths) {
|
|
outputs.push(await renderVariant(source, width, "avif"));
|
|
outputs.push(await renderVariant(source, width, "webp"));
|
|
}
|
|
}
|
|
|
|
console.log(`Generated ${outputs.length} responsive AVIF/WebP image variants.`);
|