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,16 +15,21 @@
{{- $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) -}}
{{/* Retrieve the $image resource from local or global resources */}} {{- with or (.Page.Resources.Get $image) (resources.Get $image) -}}
{{- $processed := .Process $process -}} {{/* .Process does not work on svgs */}}
{{- $width = $processed.Width -}} {{- if (not (eq .MediaType.SubType "svg")) -}}
{{- $height = $processed.Height -}} {{/* Retrieve the $image resource from local or global resources */}}
{{- $image = $processed.RelPermalink -}} {{- $processed := .Process $process -}}
{{ else }} {{- $width = $processed.Width -}}
{{/* Otherwise, use relative link of the image */}} {{- $height = $processed.Height -}}
{{- if hasPrefix $image "/" -}} {{- $image = $processed.RelPermalink -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}} {{- end -}}
{{ else }}
{{/* Otherwise, use relative link of the image */}}
{{- if hasPrefix $image "/" -}}
{{- $image = relURL (strings.TrimPrefix "/" $image) -}}
{{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}