From 1f8fb5f83acc4fc1f8a587cea3b6bb792edfdb68 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 27 Jan 2021 13:47:46 -0800 Subject: [PATCH] New shortcode for This shortcode handles dark/light variants of AVIF, WebP, and PNG images. --- layouts/shortcodes/picture.html | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 layouts/shortcodes/picture.html diff --git a/layouts/shortcodes/picture.html b/layouts/shortcodes/picture.html new file mode 100644 index 0000000..a0ba134 --- /dev/null +++ b/layouts/shortcodes/picture.html @@ -0,0 +1,47 @@ +{{ $light_png := resources.GetMatch (printf "/p/%s.png" (.Get "name")) | resources.Fingerprint "md5" -}} +{{ $light_webp := resources.GetMatch (printf "/p/%s.webp" (.Get "name")) | resources.Fingerprint "md5" -}} +{{ $light_avif := resources.GetMatch (printf "/p/%s.avif" (.Get "name")) | resources.Fingerprint "md5" -}} +{{ $dark_png := resources.GetMatch (printf "/p/%s_dark.png" (.Get "name")) | resources.Fingerprint "md5" -}} +{{ $dark_webp := resources.GetMatch (printf "/p/%s_dark.webp" (.Get "name")) | resources.Fingerprint "md5" -}} +{{ $dark_avif := resources.GetMatch (printf "/p/%s_dark.avif" (.Get "name")) | resources.Fingerprint "md5" -}} + + {{ with $dark_avif -}} + + {{ end -}} + {{ with $dark_webp -}} + + {{ end -}} + {{ with $dark_png -}} + + {{ end -}} + {{ with $light_avif -}} + + {{ end -}} + {{ with $light_webp -}} + + {{ end -}} + {{ with $light_png -}} + + {{ end -}} + {{ .Get "alt" }} +