Perf: use .GetTerms optimization for getting terms on a page

This commit is contained in:
Cell
2023-12-11 14:19:13 +08:00
parent 4bfe3962a9
commit d02a9977a2
4 changed files with 17 additions and 23 deletions
+4 -6
View File
@@ -55,14 +55,12 @@
{{- /* Footer */ -}}
<div class="post-footer">
<a href="{{ .RelPermalink }}">{{ T "single.readMore" }}</a>
{{- with .Params.tags -}}
{{- $tagTerms := .GetTerms "tags" -}}
{{- if $tagTerms -}}
<div class="post-tags">
{{- dict "Class" "fa-solid fa-tags fa-fw me-1" | partial "plugin/icon.html" -}}
{{- range $value := . -}}
{{- $tag := partialCached "function/path.html" $value $value | printf "/tags/%v" | $.Site.GetPage -}}
{{- with $tag -}}
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="post-tag">{{ .LinkTitle }}</a>
{{- end -}}
{{- range $tagTerms -}}
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="post-tag">{{ .LinkTitle }}</a>
{{- end -}}
</div>
{{- end -}}
+1 -1
View File
@@ -5,7 +5,7 @@
{{- $collectionTerms := .GetTerms "collections" -}}
{{- range $collectionTerms -}}
{{- $termLink := printf `<a href="%v">%v <span>%v・%v</span></span></a>`
.RelPermalink
(partial "function/escapeurl.html" .RelPermalink)
(dict "Class" "fa-solid fa-layer-group fa-fw" | partial "plugin/icon.html")
(T "collection")
.LinkTitle
+4 -6
View File
@@ -58,13 +58,11 @@
<div class="post-info-more">
<section class="post-tags">
{{- with .Params.tags -}}
{{- $tagTerms := .GetTerms "tags" -}}
{{- if $tagTerms -}}
{{- dict "Class" "fa-solid fa-tags fa-fw me-1" | partial "plugin/icon.html" -}}
{{- range $value := . -}}
{{- $tag := partialCached "function/path.html" $value $value | printf "/tags/%v" | $.Site.GetPage -}}
{{- with $tag -}}
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="post-tag">{{ .LinkTitle }}</a>
{{- end -}}
{{- range $tagTerms -}}
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="post-tag">{{ .LinkTitle }}</a>
{{- end -}}
{{- end -}}
</section>
+8 -10
View File
@@ -1,25 +1,23 @@
{{- $categories := slice -}}
{{- range .Params.categories -}}
{{- $category := partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}}
{{- range .GetTerms "categories" -}}
{{- $categories = $categories | append (
printf `<a href="%v" class="post-category" title="%v">%v %v</a>`
(partial "function/escapeurl.html" $category.RelPermalink)
(printf "%v - %v" (T "category") $category.LinkTitle)
(partial "function/escapeurl.html" .RelPermalink)
(printf "%v - %v" (T "category") .LinkTitle)
(dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html")
$category.LinkTitle
.LinkTitle
) -}}
{{- end -}}
{{- $categoriesStr := delimit $categories "&ensp;" -}}
{{- $collections := slice -}}
{{- range .Params.collections -}}
{{- $collection := partialCached "function/path.html" . . | printf "/collections/%v" | $.Site.GetPage -}}
{{- range .GetTerms "collections" -}}
{{- $collections = $collections | append (
printf `<a href="%v" class="post-collection" title="%v">%v %v</a>`
(partial "function/escapeurl.html" $collection.RelPermalink)
(printf "%v - %v" (T "collection") $collection.LinkTitle)
(partial "function/escapeurl.html" .RelPermalink)
(printf "%v - %v" (T "collection") .LinkTitle)
(dict "Class" "fa-solid fa-layer-group fa-fw" | partial "plugin/icon.html")
$collection.LinkTitle
.LinkTitle
) -}}
{{- end -}}
{{- $collectionStr := delimit $collections "&ensp;" -}}