From 31022581d8aefbd5e8657ca8bad85aa89f8a8fce Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 30 Jan 2026 15:07:14 +0100 Subject: [PATCH] refactor: image logic in page (#1255) * fix: add SVG check in helper/image before accessing .Width and .Height * refactor: drop image resizing logic in render-image, and use helper/image to process image * fix: render-image $permalink not correct --- layouts/_markup/render-image.html | 32 +++------------- layouts/_partials/helper/image.html | 57 ++++++++++++++--------------- 2 files changed, 33 insertions(+), 56 deletions(-) diff --git a/layouts/_markup/render-image.html b/layouts/_markup/render-image.html index 5577736..a5316d9 100644 --- a/layouts/_markup/render-image.html +++ b/layouts/_markup/render-image.html @@ -1,34 +1,12 @@ -{{- $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}} -{{- $Permalink := .Destination | relURL | safeURL -}} +{{- $image := partial "helper/image" (dict "Resources" .Page.Resources "Image" .Destination) -}} {{- $alt := .PlainText | safeHTML -}} -{{- $Width := 0 -}} -{{- $Height := 0 -}} -{{- $Srcset := "" -}} {{/* SVG and external images won't work with gallery layout, because their width and height attributes are unknown */}} -{{- $galleryImage := false -}} +{{- $galleryImage := and $image.Height $image.Width -}} -{{- if $image -}} - {{- $notSVG := ne (path.Ext .Destination) ".svg" -}} - {{- $Permalink = $image.RelPermalink -}} - - {{- if $notSVG -}} - {{- $Width = $image.Width -}} - {{- $Height = $image.Height -}} - {{- $galleryImage = true -}} - - {{- if .Page.Site.Params.imageProcessing.content.enabled -}} - {{- $small := $image.Resize `480x` -}} - {{- $big := $image.Resize `1024x` -}} - {{- $Srcset = printf `%s 480w, %s 1024w` $small.RelPermalink $big.RelPermalink -}} - {{- end -}} - {{- end -}} -{{- end -}} - -