blogotheme/layouts/shortcodes/image.html

14 lines
760 B
HTML
Raw Permalink Normal View History

2021-01-03 14:33:26 +01:00
<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 }}">
<img src="{{ $resized.Permalink }}" {{ if isset .Params "alt" -}} alt="{{ .Get "alt"}}" {{- end }}>
{{ else }}
<source srcset="{{ $image.Permalink }}">
<img src="{{ $image.Permalink }}" {{ if isset .Params "alt" -}} alt="{{ .Get "alt"}}" {{- end }}>
{{- end}}
</picture>