From 0a067cc87fc62008c5def68e25bbb5978eac51a6 Mon Sep 17 00:00:00 2001 From: Ole Eskild Steensen Date: Fri, 26 May 2023 11:25:13 +0200 Subject: [PATCH] Fix image scaling --- .eleventy.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index fc2122d..5934f61 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -342,8 +342,8 @@ module.exports = function (eleventyConfig) { return str && parsed.innerHTML; }); - function fillPictureSourceSets(src, cls, alt, meta, t) { - t.tagName = "picture"; + function fillPictureSourceSets(src, cls, alt, meta, width, imageTag) { + imageTag.tagName = "picture"; let html = ``; - t.innerHTML = html; + imageTag.innerHTML = html; } eleventyConfig.addTransform("picture", function (str) { const parsed = parse(str); - for (const t of parsed.querySelectorAll(".cm-s-obsidian img")) { - const src = t.getAttribute("src"); + for (const imageTag of parsed.querySelectorAll(".cm-s-obsidian img")) { + const src = imageTag.getAttribute("src"); if (src && src.startsWith("/") && !src.endsWith(".svg")) { - const cls = t.classList.value; - const alt = t.getAttribute("alt"); + const cls = imageTag.classList.value; + const alt = imageTag.getAttribute("alt"); + const width = imageTag.getAttribute("width") || ''; try { const meta = transformImage( - "./src/site" + decodeURI(t.getAttribute("src")), + "./src/site" + decodeURI(imageTag.getAttribute("src")), cls.toString(), alt, ["(max-width: 480px)", "(max-width: 1024px)"] ); if (meta) { - fillPictureSourceSets(src, cls, alt, meta, t); + fillPictureSourceSets(src, cls, alt, meta, width, imageTag); } } catch { // Make it fault tolarent.