feat: Lazy load image in all places

pull/552/head
Tomy Hsieh 2023-05-27 05:26:57 +08:00
parent 159aaae1e5
commit adf7f6f224
No known key found for this signature in database
GPG Key ID: 4E6AF0EEDD2205F8
8 changed files with 9 additions and 2 deletions

View File

@ -3,7 +3,7 @@
{{ $caption := .Title }} {{ $caption := .Title }}
{{ if findRE "^https?" $url.Scheme }} {{ if findRE "^https?" $url.Scheme }}
<figure> <figure>
<img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" loading="lazy" />
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ else }} {{ else }}
@ -38,7 +38,7 @@
</figure> </figure>
{{ else }} {{ else }}
<figure> <figure>
<img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" loading="lazy" />
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ end }} {{ end }}

View File

@ -31,6 +31,7 @@
{{ end }} {{ end }}
{{ end }} {{ end }}
alt="{{ $.Params.featureAlt | default $.Params.coverAlt | default "" }}" alt="{{ $.Params.featureAlt | default $.Params.coverAlt | default "" }}"
loading="lazy"
/> />
{{ with $.Params.coverCaption }} {{ with $.Params.coverCaption }}
<figcaption class="mb-6 -mt-3 text-center">{{ . | markdownify }}</figcaption> <figcaption class="mb-6 -mt-3 text-center">{{ . | markdownify }}</figcaption>

View File

@ -23,6 +23,7 @@
160w, {{- (.Fill "320x240 smart").RelPermalink }} 2x" 160w, {{- (.Fill "320x240 smart").RelPermalink }} 2x"
src="{{ (.Fill "160x120 smart").RelPermalink }}" src="{{ (.Fill "160x120 smart").RelPermalink }}"
{{ end }} {{ end }}
loading="lazy"
/> />
</a> </a>
</div> </div>

View File

@ -10,6 +10,7 @@
height="96" height="96"
alt="{{ $.Site.Author.name | default "Author" }}" alt="{{ $.Site.Author.name | default "Author" }}"
src="{{ $authorImage.RelPermalink }}" src="{{ $authorImage.RelPermalink }}"
loading="lazy"
/> />
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -14,6 +14,7 @@
height="144" height="144"
alt="{{ $.Site.Author.name | default "Author" }}" alt="{{ $.Site.Author.name | default "Author" }}"
src="{{ $authorImage.RelPermalink }}" src="{{ $authorImage.RelPermalink }}"
loading="lazy"
/> />
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -9,6 +9,7 @@
height="{{ div $logo.Height 2 }}" height="{{ div $logo.Height 2 }}"
class="max-h-[10rem] max-w-[10rem] object-scale-down object-left{{ if $logo_dark }} hidden dark:flex{{ end }}" class="max-h-[10rem] max-w-[10rem] object-scale-down object-left{{ if $logo_dark }} hidden dark:flex{{ end }}"
alt="{{ .Site.Title }}" alt="{{ .Site.Title }}"
loading="lazy"
/> />
{{- if $logo_dark }} {{- if $logo_dark }}
<img <img

View File

@ -11,6 +11,7 @@
<img <img
class="mx-auto my-0 rounded-md" class="mx-auto my-0 rounded-md"
alt="{{ $altText }}" alt="{{ $altText }}"
loading="lazy"
{{ if findRE "^https?" $url.Scheme }} {{ if findRE "^https?" $url.Scheme }}
src="{{ $url.String }}" src="{{ $url.String }}"
{{ else }} {{ else }}

View File

@ -8,6 +8,7 @@
{{- if or (.Get "alt") (.Get "caption") }} {{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify | plainify }}{{ end }}" alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify | plainify }}{{ end }}"
{{- end -}} {{- end -}}
loading="lazy"
width="100%" width="100%"
height="auto" height="auto"
style="max-width:{{ div $image.Width 2 }}px; max-height:{{ div $image.Height 2 }}px;" style="max-width:{{ div $image.Width 2 }}px; max-height:{{ div $image.Height 2 }}px;"