1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-09-20 12:12:09 +00:00
seirdy.one/layouts/shortcodes/picture.html
2021-01-28 13:08:21 -08:00

48 lines
1.7 KiB
HTML

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