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
14 changes: 14 additions & 0 deletions third_party/eleventy-plugin-local-images/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ const grabRemoteImages = async (rawContent, outputPath) => {
let content = rawContent;

if (outputPath && outputPath.endsWith(".html")) {
// Optimization: fast exit if content doesn't contain images or metadata
// Only apply this optimization if the selector is one of the known defaults
// to avoid breaking custom selectors.
const projectSelector =
"img,amp-img,amp-video,meta[property='og:image'],meta[name='twitter:image'],amp-story";

if (selector === "img" || selector === projectSelector) {
const triggers =
/<img|<amp-(?:img|video|story)|property=['"]og:image['"]|name=['"]twitter:image['"]/i;
if (!triggers.test(content)) {
return content;
}
}

const dom = new JSDOM(content);
const images = [...dom.window.document.querySelectorAll(selector)];

Expand Down