Add retina support for image shortcodes

This commit is contained in:
Joe Hutchinson
2021-02-04 00:51:38 -05:00
parent 173e1e208e
commit ea5999223a
2 changed files with 16 additions and 14 deletions

View File

@@ -1,11 +1,10 @@
<picture>
{{ if (fileExists (printf "%s/%s" "content" (replace (.Get "src") (path.Ext (.Get "src")) ".webp"))) -}}
<source srcset="{{ replace (.Get "src") (path.Ext (.Get "src")) ".webp" | absURL }}" type="image/webp">
{{- end }}
{{ $image := $.Page.Resources.GetMatch (.Get "src") }}
{{ if gt $image.Width 800 -}}
{{ $resized := $image.Resize "800x Lanczos" }}
<source srcset="{{ $resized.Permalink }}">
{{ if gt $image.Width 711 -}}
{{ $resized := $image.Resize "711x Lanczos" }}
{{ $resized_2 := $image.Resize "1422x Lanczos" }}
{{ $resized_3 := $image.Resize "2133x Lanczos" }}
<source srcset="{{ $resized.Permalink }} 1x, {{ $resized_2.Permalink }} 2x, {{ $resized_3.Permalink }} 3x">
<img src="{{ $resized.Permalink }}" {{ if isset .Params "alt" -}} alt="{{ .Get "alt"}}" {{- end }}>
{{ else }}
<source srcset="{{ $image.Permalink }}">