add loading lazy to image render

This commit is contained in:
Nuno Coração 2024-03-09 15:24:00 +00:00
parent 893687d0d4
commit f421ce16c8

View file

@ -4,7 +4,7 @@
{{ $caption := .Title }} {{ $caption := .Title }}
{{ if findRE "^https?" $url.Scheme }} {{ if findRE "^https?" $url.Scheme }}
<figure> <figure>
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img class="my-0 rounded-md" loading="lazy" src="{{ $url.String }}" alt="{{ $altText }}" />
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ else }} {{ else }}
@ -19,12 +19,14 @@
{{ if $disableImageOptimization }} {{ if $disableImageOptimization }}
<img <img
class="my-0 rounded-md" class="my-0 rounded-md"
loading="lazy"
src="{{ .RelPermalink }}" src="{{ .RelPermalink }}"
alt="{{ $altText }}" alt="{{ $altText }}"
/> />
{{ else }} {{ else }}
<img <img
class="my-0 rounded-md" class="my-0 rounded-md"
loading="lazy"
srcset=" srcset="
{{ (.Resize "330x").RelPermalink }} 330w, {{ (.Resize "330x").RelPermalink }} 330w,
{{ (.Resize "660x").RelPermalink }} 660w, {{ (.Resize "660x").RelPermalink }} 660w,
@ -38,7 +40,7 @@
</figure> </figure>
{{ else }} {{ else }}
<figure> <figure>
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img class="my-0 rounded-md" loading="lazy" src="{{ $url.String }}" alt="{{ $altText }}" />
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ end }} {{ end }}