1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-27 14:12:09 +00:00

Update picture shortcode to support GIF

This commit is contained in:
Rohan Kumar 2024-04-19 18:55:45 -04:00
parent 25ad6f3cdb
commit e591c9d1ee
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479

View file

@ -1,3 +1,4 @@
{{ $light_gif := resources.GetMatch (printf "/p/%s.gif" (.Get "name")) -}}
{{ $light_svg := resources.GetMatch (printf "/p/%s.svg" (.Get "name")) -}} {{ $light_svg := resources.GetMatch (printf "/p/%s.svg" (.Get "name")) -}}
{{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) -}} {{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) -}}
{{ $light_jpg := resources.GetMatch (printf "/p/%s.jpg" (.Get "name")) -}} {{ $light_jpg := resources.GetMatch (printf "/p/%s.jpg" (.Get "name")) -}}
@ -5,6 +6,7 @@
{{ $light_avif := resources.GetMatch (printf "/p/%s.avif" (.Get "name")) -}} {{ $light_avif := resources.GetMatch (printf "/p/%s.avif" (.Get "name")) -}}
{{ $light_jxl := resources.GetMatch (printf "/p/%s.jxl" (.Get "name")) -}} {{ $light_jxl := resources.GetMatch (printf "/p/%s.jxl" (.Get "name")) -}}
{{ $dark_svg := resources.GetMatch (printf "/p/%s_dark.svg" (.Get "name")) -}} {{ $dark_svg := resources.GetMatch (printf "/p/%s_dark.svg" (.Get "name")) -}}
{{ $dark_gif := resources.GetMatch (printf "/p/%s_dark.gif" (.Get "name")) -}}
{{ $dark_png := resources.GetMatch (printf "/p/%s_dark.png" (.Get "name")) -}} {{ $dark_png := resources.GetMatch (printf "/p/%s_dark.png" (.Get "name")) -}}
{{ $dark_jpg := resources.GetMatch (printf "/p/%s_dark.jpg" (.Get "name")) -}} {{ $dark_jpg := resources.GetMatch (printf "/p/%s_dark.jpg" (.Get "name")) -}}
{{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) -}} {{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) -}}
@ -19,12 +21,30 @@
{{- $orig_img_type = "image/jpeg" -}} {{- $orig_img_type = "image/jpeg" -}}
{{- $orig_img = $light_jpg -}} {{- $orig_img = $light_jpg -}}
{{- end -}} {{- end -}}
{{- with $light_gif -}}
{{- $orig_img_type = "image/gif" -}}
{{- $orig_img = $light_gif -}}
{{- end -}}
{{- with $dark_jpg -}} {{- with $dark_jpg -}}
{{- $orig_img_dark_type = "image/jpeg" -}} {{- $orig_img_dark_type = "image/jpeg" -}}
{{- $orig_img_dark = $dark_jpg -}} {{- $orig_img_dark = $dark_jpg -}}
{{- end -}} {{- end -}}
{{- $img_width := $orig_img.Width -}} {{- with $dark_gif -}}
{{- $img_height := $orig_img.Height -}} {{- $orig_img_dark_type = "image/gif" -}}
{{- $orig_img_dark = $dark_gif -}}
{{- end -}}
{{- $img_width := 0 -}}
{{- with .Get "width" -}}
{{- $img_width = . -}}
{{- else -}}
{{- $img_width = $orig_img.Width -}}
{{- end -}}
{{- $img_height := 0 -}}
{{- with .Get "height" -}}
{{- $img_height = . -}}
{{- else -}}
{{- $img_height = $orig_img.Height -}}
{{- end -}}
{{- with (.Get "sf") -}} {{- with (.Get "sf") -}}
{{- $img_width = (mul $img_width . | math.Round) -}} {{- $img_width = (mul $img_width . | math.Round) -}}
{{- $img_height = (mul $img_height . | math.Round ) -}} {{- $img_height = (mul $img_height . | math.Round ) -}}