From e482fbe36ab817267336bc7543f53c8d8c14dee4 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sat, 30 Dec 2023 23:59:07 +0800 Subject: [PATCH] :zap: Chore: optimize .Resources variable acquisition in function resources.html --- layouts/_default/_markup/render-image.html | 4 ++-- layouts/_default/_markup/render-link.html | 2 +- layouts/friends/single.html | 2 +- layouts/page/friends.html | 2 +- layouts/partials/function/resource.html | 5 +++-- layouts/partials/head/seo.html | 8 ++++---- layouts/partials/plugin/reward.html | 2 +- layouts/partials/rss/item.html | 2 +- layouts/posts/single.html | 2 +- layouts/shortcodes/image.html | 2 +- layouts/shortcodes/link.html | 2 +- layouts/shortcodes/music.html | 4 ++-- 12 files changed, 19 insertions(+), 18 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 68cc9f92..7f9382a0 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,11 +1,11 @@ {{- if .Title | and .Text -}} - {{- dict "Src" .Destination "Alt" .Text "Caption" .Text "Title" .Title "Linked" true "Resources" .Page.Resources "Responsive" true | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Alt" .Text "Caption" .Text "Title" .Title "Linked" true "Responsive" true | partial "plugin/image.html" -}} {{- .Text | safeHTML -}} {{- else -}} {{- $linked := (eq (.Page.Scratch.Get "params").lightgallery "force") | or (ne .Title "") -}} - {{- dict "Src" .Destination "Alt" .Text "Title" .Title "Linked" $linked "Resources" .Page.Resources "Responsive" true | partial "plugin/image.html" -}} + {{- dict "Src" .Destination "Alt" .Text "Title" .Title "Linked" $linked "Responsive" true | partial "plugin/image.html" -}} {{- end -}} diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html index 8470fb03..26b1ea68 100644 --- a/layouts/_default/_markup/render-link.html +++ b/layouts/_default/_markup/render-link.html @@ -1,5 +1,5 @@ {{- $destination := .Destination -}} -{{- with dict "Path" $destination "Resources" .Page.Resources | partial "function/resource.html" -}} +{{- with dict "Path" $destination | partial "function/resource.html" -}} {{- $destination = .RelPermalink -}} {{- end -}} {{- $options := dict "Destination" $destination "Title" .Title "Content" .Text "ExternalIcon" .Page.Site.Params.externalIcon -}} diff --git a/layouts/friends/single.html b/layouts/friends/single.html index dcd80dc7..c069f7a5 100644 --- a/layouts/friends/single.html +++ b/layouts/friends/single.html @@ -22,7 +22,7 @@ {{ range $index, $friend := .Site.Data.friends }} {{ if $friend.avatar }} - {{- dict "Src" $friend.avatar "Alt" $friend.nickname "Class" "friend-avatar" "Resources" $.Resources | partial "plugin/image.html" -}} + {{- dict "Src" $friend.avatar "Alt" $friend.nickname "Class" "friend-avatar" | partial "plugin/image.html" -}} {{ else }} diff --git a/layouts/page/friends.html b/layouts/page/friends.html index bb12bbc3..c8bd9064 100644 --- a/layouts/page/friends.html +++ b/layouts/page/friends.html @@ -19,7 +19,7 @@ {{ range $index, $friend := .Site.Data.friends }} {{ if $friend.avatar }} - {{- dict "Src" $friend.avatar "Alt" $friend.nickname "Class" "friend-avatar" "Resources" $.Resources | partial "plugin/image.html" -}} + {{- dict "Src" $friend.avatar "Alt" $friend.nickname "Class" "friend-avatar" | partial "plugin/image.html" -}} {{ else }} diff --git a/layouts/partials/function/resource.html b/layouts/partials/function/resource.html index 717a882f..6f7c9919 100644 --- a/layouts/partials/function/resource.html +++ b/layouts/partials/function/resource.html @@ -1,8 +1,9 @@ +{{- $Resources := .Resources | default page.Resources -}} {{- $resource := 0 -}} {{- $url := urls.Parse .Path -}} {{- if not $url.Host | and $url.Path | and (strings.HasSuffix $url.Path "/" | not) -}} - {{- if .Resources -}} - {{- with .Resources.GetMatch $url.Path -}} + {{- if $Resources -}} + {{- with $Resources.GetMatch $url.Path -}} {{- $resource = . -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index 9439f714..f1ba4e84 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -42,7 +42,7 @@ "description": {{ . | safeHTML }}, {{- end -}} {{- $image := .Site.Params.seo.image -}} - {{- with dict "Path" $image "Resources" .Resources | partial "function/resource.html" -}} + {{- with dict "Path" $image | partial "function/resource.html" -}} "image": { "@type": "ImageObject", "url": "{{ .Permalink }}", @@ -55,7 +55,7 @@ {{- end -}} {{- end -}} {{- with .Site.Params.seo.thumbnailUrl -}} - {{- with dict "Path" . "Resources" $.Resources | partial "function/resource.html" -}} + {{- with dict "Path" . | partial "function/resource.html" -}} "thumbnailUrl": "{{ .Permalink }}", {{- else -}} "thumbnailUrl": "{{ . | absURL }}", @@ -104,7 +104,7 @@ "image": [ {{- range $index, $value := . -}} {{- if gt $index 0 }},{{ end -}} - {{- with dict "Path" $value "Resources" $.Resources | partial "function/resource.html" -}} + {{- with dict "Path" $value | partial "function/resource.html" -}} { "@type": "ImageObject", "url": "{{ .Permalink }}", @@ -142,7 +142,7 @@ "@type": "Organization", "name": {{ $publisher.name | safeHTML }} {{- $logo := $publisher.logoUrl -}} - {{- with dict "Path" $logo "Resources" .Resources | partial "function/resource.html" -}} + {{- with dict "Path" $logo | partial "function/resource.html" -}} ,"logo": { "@type": "ImageObject", "url": "{{ .Permalink }}", diff --git a/layouts/partials/plugin/reward.html b/layouts/partials/plugin/reward.html index 60b040f7..9e830f3a 100644 --- a/layouts/partials/plugin/reward.html +++ b/layouts/partials/plugin/reward.html @@ -12,7 +12,7 @@ {{- with T (printf "single.reward.%v" $way) -}}{{ $way = . }}{{- end -}} {{- if $image -}} - {{- dict "Src" $image "Alt" (printf "%v %v" $author $way) "Resources" $.Resources | partial "plugin/image.html" -}} + {{- dict "Src" $image "Alt" (printf "%v %v" $author $way) | partial "plugin/image.html" -}} {{ $way }} {{- end -}} diff --git a/layouts/partials/rss/item.html b/layouts/partials/rss/item.html index b320b5cb..bc86c4ab 100644 --- a/layouts/partials/rss/item.html +++ b/layouts/partials/rss/item.html @@ -33,7 +33,7 @@ {{- " - {{- dict "Src" . "Title" $.Page.Description "Alt" $.Page.Title "Resources" $.Page.Resources "Loading" "eager" "Referrerpolicy" "no-referrer" | partial "plugin/image.html" -}} + {{- dict "Src" . "Title" $.Page.Description "Alt" $.Page.Title "Loading" "eager" "Referrerpolicy" "no-referrer" | partial "plugin/image.html" -}} {{- end -}} {{- $content := .Page.Description -}} diff --git a/layouts/posts/single.html b/layouts/posts/single.html index a2ae635a..d5b0bca6 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -142,7 +142,7 @@ {{- end -}} {{- with $image -}} - {{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}} + {{- dict "Src" . "Title" $.Description | partial "plugin/image.html" -}} {{- end -}} diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html index ea2f01f0..828b9ac2 100644 --- a/layouts/shortcodes/image.html +++ b/layouts/shortcodes/image.html @@ -16,7 +16,7 @@ {{- $options = cond $caption true false | dict "Linked" | merge $options -}} {{- end -}} -{{- $options = dict "Resources" .Page.Resources "Responsive" true | merge $options -}} +{{- $options = dict "Responsive" true | merge $options -}} {{- with $caption -}} diff --git a/layouts/shortcodes/link.html b/layouts/shortcodes/link.html index bf0615e6..10c20ed9 100644 --- a/layouts/shortcodes/link.html +++ b/layouts/shortcodes/link.html @@ -1,5 +1,5 @@ {{- $destination := cond .IsNamedParams (.Get "href") (.Get 0) -}} -{{- with dict "Path" $destination "Resources" .Page.Resources | partial "function/resource.html" -}} +{{- with dict "Path" $destination | partial "function/resource.html" -}} {{- $destination = .RelPermalink -}} {{- end -}} {{- $options := dict "Destination" $destination -}} diff --git a/layouts/shortcodes/music.html b/layouts/shortcodes/music.html index 2c3ec031..53dc923b 100644 --- a/layouts/shortcodes/music.html +++ b/layouts/shortcodes/music.html @@ -3,11 +3,11 @@ {{- $theme = .Get "theme" | default $theme -}} {{- if .Get "url" -}} {{- $url := .Get "url" -}} - {{- with dict "Path" $url "Resources" .Page.Resources | partial "function/resource.html" -}} + {{- with dict "Path" $url | partial "function/resource.html" -}} {{- $url = .RelPermalink -}} {{- end -}} {{- $cover := .Get "cover" -}} - {{- with dict "Path" $cover "Resources" .Page.Resources | partial "function/resource.html" -}} + {{- with dict "Path" $cover | partial "function/resource.html" -}} {{- $cover = .RelPermalink -}} {{- end -}}