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

Allow svg alts in <picture> shortcode

This commit is contained in:
Rohan Kumar 2021-02-01 22:24:40 -08:00
parent 93846a469b
commit a57f694bb4
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479

View file

@ -1,10 +1,19 @@
{{ $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_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")) -}}
{{ $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")) -}}
<picture> <picture>
{{ with $dark_svg -}}
{{ $dark_svg_src := . | resources.Fingerprint "md5" -}}
<source
srcset="{{ $dark_svg_src.RelPermalink }}"
type="image/svg+xml"
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
@ -26,6 +35,12 @@
type="image/png" type="image/png"
media="(prefers-color-scheme: dark)"> media="(prefers-color-scheme: dark)">
{{ end -}} {{ end -}}
{{ with $light_svg -}}
{{ $light_svg_src := . | resources.Fingerprint "md5" -}}
<source
srcset="{{ $light_svg_src.RelPermalink }}"
type="image/svg+xml">
{{ end -}}
{{ with $light_avif -}} {{ with $light_avif -}}
{{ $light_avif_src := . | resources.Fingerprint "md5" -}} {{ $light_avif_src := . | resources.Fingerprint "md5" -}}
<source <source