From c91f502e8f95944cf6df837e180bd1f468f5c0a8 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:50:44 +0800 Subject: [PATCH 01/15] feat: add isUrlRemote.html file for remote URL detection --- layouts/partials/function/isUrlRemote.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 layouts/partials/function/isUrlRemote.html diff --git a/layouts/partials/function/isUrlRemote.html b/layouts/partials/function/isUrlRemote.html new file mode 100644 index 000000000..27956da19 --- /dev/null +++ b/layouts/partials/function/isUrlRemote.html @@ -0,0 +1 @@ +{{- return .Host | and .Path | and (strings.HasSuffix .Path "/" | not) -}} From 9b14906acba2c58dbfb459dab3890803823a81f2 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:52:18 +0800 Subject: [PATCH 02/15] refactor: refactor image resource pipeline --- layouts/partials/function/getImage.html | 17 +++++++++++++++++ layouts/partials/function/resource.html | 6 +----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/function/getImage.html diff --git a/layouts/partials/function/getImage.html b/layouts/partials/function/getImage.html new file mode 100644 index 000000000..c893b6d0a --- /dev/null +++ b/layouts/partials/function/getImage.html @@ -0,0 +1,17 @@ +{{- $path:= .Path -}} +{{- $imageResource := 0 -}} + +{{- with dict "Path" $path "Resources" .Resources | partial "function/resource.html" -}} + {{- $imageResource = . -}} +{{- else -}} + {{- $url := urls.Parse .Path -}} + {{- if (eq site.Params.cacheRemoteImages true) | and (partial "function/isUrlRemote.html" $url) | and .Remote -}} + {{- $imageResource = partial "function/getRemoteImage.html" $path -}} + {{- end -}} +{{- end -}} + +{{- if not (and (not (eq $imageResource 0)) (eq $imageResource.ResourceType "image")) -}} + {{- $imageResource = 0 -}} +{{- end -}} + +{{- return $imageResource -}} diff --git a/layouts/partials/function/resource.html b/layouts/partials/function/resource.html index 2d40d4826..d1e7eb4c2 100644 --- a/layouts/partials/function/resource.html +++ b/layouts/partials/function/resource.html @@ -1,6 +1,6 @@ {{- $resource := 0 -}} {{- $url := urls.Parse .Path -}} -{{- if not $url.Host | and $url.Path | and (strings.HasSuffix $url.Path "/" | not) -}} +{{- if not (partial "function/isUrlRemote.html" $url) -}} {{- if .Resources -}} {{- with .Resources.GetMatch $url.Path -}} {{- $resource = . -}} @@ -11,10 +11,6 @@ {{- $resource = . -}} {{- end -}} {{- end -}} -{{- else -}} - {{- if eq site.Params.cacheRemoteImages true -}} - {{- $resource = partial "function/getRemoteImage.html" .Path -}} - {{- end -}} {{- end -}} {{- return $resource -}} From e65b2f9dcd15a89e4900d28cd4c88b343a9c40be Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:54:31 +0800 Subject: [PATCH 03/15] feat: create image handler for dynamic `srcset` generatation --- layouts/partials/function/imageHandler.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 layouts/partials/function/imageHandler.html diff --git a/layouts/partials/function/imageHandler.html b/layouts/partials/function/imageHandler.html new file mode 100644 index 000000000..8ae876c32 --- /dev/null +++ b/layouts/partials/function/imageHandler.html @@ -0,0 +1,20 @@ +{{- $return := 0 -}} +{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" -}} + +{{- if not (eq .Optim true) -}} + {{- warnf .Image.RelPermalink -}} + {{- $return = dict "S" .Image "M" .Image "L" .Image "Optimized" false -}} +{{- else if or + (not (eq site.Params.optimizeImages true)) + (not (dict "Path" .Image.RelPermalink "Suffixes" $suffixList | partial "function/suffixValidation.html")) + -}} + {{- $return = dict "S" .Image "M" .Image "L" .Image "Optimized" true -}} +{{- else -}} + {{- $s := .Image.Resize (site.Params.srcsetSmallResizeMethod | default "700x webp Lanczos q60") -}} + {{- $m := .Image.Resize (site.Params.srcsetDefaultResizeMethod | default "1200x webp Lanczos q60") -}} + {{- $l := .Image.Resize (site.Params.srcsetLargeResizeMethod | default "2000x webp Lanczos q60") -}} + {{- $return = dict "S" $s "M" $m "L" $l "Optimized" true -}} + {{- warnf $m.RelPermalink -}} +{{- end -}} + +{{- return $return -}} From 42090319c08aaf0c969370bc49b9441986e6a07a Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:52:55 +0800 Subject: [PATCH 04/15] refactor: adapt `image.html` to new image pipeline --- layouts/partials/plugin/image.html | 62 ++++++++++++++++++------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/image.html index 5713df055..d7388d392 100644 --- a/layouts/partials/plugin/image.html +++ b/layouts/partials/plugin/image.html @@ -1,30 +1,26 @@ {{- /* lightgallery.js */ -}} -{{- $src := .Src -}} +{{- $default := dict "RelPermalink" .Src -}} +{{- $remote := .Remote | default false -}} +{{- $optimize := .Optim | default false -}} +{{- $small := $default -}} +{{- $large := $default -}} {{- $height := "" -}} {{- $width := "" -}} -{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" -}} -{{- with dict "Path" .Src "Resources" .Resources | partial "function/resource.html" -}} - {{- $src = .RelPermalink -}} - {{- if and - (eq .ResourceType "image") - (dict "Path" $src "Suffixes" $suffixList | partial "function/suffixValidation.html") - -}} - {{- $height = .Height -}} - {{- $width = .Width -}} - {{- end -}} -{{- end -}} +{{- $optimized := false -}} -{{- $small := .SrcSmall | default $src -}} -{{- with dict "Path" .SrcSmall "Resources" .Resources | partial "function/resource.html" -}} - {{- $small = .RelPermalink -}} -{{- end -}} +{{- warnf "%#v" .NoOptim -}} -{{- $large := .SrcLarge | default $src -}} -{{- with dict "Path" .SrcLarge "Resources" .Resources | partial "function/resource.html" -}} - {{- $large = .RelPermalink -}} +{{- with dict "Path" .Src "Resources" .Resources "Remote" $remote | partial "function/getImage.html" -}} + {{- $output := dict "Optim" $optimize "Image" . | partial "function/imageHandler.html" -}} + {{- $small = $output.S -}} + {{- $default = $output.M -}} + {{- $large = $output.L -}} + {{- $optimized = $output.Optimized -}} + {{- $height = $default.Height -}} + {{- $width = $default.Width -}} {{- end -}} -{{- $alt := .Alt | default .Title | default $src -}} +{{- $alt := .Alt | default .Title | default .Src -}} {{- $loading := .Loading | default "lazy" -}} {{- with .Height -}} @@ -36,12 +32,20 @@ {{- end -}} {{- if .Linked -}} - + {{ $alt }} @@ -49,8 +53,16 @@ {{ $alt }} From 8e43e913182ad0ede723c9450be65aafa6f8e8a4 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:55:32 +0800 Subject: [PATCH 05/15] feat: add new configuration options for image optimization --- exampleSite/config/_default/params.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index a23406290..484a68d3f 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -30,6 +30,14 @@ bundle = false # [Experimental] cache remote images, more info: https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 # [试验性功能] 缓存图床图片,详情请见:https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 cacheRemoteImages = false +# [Experimental] generate image srcset attribute with hugo image processing feature. +# [试验性功能] 使用 hugo 图片处理功能生成 srcset 属性 +optimizeImages = true +# [Experimental] resize method for srcset attribute in optimizeImages, more info: https://gohugo.io/content-management/image-processing/#image-processing-options +# [实验性功能] optimizeImages 中 srcset 属性的缩放方法, 详情请见:https://gohugo.io/content-management/image-processing/#image-processing-options +srcsetSmallResizeMethod = "700x webp Lanczos q75" +srcsetDefaultResizeMethod = "1200x webp Lanczos q75" +srcsetLargeResizeMethod = "2000x webp Lanczos q75" # Header config # 页面头部导航栏配置 [header] From 45c602bd35b158f1fc022992c163171f534cf7a6 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:56:21 +0800 Subject: [PATCH 06/15] refactor: update parameters in render and image HTML files --- layouts/_default/_markup/render-image.html | 4 ++-- layouts/shortcodes/image.html | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 31cfa0542..6dc7beb6e 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,13 +1,13 @@ {{- $lightgallery := .Page.Params.lightgallery | default site.Params.Page.lightgallery | default false -}} {{- if .Title -}}
- {{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources "NoOptim" false "NoRemote" false | partial "plugin/image.html" -}}
{{- .Title | safeHTML -}}
{{- else -}}
- {{- dict "Src" .Destination "Title" .Text "Linked" $lightgallery "Resources" .Page.Resources | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Title" .Text "Linked" $lightgallery "Resources" .Page.Resources "Optim" true "Remote" true | partial "plugin/image.html" -}}
{{- end -}} diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html index 4bb365af6..8e23075c7 100644 --- a/layouts/shortcodes/image.html +++ b/layouts/shortcodes/image.html @@ -11,6 +11,8 @@ {{- $options = dict "Width" (.Get "width") | merge $options -}} {{- $options = .Get "linked" | ne false | dict "Linked" | merge $options -}} {{- $options = dict "Rel" (.Get "rel") | merge $options -}} + {{- $options = dict "Optim" true | merge $options -}} + {{- $options = dict "Remote" true | merge $options -}} {{- else -}} {{- $options = cond $caption true false | dict "Linked" | merge $options -}} {{- end -}} From 7acd817c459e5cdfbf7b2dca22faac08923e8b1b Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:57:15 +0800 Subject: [PATCH 07/15] refactor: optimize preview image handling in layout files - Remove unnecessary code for handling image dimensions in `layouts/_default/summary.html` - Remove unnecessary code for handling image dimensions in `layouts/posts/single.html` --- layouts/_default/summary.html | 21 ++------------------- layouts/posts/single.html | 18 +----------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/layouts/_default/summary.html b/layouts/_default/summary.html index 1f38c69d2..459c87717 100644 --- a/layouts/_default/summary.html +++ b/layouts/_default/summary.html @@ -3,27 +3,10 @@
{{- /* Featured image */ -}} {{- $image := $params.featuredImagePreview | default $params.featuredImage -}} - {{- $height := "auto" -}} - {{- $width := "auto" -}} - {{- with .Resources.GetMatch (printf "%s" ($image)) -}} - {{- $image = .RelPermalink -}} - {{- $height = .Height -}} - {{- $width = .Width -}} - {{- end -}} - {{- with .Resources.GetMatch "featured-image" -}} - {{- $image = .RelPermalink -}} - {{- $height = .Height -}} - {{- $width = .Width -}} - {{- end -}} - {{- with .Resources.GetMatch "featured-image-preview" -}} - {{- $image = .RelPermalink -}} - {{- $height = .Height -}} - {{- $width = .Width -}} - {{- end -}} {{- with $image -}} {{- end -}} @@ -103,4 +86,4 @@

{{- end -}} -

\ No newline at end of file + diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 0d03dff5e..4a1c11280 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -146,25 +146,9 @@

{{ . }}

{{- /* Featured image */ -}} {{- $image := $params.featuredimage -}} - {{- $width := "auto" -}} - {{- $height := "auto" -}} - {{- with .Resources.GetMatch (printf "**%s" $params.featuredimage) -}} - {{- if eq .ResourceType "image" -}} - {{- $image = .RelPermalink -}} - {{- $width = .Width -}} - {{- $height = .Height -}} - {{- else -}} - {{- warnf "invalid featured image detected!" -}} - {{- end -}} - {{- end -}} - {{- with .Resources.GetMatch "featured-image" -}} - {{- $image = .RelPermalink -}} - {{- $width = .Width -}} - {{- $height = .Height -}} - {{- end -}} {{- with $image -}} {{- end -}} {{- /* Series list */ -}} From 95def4c0dc2594d3a4074a1f2710709dfd6c2423 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 21:57:38 +0800 Subject: [PATCH 08/15] chore: refine comment about caching remote images --- exampleSite/config/_default/params.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 484a68d3f..32a678989 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -27,7 +27,7 @@ enablePWA = false license = 'CC BY-NC 4.0' # [Experimental] Bundle js bundle = false -# [Experimental] cache remote images, more info: https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 +# [Experimental] cache remote images in markdown, more info: https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 # [试验性功能] 缓存图床图片,详情请见:https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 cacheRemoteImages = false # [Experimental] generate image srcset attribute with hugo image processing feature. From f7aaa2f145b3b82f0eb69939c23f469dada65099 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 22:01:18 +0800 Subject: [PATCH 09/15] fix: set experimental `optimizeImages` to false --- exampleSite/config/_default/params.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 32a678989..cf84e2212 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -32,7 +32,7 @@ bundle = false cacheRemoteImages = false # [Experimental] generate image srcset attribute with hugo image processing feature. # [试验性功能] 使用 hugo 图片处理功能生成 srcset 属性 -optimizeImages = true +optimizeImages = false # [Experimental] resize method for srcset attribute in optimizeImages, more info: https://gohugo.io/content-management/image-processing/#image-processing-options # [实验性功能] optimizeImages 中 srcset 属性的缩放方法, 详情请见:https://gohugo.io/content-management/image-processing/#image-processing-options srcsetSmallResizeMethod = "700x webp Lanczos q75" From 032d6d7c95f995f3b2d16703f12d0d432df8a1c2 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 22:04:23 +0800 Subject: [PATCH 10/15] fix: fix wrong dict key and value in md render hook --- layouts/_default/_markup/render-image.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 6dc7beb6e..9441c0cb9 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,7 +1,7 @@ {{- $lightgallery := .Page.Params.lightgallery | default site.Params.Page.lightgallery | default false -}} {{- if .Title -}}
- {{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources "NoOptim" false "NoRemote" false | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Title" .Text "Caption" .Title "Linked" $lightgallery "Resources" .Page.Resources "Optim" true "Remote" true | partial "plugin/image.html" -}}
{{- .Title | safeHTML -}}
From 5f7b19a44bfeec8352d623911570c324e42eb747 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 28 Jan 2024 22:22:57 +0800 Subject: [PATCH 11/15] fix: remove debug `warnf` --- layouts/partials/function/imageHandler.html | 2 -- layouts/partials/plugin/image.html | 2 -- 2 files changed, 4 deletions(-) diff --git a/layouts/partials/function/imageHandler.html b/layouts/partials/function/imageHandler.html index 8ae876c32..b27d60e3f 100644 --- a/layouts/partials/function/imageHandler.html +++ b/layouts/partials/function/imageHandler.html @@ -2,7 +2,6 @@ {{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" -}} {{- if not (eq .Optim true) -}} - {{- warnf .Image.RelPermalink -}} {{- $return = dict "S" .Image "M" .Image "L" .Image "Optimized" false -}} {{- else if or (not (eq site.Params.optimizeImages true)) @@ -14,7 +13,6 @@ {{- $m := .Image.Resize (site.Params.srcsetDefaultResizeMethod | default "1200x webp Lanczos q60") -}} {{- $l := .Image.Resize (site.Params.srcsetLargeResizeMethod | default "2000x webp Lanczos q60") -}} {{- $return = dict "S" $s "M" $m "L" $l "Optimized" true -}} - {{- warnf $m.RelPermalink -}} {{- end -}} {{- return $return -}} diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/image.html index d7388d392..89c211905 100644 --- a/layouts/partials/plugin/image.html +++ b/layouts/partials/plugin/image.html @@ -8,8 +8,6 @@ {{- $width := "" -}} {{- $optimized := false -}} -{{- warnf "%#v" .NoOptim -}} - {{- with dict "Path" .Src "Resources" .Resources "Remote" $remote | partial "function/getImage.html" -}} {{- $output := dict "Optim" $optimize "Image" . | partial "function/imageHandler.html" -}} {{- $small = $output.S -}} From 4e7c350afb350b75d2f3ab669d10ba5d8bcfc7a2 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Tue, 30 Jan 2024 00:05:07 +0800 Subject: [PATCH 12/15] fix: refactor image.html template attributes --- layouts/partials/plugin/image.html | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/image.html index 89c211905..44b8465aa 100644 --- a/layouts/partials/plugin/image.html +++ b/layouts/partials/plugin/image.html @@ -35,16 +35,16 @@ {{ with .Class }}class="{{ . }}"{{ end }} loading="{{ $loading }}" src="{{ $default.RelPermalink | safeURL }}" + srcset=" {{- if eq $optimized false -}} - srcset="{{ $small.RelPermalink | safeURL }}, {{ $default.RelPermalink | safeURL }} 1.5x, {{ $large.RelPermalink | safeURL }} 2x" + {{ $small.RelPermalink | safeURL }}, {{ $default.RelPermalink | safeURL }} 1.5x, {{ $large.RelPermalink | safeURL }} 2x {{- else -}} - srcset=" - {{ $small.RelPermalink | safeURL }} {{ $small.Width }}w, - {{ $default.RelPermalink | safeURL }} {{ $default.Width }}w, - {{ $large.RelPermalink | safeURL }} {{ $large.Width }}w - " + {{ $small.RelPermalink | safeURL }} {{ $small.Width }}w, + {{ $default.RelPermalink | safeURL }} {{ $default.Width }}w, + {{ $large.RelPermalink | safeURL }} {{ $large.Width }}w {{- end -}} - {{/* sizes="auto" https://github.com/HEIGE-PCloud/DoIt/issues/1165 */}} + " + sizes="auto" alt="{{ $alt }}"{{ with $height }} height="{{ . }}" {{ end }}{{ with $width }} width="{{ . }}" {{ end }}> {{- else -}} @@ -52,16 +52,15 @@ {{ with .Class }}class="{{ . }}"{{ end }} loading="{{ $loading }}" src="{{ $default.RelPermalink | safeURL }}" + srcset=" {{- if eq $optimized false -}} - srcset="{{ $small.RelPermalink | safeURL }}, {{ $default.RelPermalink | safeURL }} 1.5x, {{ $large.RelPermalink | safeURL }} 2x" + {{ $small.RelPermalink | safeURL }}, {{ $default.RelPermalink | safeURL }} 1.5x, {{ $large.RelPermalink | safeURL }} 2x {{- else -}} - srcset=" - {{ $small.RelPermalink | safeURL }} {{ $small.Width }}w, - {{ $default.RelPermalink | safeURL }} {{ $default.Width }}w, - {{ $large.RelPermalink | safeURL }} {{ $large.Width }}w - " + {{ $small.RelPermalink | safeURL }} {{ $small.Width }}w, + {{ $default.RelPermalink | safeURL }} {{ $default.Width }}w, + {{ $large.RelPermalink | safeURL }} {{ $large.Width }}w {{- end -}} - {{/* sizes="auto" https://github.com/HEIGE-PCloud/DoIt/issues/1165 */}} - alt="{{ $alt }}" + " + sizes="auto" title="{{ .Title | default $alt }}"{{ with $height }} height="{{ . }}" {{ end }} {{ with $width }} width="{{ . }}" {{ end }}> {{- end -}} From 13b6069ea3deed59d68d215bedece21bc62bc3ee Mon Sep 17 00:00:00 2001 From: HEIGE-PCloud Date: Wed, 31 Jan 2024 21:05:40 +0000 Subject: [PATCH 13/15] chore: enable optimisation on the exampleSite --- exampleSite/config/_default/params.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index cf84e2212..a0436969b 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -29,10 +29,10 @@ license = ' Date: Wed, 31 Jan 2024 21:07:36 +0000 Subject: [PATCH 14/15] fix: remove sizes=auto 100vw is a reasonable default anyway --- layouts/partials/plugin/image.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/layouts/partials/plugin/image.html b/layouts/partials/plugin/image.html index 44b8465aa..b0beed78c 100644 --- a/layouts/partials/plugin/image.html +++ b/layouts/partials/plugin/image.html @@ -44,7 +44,6 @@ {{ $large.RelPermalink | safeURL }} {{ $large.Width }}w {{- end -}} " - sizes="auto" alt="{{ $alt }}"{{ with $height }} height="{{ . }}" {{ end }}{{ with $width }} width="{{ . }}" {{ end }}> {{- else -}} @@ -61,6 +60,5 @@ {{ $large.RelPermalink | safeURL }} {{ $large.Width }}w {{- end -}} " - sizes="auto" title="{{ .Title | default $alt }}"{{ with $height }} height="{{ . }}" {{ end }} {{ with $width }} width="{{ . }}" {{ end }}> {{- end -}} From 33aa16cb837f90572a76b35c459698ade28e41f0 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Fri, 2 Feb 2024 21:17:21 +0800 Subject: [PATCH 15/15] docs: update documentation on `optimizeImages` and `cacheRemoteImages` --- exampleSite/config/_default/params.toml | 4 ++-- .../posts/theme-documentation-basics/index.en.md | 10 ++++++++-- .../posts/theme-documentation-basics/index.zh-cn.md | 10 ++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index a0436969b..7d910b9a1 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -28,10 +28,10 @@ license = '}} enable PWA support enablePWA = false - # [Experimental] cache remote images, more info: https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 - cacheRemoteImages = false + # [Experimental] cache remote images in markdown, more info: https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 + cacheRemoteImages = true + # [Experimental] generate image srcset attribute with hugo image processing feature. + optimizeImages = true + # [Experimental] resize method for srcset attribute in optimizeImages, more info: https://gohugo.io/content-management/image-processing/#image-processing-options + srcsetSmallResizeMethod = "700x webp Lanczos q75" + srcsetDefaultResizeMethod = "1200x webp Lanczos q75" + srcsetLargeResizeMethod = "2000x webp Lanczos q75" # {{< version 0.2.0 >}} App icon config # {{< version 0.2.14 >}} License information license = 'CC BY-NC 4.0' diff --git a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md index 17845b493..cb71d1c0c 100644 --- a/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md +++ b/exampleSite/content/posts/theme-documentation-basics/index.zh-cn.md @@ -217,8 +217,14 @@ hugo images = ["/logo.png"] # {{< version 0.2.11 >}} 开启 PWA 支持 enablePWA = false - # [试验性功能] 缓存图床图片,详情请见:https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 - cacheRemoteImages = false + # [试验性功能] 缓存markdown中的图片链接到本地,详情请见:https://github.com/HEIGE-PCloud/DoIt/pull/860#issue-1574342372 + cacheRemoteImages = true + # [试验性功能] 使用 hugo 自带的图片处理功能生成 srcset 属性 +optimizeImages = true + # [实验性功能] optimizeImages 中 srcset 属性的缩放方法, 详情请见:https://gohugo.io/content-management/image-processing/#image-processing-options + srcsetSmallResizeMethod = "700x webp Lanczos q75" + srcsetDefaultResizeMethod = "1200x webp Lanczos q75" + srcsetLargeResizeMethod = "2000x webp Lanczos q75" # {{< version 0.2.14 >}} 版权信息 license = 'CC BY-NC 4.0' # {{< version 0.2.0 >}} 应用图标配置