Perf: optimize code

This commit is contained in:
Cell
2022-11-20 18:47:42 +08:00
parent d31215044d
commit ffb3888414
6 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -43,7 +43,7 @@
{{- $categories := slice -}}
{{- range .Params.categories -}}
{{- $category := partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}}
{{- $categories = $categories | append (printf `<a href="%v">%v %v</a>` (replace $category.RelPermalink "#" "%23") (dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html") $category.Title) -}}
{{- $categories = $categories | append (printf `<a href="%v">%v %v</a>` (partial "function/escapeurl.html" $category.RelPermalink) (dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html") $category.Title) -}}
{{- end -}}
{{- with delimit $categories "&ensp;" -}}
&nbsp;<span class="post-category">
@@ -70,7 +70,7 @@
{{- range $value := . -}}
{{- $tag := partialCached "function/path.html" $value $value | printf "/tags/%v" | $.Site.GetPage -}}
{{- with $tag -}}
<a href='{{ replace .RelPermalink "#" "%23" }}' class="post-tag">{{ .Title }}</a>
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="post-tag">{{ .Title }}</a>
{{- end -}}
{{- end -}}
</div>
+1 -1
View File
@@ -1,4 +1,4 @@
{{- /* https://discourse.gohugo.io/t/how-decode-urls-in-hugo/7549/4 */ -}}
{{- $URL := partial "function/urlquery.html" . -}}
{{- $URL := partial "function/escapeurl.html" . -}}
{{- $URL = $URL | urlize | urls.Parse -}}
{{- return $URL.Path -}}
+1 -1
View File
@@ -63,7 +63,7 @@
{{- range $value := . -}}
{{- $tag := partialCached "function/path.html" $value $value | printf "/tags/%v" | $.Site.GetPage -}}
{{- with $tag -}}
<a href='{{ replace .RelPermalink "#" "%23" }}' class="post-tag">{{ .Title }}</a>
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="post-tag">{{ .Title }}</a>
{{- end -}}
{{- end -}}
{{- end -}}
+1 -1
View File
@@ -52,7 +52,7 @@
{{- $categories := slice -}}
{{- range .Params.categories -}}
{{- $category := partialCached "function/path.html" . . | printf "/categories/%v" | $.Site.GetPage -}}
{{- $categories = $categories | append (printf `<a href="%v">%v %v</a>` (replace $category.RelPermalink "#" "%23") (dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html") $category.Title) -}}
{{- $categories = $categories | append (printf `<a href="%v">%v %v</a>` (partial "function/escapeurl.html" $category.RelPermalink) (dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html") $category.Title) -}}
{{- end -}}
{{- with delimit $categories "&ensp;" }}
<span class="post-category">
+4 -4
View File
@@ -24,7 +24,7 @@
<div class="card-item">
<div class="card-item-wrapper">
<h3 class="card-item-title">
<a href='{{ replace .RelPermalink "#" "%23" }}'>
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}'>
{{ dict "Class" "fa-regular fa-folder fa-fw" | partial "plugin/icon.html" }}
{{ .Page.Title }}&nbsp;<sup>{{- len $pages -}}</sup>
</a>
@@ -36,7 +36,7 @@
{{- end -}}
{{- if gt (len $pages) 5 -}}
<span class="more-post">
<a href='{{ replace .RelPermalink "#" "%23" }}' class="more-single-link">{{ T "more" }} >></a>
<a href='{{ partial "function/escapeurl.html" .RelPermalink }}' class="more-single-link">{{ T "more" }} >></a>
</span>
{{- end -}}
</div>
@@ -57,11 +57,11 @@
{{- range $tags -}}
{{- $grade := math.Min (math.Floor (div (sub .Count 1) $baseGrade)) 10 -}}
{{- $fontSize := add $minFont (mul $grade $baseFont) -}}
<a href='{{ replace .Page.RelPermalink "#" "%23" }}' class="tag-cloud-{{ $grade }}" style="--tag-font: {{ $fontSize }}px">{{ .Page.Title }} <sup>{{ .Count }}</sup></a>
<a href='{{ partial "function/escapeurl.html" .Page.RelPermalink }}' class="tag-cloud-{{ $grade }}" style="--tag-font: {{ $fontSize }}px">{{ .Page.Title }} <sup>{{ .Count }}</sup></a>
{{- end -}}
{{- else -}}
{{- range $.Site.Taxonomies.tags.ByCount -}}
<a href='{{ replace .Page.RelPermalink "#" "%23" }}'>{{ .Page.Title }} <sup>{{ .Count }}</sup></a>
<a href='{{ partial "function/escapeurl.html" .Page.RelPermalink }}'>{{ .Page.Title }} <sup>{{ .Count }}</sup></a>
{{- end -}}
{{- end -}}
</div>