From 82a44935bee3c2ff521a8743a1a6a1bfb47a2ca7 Mon Sep 17 00:00:00 2001 From: Tomy Hsieh Date: Mon, 8 May 2023 17:04:55 +0700 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20feat:=20Lazy=20load=20image=20b?= =?UTF-8?q?y=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/_default/_markup/render-image.html | 1 + 1 file changed, 1 insertion(+) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 9c7096dc..2b5974d0 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -32,6 +32,7 @@ {{ end }} {{ end }} alt="{{ $altText }}" + loading="lazy" /> {{ with $caption }}
{{ . | markdownify }}
{{ end }} From adf7f6f224caa30e0696ca5b7d5ac294229abc99 Mon Sep 17 00:00:00 2001 From: Tomy Hsieh Date: Sat, 27 May 2023 05:26:57 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20feat:=20Lazy=20load=20image=20i?= =?UTF-8?q?n=20all=20places?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/_default/_markup/render-image.html | 4 ++-- layouts/_default/single.html | 1 + layouts/partials/article-link.html | 1 + layouts/partials/author.html | 1 + layouts/partials/home/profile.html | 1 + layouts/partials/logo.html | 1 + layouts/shortcodes/figure.html | 1 + layouts/shortcodes/screenshot.html | 1 + 8 files changed, 9 insertions(+), 2 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 2b5974d0..83ecf482 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -3,7 +3,7 @@ {{ $caption := .Title }} {{ if findRE "^https?" $url.Scheme }}
- {{ $altText }} + {{ $altText }} {{ with $caption }}
{{ . | markdownify }}
{{ end }}
{{ else }} @@ -38,7 +38,7 @@ {{ else }}
- {{ $altText }} + {{ $altText }} {{ with $caption }}
{{ . | markdownify }}
{{ end }}
{{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 70e8fe88..06ee2dfd 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -31,6 +31,7 @@ {{ end }} {{ end }} alt="{{ $.Params.featureAlt | default $.Params.coverAlt | default "" }}" + loading="lazy" /> {{ with $.Params.coverCaption }}
{{ . | markdownify }}
diff --git a/layouts/partials/article-link.html b/layouts/partials/article-link.html index 330cc07f..93c24b18 100644 --- a/layouts/partials/article-link.html +++ b/layouts/partials/article-link.html @@ -23,6 +23,7 @@ 160w, {{- (.Fill "320x240 smart").RelPermalink }} 2x" src="{{ (.Fill "160x120 smart").RelPermalink }}" {{ end }} + loading="lazy" /> diff --git a/layouts/partials/author.html b/layouts/partials/author.html index d482d3a6..5aae1f8d 100644 --- a/layouts/partials/author.html +++ b/layouts/partials/author.html @@ -10,6 +10,7 @@ height="96" alt="{{ $.Site.Author.name | default "Author" }}" src="{{ $authorImage.RelPermalink }}" + loading="lazy" /> {{ end }} {{ end }} diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index 93ce2462..ca465a23 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -14,6 +14,7 @@ height="144" alt="{{ $.Site.Author.name | default "Author" }}" src="{{ $authorImage.RelPermalink }}" + loading="lazy" /> {{ end }} {{ end }} diff --git a/layouts/partials/logo.html b/layouts/partials/logo.html index ee119168..4c669a57 100644 --- a/layouts/partials/logo.html +++ b/layouts/partials/logo.html @@ -9,6 +9,7 @@ height="{{ div $logo.Height 2 }}" class="max-h-[10rem] max-w-[10rem] object-scale-down object-left{{ if $logo_dark }} hidden dark:flex{{ end }}" alt="{{ .Site.Title }}" + loading="lazy" /> {{- if $logo_dark }} {{ $altText }} Date: Sat, 27 May 2023 05:31:23 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20feat:=20Make=20image=20lazy=20l?= =?UTF-8?q?oad=20togglable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/_default/params.toml | 1 + layouts/_default/_markup/render-image.html | 22 +++++++++++++++++++--- layouts/_default/single.html | 4 +++- layouts/partials/article-link.html | 4 +++- layouts/partials/author.html | 4 +++- layouts/partials/home/profile.html | 4 +++- layouts/partials/logo.html | 7 ++++++- layouts/shortcodes/figure.html | 4 +++- layouts/shortcodes/screenshot.html | 4 +++- 9 files changed, 44 insertions(+), 10 deletions(-) diff --git a/config/_default/params.toml b/config/_default/params.toml index 61e2b936..c79ad081 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -11,6 +11,7 @@ autoSwitchAppearance = true enableSearch = false enableCodeCopy = false +enableImageLazyLoading = true # robots = "" fingerprintAlgorithm = "sha256" diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 83ecf482..c2b220ad 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -3,7 +3,14 @@ {{ $caption := .Title }} {{ if findRE "^https?" $url.Scheme }}
- {{ $altText }} + {{ $altText }} {{ with $caption }}
{{ . | markdownify }}
{{ end }}
{{ else }} @@ -32,13 +39,22 @@ {{ end }} {{ end }} alt="{{ $altText }}" - loading="lazy" + {{ if .Site.Params.enableImageLazyLoading | default true }} + loading="lazy" + {{ end }} /> {{ with $caption }}
{{ . | markdownify }}
{{ end }} {{ else }}
- {{ $altText }} + {{ $altText }} {{ with $caption }}
{{ . | markdownify }}
{{ end }}
{{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 06ee2dfd..9f3c52cd 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -31,7 +31,9 @@ {{ end }} {{ end }} alt="{{ $.Params.featureAlt | default $.Params.coverAlt | default "" }}" - loading="lazy" + {{ if .Site.Params.enableImageLazyLoading | default true }} + loading="lazy" + {{ end }} /> {{ with $.Params.coverCaption }}
{{ . | markdownify }}
diff --git a/layouts/partials/article-link.html b/layouts/partials/article-link.html index 93c24b18..f934bae0 100644 --- a/layouts/partials/article-link.html +++ b/layouts/partials/article-link.html @@ -23,7 +23,9 @@ 160w, {{- (.Fill "320x240 smart").RelPermalink }} 2x" src="{{ (.Fill "160x120 smart").RelPermalink }}" {{ end }} - loading="lazy" + {{ if .Site.Params.enableImageLazyLoading | default true }} + loading="lazy" + {{ end }} /> diff --git a/layouts/partials/author.html b/layouts/partials/author.html index 5aae1f8d..ca7b17bc 100644 --- a/layouts/partials/author.html +++ b/layouts/partials/author.html @@ -10,7 +10,9 @@ height="96" alt="{{ $.Site.Author.name | default "Author" }}" src="{{ $authorImage.RelPermalink }}" - loading="lazy" + {{ if .Site.Params.enableImageLazyLoading | default true }} + loading="lazy" + {{ end }} /> {{ end }} {{ end }} diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index ca465a23..324e31f1 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -14,7 +14,9 @@ height="144" alt="{{ $.Site.Author.name | default "Author" }}" src="{{ $authorImage.RelPermalink }}" - loading="lazy" + {{ if .Site.Params.enableImageLazyLoading | default true }} + loading="lazy" + {{ end }} /> {{ end }} {{ end }} diff --git a/layouts/partials/logo.html b/layouts/partials/logo.html index 4c669a57..1fefceb7 100644 --- a/layouts/partials/logo.html +++ b/layouts/partials/logo.html @@ -9,7 +9,9 @@ height="{{ div $logo.Height 2 }}" class="max-h-[10rem] max-w-[10rem] object-scale-down object-left{{ if $logo_dark }} hidden dark:flex{{ end }}" alt="{{ .Site.Title }}" - loading="lazy" + {{ if .Site.Params.enableImageLazyLoading | default true }} + loading="lazy" + {{ end }} /> {{- if $logo_dark }} {{ .Site.Title }} {{- end}} diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 60a9edf8..b6d14289 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -11,7 +11,9 @@ {{ $altText }} Date: Sat, 27 May 2023 05:37:02 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=9B=A0=20fix:=20Syntax=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/_default/_markup/render-image.html | 7 ++++--- layouts/_default/single.html | 2 +- layouts/partials/article-link.html | 2 +- layouts/partials/author.html | 2 +- layouts/partials/home/profile.html | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index c2b220ad..e2009a06 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,13 +1,14 @@ {{ $url := urls.Parse .Destination }} {{ $altText := .Text }} {{ $caption := .Title }} +{{ $lazyLoad := $.Page.Site.Params.enableImageLazyLoading | default true }} {{ if findRE "^https?" $url.Scheme }}
{{ $altText }} @@ -39,7 +40,7 @@ {{ end }} {{ end }} alt="{{ $altText }}" - {{ if .Site.Params.enableImageLazyLoading | default true }} + {{ if $lazyLoad }} loading="lazy" {{ end }} /> @@ -51,7 +52,7 @@ class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" - {{ if .Site.Params.enableImageLazyLoading | default true }} + {{ if $lazyLoad }} loading="lazy" {{ end }} /> diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 9f3c52cd..90c5110b 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -31,7 +31,7 @@ {{ end }} {{ end }} alt="{{ $.Params.featureAlt | default $.Params.coverAlt | default "" }}" - {{ if .Site.Params.enableImageLazyLoading | default true }} + {{ if $.Site.Params.enableImageLazyLoading | default true }} loading="lazy" {{ end }} /> diff --git a/layouts/partials/article-link.html b/layouts/partials/article-link.html index f934bae0..689bdf71 100644 --- a/layouts/partials/article-link.html +++ b/layouts/partials/article-link.html @@ -23,7 +23,7 @@ 160w, {{- (.Fill "320x240 smart").RelPermalink }} 2x" src="{{ (.Fill "160x120 smart").RelPermalink }}" {{ end }} - {{ if .Site.Params.enableImageLazyLoading | default true }} + {{ if $.Site.Params.enableImageLazyLoading | default true }} loading="lazy" {{ end }} /> diff --git a/layouts/partials/author.html b/layouts/partials/author.html index ca7b17bc..2d29aa82 100644 --- a/layouts/partials/author.html +++ b/layouts/partials/author.html @@ -10,7 +10,7 @@ height="96" alt="{{ $.Site.Author.name | default "Author" }}" src="{{ $authorImage.RelPermalink }}" - {{ if .Site.Params.enableImageLazyLoading | default true }} + {{ if $.Site.Params.enableImageLazyLoading | default true }} loading="lazy" {{ end }} /> diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index 324e31f1..24fb6f63 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -14,7 +14,7 @@ height="144" alt="{{ $.Site.Author.name | default "Author" }}" src="{{ $authorImage.RelPermalink }}" - {{ if .Site.Params.enableImageLazyLoading | default true }} + {{ if $.Site.Params.enableImageLazyLoading | default true }} loading="lazy" {{ end }} /> From 16c56d2129edb0c8109410cae5e196250c4a7c5f Mon Sep 17 00:00:00 2001 From: Tomy Hsieh Date: Sat, 27 May 2023 05:55:29 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=96=20docs:=20Add=20information=20?= =?UTF-8?q?for=20`enableImageLazyLoading`=20param?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exampleSite/config/_default/params.toml | 1 + exampleSite/content/docs/configuration/index.md | 1 + 2 files changed, 2 insertions(+) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 21378072..d828f120 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -11,6 +11,7 @@ autoSwitchAppearance = true enableSearch = true enableCodeCopy = true +enableImageLazyLoading = true # robots = "" fingerprintAlgorithm = "sha256" diff --git a/exampleSite/content/docs/configuration/index.md b/exampleSite/content/docs/configuration/index.md index 8bb275ca..c341466a 100644 --- a/exampleSite/content/docs/configuration/index.md +++ b/exampleSite/content/docs/configuration/index.md @@ -129,6 +129,7 @@ Many of the article defaults here can be overridden on a per article basis by sp |`autoSwitchAppearance`|`true`|Whether the theme appearance automatically switches based upon the visitor's operating system preference. Set to `false` to force the site to always use the `defaultAppearance`.| |`enableSearch`|`false`|Whether site search is enabled. Set to `true` to enable search functionality. Note that the search feature depends on the `outputs.home` setting in the [site configuration](#site-configuration) being set correctly.| |`enableCodeCopy`|`false`|Whether copy-to-clipboard buttons are enabled for `` blocks. The `highlight.noClasses` parameter must be set to `false` for code copy to function correctly. Read more about [other configuration files](#other-configuration-files) below.| +|`enableImageLazyLoading`|`true`|Whether image should be lazy loading.| |`robots`|_Not set_|String that indicates how robots should handle your site. If set, it will be output in the page head. Refer to [Google's docs](https://developers.google.com/search/docs/advanced/robots/robots_meta_tag#directives) for valid values.| |`fingerprintAlgorithm`|`"sha256"`|String that indicates which hashing algorithm is used when fingerprinting assets. Valid options include `md5`, `sha256`, `sha384` and `sha512`.| |`header.layout`|`"basic"`|The layout of the page header and menu. Valid values are `basic`, `hamburger`, `hybrid` or `custom`. When set to `custom`, you must provide your own layout by creating a `/layouts/partials/header/custom.html` file.|