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

Fix <picture> shortcode to skip missing images

This commit is contained in:
Rohan Kumar 2021-01-28 13:08:21 -08:00
parent 790f7f70ef
commit e4b8b88a79
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479

View file

@ -1,46 +1,47 @@
{{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) | resources.Fingerprint "md5" -}} {{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) -}}
{{ $light_webp := resources.GetMatch (printf "/p/%s.webp" (.Get "name")) | resources.Fingerprint "md5" -}} {{ $light_webp := resources.GetMatch (printf "/p/%s.webp" (.Get "name")) -}}
{{ $light_avif := resources.GetMatch (printf "/p/%s.avif" (.Get "name")) | resources.Fingerprint "md5" -}} {{ $light_avif := resources.GetMatch (printf "/p/%s.avif" (.Get "name")) -}}
{{ $dark_png := resources.GetMatch (printf "/p/%s_dark.png" (.Get "name")) | resources.Fingerprint "md5" -}} {{ $dark_png := resources.GetMatch (printf "/p/%s_dark.png" (.Get "name")) -}}
{{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) | resources.Fingerprint "md5" -}} {{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) -}}
{{ $dark_avif := resources.GetMatch (printf "/p/%s_dark.avif" (.Get "name")) | resources.Fingerprint "md5" -}} {{ $dark_avif := resources.GetMatch (printf "/p/%s_dark.avif" (.Get "name")) -}}
<picture> <picture>
{{ with $dark_avif -}} {{ with $dark_avif -}}
{{ $dark_avif_src := . | resources.Fingerprint "md5" -}}
<source <source
srcset="{{ .RelPermalink }}" srcset="{{ $dark_avif_src.RelPermalink }}"
type="image/avif" type="image/avif"
media="(prefers-color-scheme: dark)"> media="(prefers-color-scheme: dark)">
{{ end -}} {{ end -}}
{{ with $dark_webp -}} {{ with $dark_webp -}}
{{ $dark_webp_src := . | resources.Fingerprint "md5" -}}
<source <source
srcset="{{ .RelPermalink }}" srcset="{{ $dark_webp_src.RelPermalink }}"
type="image/webp" type="image/webp"
media="(prefers-color-scheme: dark)"> media="(prefers-color-scheme: dark)">
{{ end -}} {{ end -}}
{{ with $dark_png -}} {{ with $dark_png -}}
{{ $dark_png_src := . | resources.Fingerprint "md5" -}}
<source <source
srcset="{{ .RelPermalink }}" srcset="{{ $dark_png_src.RelPermalink }}"
type="image/png" type="image/png"
media="(prefers-color-scheme: dark)"> media="(prefers-color-scheme: dark)">
{{ end -}} {{ end -}}
{{ with $light_avif -}} {{ with $light_avif -}}
{{ $light_avif_src := . | resources.Fingerprint "md5" -}}
<source <source
srcset="{{ .RelPermalink }}" srcset="{{ $light_avif_src.RelPermalink }}"
type="image/avif" type="image/avif">
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)">
{{ end -}} {{ end -}}
{{ with $light_webp -}} {{ with $light_webp -}}
{{ $light_webp_src := . | resources.Fingerprint "md5" -}}
<source <source
srcset="{{ .RelPermalink }}" srcset="{{ $light_webp_src.RelPermalink }}"
type="image/webp" type="image/webp">
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)">
{{ end -}} {{ end -}}
{{ with $light_png -}} {{ $light_png_src := $light_png | resources.Fingerprint "md5" -}}
<source <source
srcset="{{ .RelPermalink }}" srcset="{{ $light_png_src.RelPermalink }}"
type="image/png" type="image/png">
media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)">
{{ end -}}
<img <img
width="{{ $light_png.Width }}" width="{{ $light_png.Width }}"
src="{{ $light_png.RelPermalink }}" alt='{{ .Get "alt" }}'> src="{{ $light_png.RelPermalink }}" alt='{{ .Get "alt" }}'>