From a1232ecf9f5157e6d86aea5cf3c43c29054455c1 Mon Sep 17 00:00:00 2001 From: Jan Zerfowski <54621022+jzerfowski@users.noreply.github.com> Date: Sat, 18 Jan 2025 18:05:13 +0100 Subject: [PATCH] fix: skip image process on svgs and remote images (#551) --- layouts/shortcodes/card.html | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/layouts/shortcodes/card.html b/layouts/shortcodes/card.html index be4612f8..1301bba5 100644 --- a/layouts/shortcodes/card.html +++ b/layouts/shortcodes/card.html @@ -15,16 +15,21 @@ {{- $options := .Get "options" | default "800x webp q80" -}} {{- $process := .Get "process" | default (printf "%s %s" $method $options) -}} -{{- with or (.Page.Resources.Get $image) (resources.Get $image) -}} - {{/* Retrieve the $image resource from local or global resources */}} - {{- $processed := .Process $process -}} - {{- $width = $processed.Width -}} - {{- $height = $processed.Height -}} - {{- $image = $processed.RelPermalink -}} -{{ else }} - {{/* Otherwise, use relative link of the image */}} - {{- if hasPrefix $image "/" -}} - {{- $image = relURL (strings.TrimPrefix "/" $image) -}} +{{- if and $image (not (urls.Parse $image).Scheme) -}} + {{- with or (.Page.Resources.Get $image) (resources.Get $image) -}} + {{/* .Process does not work on svgs */}} + {{- if (not (eq .MediaType.SubType "svg")) -}} + {{/* Retrieve the $image resource from local or global resources */}} + {{- $processed := .Process $process -}} + {{- $width = $processed.Width -}} + {{- $height = $processed.Height -}} + {{- $image = $processed.RelPermalink -}} + {{- end -}} + {{ else }} + {{/* Otherwise, use relative link of the image */}} + {{- if hasPrefix $image "/" -}} + {{- $image = relURL (strings.TrimPrefix "/" $image) -}} + {{- end -}} {{- end -}} {{- end -}}