From 32a815789cab316e4229b4e7818b6c81ddb7f065 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Wed, 1 Feb 2023 10:33:32 +0100 Subject: [PATCH] Add base size to srcset in img and figure shortcodes. --- layouts/shortcodes/figure.html | 3 +++ layouts/shortcodes/img.html | 3 +++ 2 files changed, 6 insertions(+) diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 518f81b..b357b27 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -41,6 +41,9 @@ {{ $src = $image.RelPermalink -}} {{ $width = $image.Width -}} {{ $height = $image.Height -}} + {{ if $srcset -}} + {{ $srcsetw = $srcsetw | append (printf "%s %sw" $src (strings.TrimRight "x" $size)) }} + {{ end -}} {{ else -}} {{ $src = $resource.RelPermalink -}} {{ $realwidth = $resource.Width -}} diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html index 2cb3fc9..ebe47d2 100644 --- a/layouts/shortcodes/img.html +++ b/layouts/shortcodes/img.html @@ -37,6 +37,9 @@ {{ $src = $image.RelPermalink -}} {{ $width = $image.Width -}} {{ $height = $image.Height -}} + {{ if $srcset -}} + {{ $srcsetw = $srcsetw | append (printf "%s %sw" $src (strings.TrimRight "x" $size)) }} + {{ end -}} {{ else -}} {{ $src = $resource.RelPermalink -}} {{ $realwidth = $resource.Width -}}