Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion _11ty/img-dim.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const srcset = require("./srcset");
const path = require("path");
const { gif2mp4 } = require("./video-gif");

const imageDimensionsCache = new Map();

/**
* Sets `width` and `height` on each image, adds blurry placeholder
* and generates a srcset if none present.
Expand Down Expand Up @@ -54,7 +56,11 @@ const processImage = async (img, outputPath) => {
}
let dimensions;
try {
dimensions = await sizeOf("_site/" + src);
let imagePath = "_site/" + src;
if (!imageDimensionsCache.has(imagePath)) {
imageDimensionsCache.set(imagePath, sizeOf(imagePath));
}
dimensions = await imageDimensionsCache.get(imagePath);
} catch (e) {
console.warn(e.message, src);
return;
Expand Down