Skip to content

Commit

Permalink
fix: allow using SVG and Avif images, but do not apply any filters on…
Browse files Browse the repository at this point in the history
… them (#59)
  • Loading branch information
razonyang authored Aug 26, 2024
1 parent b0619ee commit 7b8dc1d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions layouts/partials/images/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,23 @@
{{- else }}
{{- $res = $page.Resources.GetMatch $path }}
{{- end }}
{{- $mediaMainType := "" }}
{{- $mediaSubType := "" }}
{{- with $res }}
{{- $mediaMainType = .MediaType.MainType }}
{{- $mediaSubType = .MediaType.SubType }}
{{- end }}
{{/* Check if the image resource is valid. */}}
{{- if and (ne $mediaMainType "") (ne $mediaMainType "image") }}
{{- errorf "the image is invalid: %s" $filename }}
{{- end }}
{{- $unsupportedFormats := slice "avif" "svg" }}
{{- if and (ne $mediaSubType "") (in $unsupportedFormats $mediaSubType) }}
{{/* Leave it as it is for unsupported formats. */}}
{{- $src = ($res | fingerprint "md5").RelPermalink }}
{{- end }}
{{- if and (eq $mediaMainType "image") (not (in $unsupportedFormats $mediaSubType)) }}
{{- $originalSrc = ($res | fingerprint "md5").RelPermalink }}
{{/* Check if the image resource is valid. */}}
{{- if ne $res.MediaType.MainType "image" }}
{{- errorf "the image is invalid: %s" $filename }}
{{- end }}
{{- if in (slice "image/avif") $res.MediaType.Type }}
{{- errorf "the image resource type %q is not supported: %s" $res.MediaType.Type $url.Path }}
{{- end }}
{{- $originalWidth = $res.Width }}
{{- $originalHeight = $res.Height }}
{{/* Resize the image. */}}
Expand Down

0 comments on commit 7b8dc1d

Please sign in to comment.