fix: skip image process on svgs and remote images (#551)

This commit is contained in:
Jan Zerfowski 2025-01-18 18:05:13 +01:00 committed by GitHub
parent a933f464f5
commit a1232ecf9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,17 +15,22 @@
{{- $options := .Get "options" | default "800x webp q80" -}} {{- $options := .Get "options" | default "800x webp q80" -}}
{{- $process := .Get "process" | default (printf "%s %s" $method $options) -}} {{- $process := .Get "process" | default (printf "%s %s" $method $options) -}}
{{- with or (.Page.Resources.Get $image) (resources.Get $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 */}} {{/* Retrieve the $image resource from local or global resources */}}
{{- $processed := .Process $process -}} {{- $processed := .Process $process -}}
{{- $width = $processed.Width -}} {{- $width = $processed.Width -}}
{{- $height = $processed.Height -}} {{- $height = $processed.Height -}}
{{- $image = $processed.RelPermalink -}} {{- $image = $processed.RelPermalink -}}
{{ else }} {{- end -}}
{{ else }}
{{/* Otherwise, use relative link of the image */}} {{/* Otherwise, use relative link of the image */}}
{{- if hasPrefix $image "/" -}} {{- if hasPrefix $image "/" -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}} {{- $image = relURL (strings.TrimPrefix "/" $image) -}}
{{- end -}} {{- end -}}
{{- end -}}
{{- end -}} {{- end -}}
{{- partial "shortcodes/card" (dict {{- partial "shortcodes/card" (dict