Skip to content

Commit

Permalink
fix: check if the image resource media type is avif and print error w…
Browse files Browse the repository at this point in the history
…hen necessary
  • Loading branch information
razonyang committed Mar 15, 2024
1 parent 59b9b9f commit 8afe41e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions layouts/partials/images/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@
{{- end }}
{{- with $res }}
{{- $originalSrc = ($res | fingerprint "md5").RelPermalink }}
{{- $originalWidth = $res.Width }}
{{- $originalHeight = $res.Height }}
{{/* 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. */}}
{{- if and $width $height }}
{{- $res = .Resize (printf "%sx%s" (strings.TrimSuffix "px" $width) (strings.TrimSuffix "px" $height)) }}
Expand Down

0 comments on commit 8afe41e

Please sign in to comment.