From 57ee13a0bb9fbc14d30775dd91ae305071d83f75 Mon Sep 17 00:00:00 2001 From: Alexander Avery Date: Tue, 22 Jul 2025 20:55:05 -0400 Subject: [PATCH] allow for varied image filetypes in shortcode and partial --- layouts/partials/image.html | 7 +++++-- layouts/shortcodes/image.html | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/layouts/partials/image.html b/layouts/partials/image.html index 6dc8b1d..5c45d8b 100644 --- a/layouts/partials/image.html +++ b/layouts/partials/image.html @@ -4,12 +4,15 @@ Renders an image with the given class, alt, and sizes. @context {image} the image resource. @context {sizes} each size to include in the srcset. @context {classes} classes for the image. +@context {ext} extension of output image. */}} {{- $alt := .alt }} {{- $img := .image }} {{- $sizes := .sizes }} {{- $classes := .classes }} + {{- $ext := .ext }} + {{- $srcsetParts := slice }} {{- $sizesParts := slice }} @@ -18,7 +21,7 @@ Renders an image with the given class, alt, and sizes. {{- if .image }} {{/* Loop through widths to resize images and build attributes */}} {{- range $index, $width := $sizes }} - {{- $resizeSpec := printf "%dx webp q90" $width }} + {{- $resizeSpec := printf "%dx %s q90" $width $ext }} {{- $resized := ($img.Resize $resizeSpec) }} {{- $srcsetParts = $srcsetParts | append (printf "%s %dw" $resized.RelPermalink $width) }} @@ -33,7 +36,7 @@ Renders an image with the given class, alt, and sizes. {{- end }} {{- $smallestWidth := index $sizes 0 }} - {{- $smallestResizeSpec := printf "%dx webp q90" $smallestWidth }} + {{- $smallestResizeSpec := printf "%dx %s q90" $smallestWidth $ext }} {{- $smallest := ($img.Resize $smallestResizeSpec) }} {{- $src := $smallest.RelPermalink }}