portails/layouts/_default/_markup/render-image.html

36 lines
1.6 KiB
HTML
Raw Normal View History

2022-01-14 11:16:45 +01:00
{{ $image := "" -}}
{{ if (urls.Parse .Destination).IsAbs }}
{{ $image = resources.GetRemote .Destination -}}
{{ else -}}
{{ $image = .Page.Resources.GetMatch .Destination -}}
{{ end -}}
2022-01-14 10:42:40 +01:00
{{ with $image -}}
{{ $lqip := $image.Resize site.Params.lqipWidth -}}
2021-09-23 08:23:25 +02:00
2022-01-14 10:42:40 +01:00
{{ $imgSrc := "" -}}
{{ $imgSrcSet := slice -}}
2021-09-23 08:23:25 +02:00
2022-01-14 10:42:40 +01:00
{{ $widths := site.Params.landscapePhotoWidths -}}
{{ if gt $image.Height $image.Width -}}
{{ $widths = site.Params.portraitPhotoWidths -}}
{{ end -}}
2021-09-23 08:23:25 +02:00
2022-01-14 10:42:40 +01:00
{{ range $widths -}}
{{ $srcUrl := (printf "%dx" . | $image.Resize).Permalink -}}
{{ if eq $imgSrc "" -}}{{ $imgSrc = $srcUrl -}}{{ end -}}
{{ $imgSrcSet = $imgSrcSet | append (printf "%s %dw" $srcUrl .) -}}
{{ end -}}
{{ $imgSrcSet = (delimit $imgSrcSet ",") -}}
2021-09-23 08:23:25 +02:00
2022-01-14 10:42:40 +01:00
{{ if gt $image.Width site.Params.smallLimit -}}
<figure class="figure">
<img class="figure-img img-fluid lazyload blur-up" data-sizes="auto" src="{{ $lqip.Permalink }}" data-srcset="{{ $imgSrcSet }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $.Text }}">
<noscript><img class="figure-img img-fluid" sizes="100vw" srcset="{{ $imgSrcSet }}" src="{{ $image.Permalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $.Text }}"></noscript>
{{ with $.Title }}<figcaption class="figure-caption">{{ . | safeHTML }}</figcaption>{{ end -}}
</figure>
{{ else -}}
<img class="img-fluid lazyload blur-up" src="{{ $lqip.Permalink }}" data-src="{{ $image.Permalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" alt="{{ $.Text }}">
{{ end -}}
2021-09-23 08:23:25 +02:00
{{ else -}}
2022-01-14 10:42:40 +01:00
{{ erroridf "image-not-found" "Image not found" -}}
{{ end -}}