Chore: optimize .Resources variable acquisition in function resources.html

This commit is contained in:
Cell
2023-12-30 23:59:07 +08:00
parent de5fd0c3f7
commit e482fbe36a
12 changed files with 19 additions and 18 deletions
+2 -2
View File
@@ -1,11 +1,11 @@
{{- if .Title | and .Text -}}
<figure>
{{- 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" -}}
<figcaption class="image-caption">
{{- .Text | safeHTML -}}
</figcaption>
</figure>
{{- 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 -}}
+1 -1
View File
@@ -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 -}}
+1 -1
View File
@@ -22,7 +22,7 @@
{{ range $index, $friend := .Site.Data.friends }}
<a class="friend-link" title="{{ $friend.description }}" href="{{ $friend.url | safeURL }}" rel="external noopener noreferrer" target="_blank">
{{ 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 }}
<svg class="friend-avatar" aria-hidden="true">
<use xlink:href="#icon-{{ add 1 $index }}"></use>
+1 -1
View File
@@ -19,7 +19,7 @@
{{ range $index, $friend := .Site.Data.friends }}
<a class="friend-link" title="{{ $friend.description }}" href="{{ $friend.url | safeURL }}" rel="external noopener noreferrer" target="_blank">
{{ 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 }}
<svg class="friend-avatar" aria-hidden="true">
<use xlink:href="#icon-{{ add 1 $index }}"></use>
+3 -2
View File
@@ -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 -}}
+4 -4
View File
@@ -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 }}",
+1 -1
View File
@@ -12,7 +12,7 @@
{{- with T (printf "single.reward.%v" $way) -}}{{ $way = . }}{{- end -}}
{{- if $image -}}
<div>
{{- 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" -}}
<span{{ if $reward.animation }} data-animation{{ end }}>{{ $way }}</span>
</div>
{{- end -}}
+1 -1
View File
@@ -33,7 +33,7 @@
{{- "<![CDATA[" | safeHTML -}}
{{- with $image -}}
<div class="featured-image">
{{- 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" -}}
</div>
{{- end -}}
{{- $content := .Page.Description -}}
+1 -1
View File
@@ -142,7 +142,7 @@
{{- end -}}
{{- with $image -}}
<div class="featured-image">
{{- dict "Src" . "Title" $.Description "Resources" $.Resources | partial "plugin/image.html" -}}
{{- dict "Src" . "Title" $.Description | partial "plugin/image.html" -}}
</div>
{{- end -}}
+1 -1
View File
@@ -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 -}}
<figure{{ with cond $.IsNamedParams ($.Get "class") "" }} class="{{ . }}"{{ end }}>
+1 -1
View File
@@ -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 -}}
+2 -2
View File
@@ -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 -}}
<meting-js url="{{ $url }}" name="{{ .Get `name` }}" artist="{{ .Get `artist` }}" cover="{{ $cover }}" theme="{{ $theme }}"