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

Picture shortcode: support JPEG-XL, async decoding

This commit is contained in:
Rohan Kumar 2021-06-27 19:25:58 -07:00
parent 322e7ef575
commit db3af81979
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479

View file

@ -2,10 +2,12 @@
{{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) -}} {{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) -}}
{{ $light_webp := resources.GetMatch (printf "/p/%s.webp" (.Get "name")) -}} {{ $light_webp := resources.GetMatch (printf "/p/%s.webp" (.Get "name")) -}}
{{ $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")) -}}
{{ $dark_svg := resources.GetMatch (printf "/p/%s_dark.svg" (.Get "name")) -}} {{ $dark_svg := resources.GetMatch (printf "/p/%s_dark.svg" (.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_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) -}} {{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) -}}
{{ $dark_avif := resources.GetMatch (printf "/p/%s_dark.avif" (.Get "name")) -}} {{ $dark_avif := resources.GetMatch (printf "/p/%s_dark.avif" (.Get "name")) -}}
{{ $dark_jxl := resources.GetMatch (printf "/p/%s_dark.jxl" (.Get "name")) -}}
<picture> <picture>
{{ with $dark_svg -}} {{ with $dark_svg -}}
{{ $dark_svg_src := . | resources.Fingerprint "md5" -}} {{ $dark_svg_src := . | resources.Fingerprint "md5" -}}
@ -14,6 +16,13 @@
type="image/svg+xml" type="image/svg+xml"
media="(prefers-color-scheme: dark)"> media="(prefers-color-scheme: dark)">
{{ end -}} {{ end -}}
{{ with $dark_jxl -}}
{{ $dark_jxl_src := . | resources.Fingerprint "md5" -}}
<source
srcset="{{ $dark_jxl_src.RelPermalink }}"
type="image/jxl"
media="(prefers-color-scheme: dark)">
{{ end -}}
{{ with $dark_avif -}} {{ with $dark_avif -}}
{{ $dark_avif_src := . | resources.Fingerprint "md5" -}} {{ $dark_avif_src := . | resources.Fingerprint "md5" -}}
<source <source
@ -41,6 +50,12 @@
srcset="{{ $light_svg_src.RelPermalink }}" srcset="{{ $light_svg_src.RelPermalink }}"
type="image/svg+xml"> type="image/svg+xml">
{{ end -}} {{ end -}}
{{ with $light_jxl -}}
{{ $light_jxl_src := . | resources.Fingerprint "md5" -}}
<source
srcset="{{ $light_jxl_src.RelPermalink }}"
type="image/jxl">
{{ end -}}
{{ with $light_avif -}} {{ with $light_avif -}}
{{ $light_avif_src := . | resources.Fingerprint "md5" -}} {{ $light_avif_src := . | resources.Fingerprint "md5" -}}
<source <source
@ -59,5 +74,6 @@
type="image/png"> type="image/png">
<img <img
width="{{ $light_png.Width }}" height="{{ $light_png.Height }}" width="{{ $light_png.Width }}" height="{{ $light_png.Height }}"
src="{{ $light_png.RelPermalink }}" alt='{{ .Get "alt" }}'> src="{{ $light_png.RelPermalink }}" alt='{{ .Get "alt" }}'
decoding="async">
</picture> </picture>