|
@@ -1,6 +1,11 @@
|
|
|
{{/* Enable image to be loaded from local page dir or media library at `static/img/`. */}}
|
|
|
-{{ $image_src := .Get "src" }}
|
|
|
-{{ if .Get "library" }}
|
|
|
+
|
|
|
+{{ $asset := (.Page.Resources.ByType "image").GetMatch (.Get "src") }}
|
|
|
+{{ $image_src := (.Get "src") }}
|
|
|
+{{ if $asset }}
|
|
|
+ {{ $asset2 := $asset.Fit "2000x2000" }}
|
|
|
+ {{ $image_src = $asset2.RelPermalink }}
|
|
|
+{{ else if .Get "library" }}
|
|
|
{{ $image_src = printf "img/%s" $image_src | relURL }}
|
|
|
{{ end }}
|
|
|
|
|
@@ -21,7 +26,12 @@
|
|
|
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{.}}"{{ end }}{{ with .Get "rel" }} rel="{{.}}"{{ end }}>
|
|
|
{{ end -}}
|
|
|
|
|
|
-<img data-src="{{$image_src}}" class="lazyload" alt="{{ with .Get "alt" }}{{.}}{{end}}" {{ with .Get "width" }}width="{{.}}" {{end}}{{ with .Get "height" }}height="{{.}}" {{end}}>
|
|
|
+{{/* Lazy load only when we know image dimensions in order to preserve anchor linking. */}}
|
|
|
+{{ if $asset }}
|
|
|
+ <img data-src="{{$image_src}}" class="lazyload" alt="{{ with .Get "alt" }}{{.}}{{end}}" width="{{ (.Get "width") | default $asset.Width }}" height="{{ (.Get "height") | default $asset.Height }}">
|
|
|
+{{ else }}
|
|
|
+ <img data-src="{{$image_src}}" alt="{{ with .Get "alt" }}{{.}}{{end}}" {{ with .Get "width" }}width="{{.}}" {{end}}{{ with .Get "height" }}height="{{.}}" class="lazyload"{{end}}>
|
|
|
+{{ end }}
|
|
|
|
|
|
{{- if or $lightbox (.Get "link") }}</a>{{ end }}
|
|
|
|