refactor: polish base templates

- use intermediate variable for complex condition
- replace .Site with global function site
This commit is contained in:
ZhenShuo Leo
2025-07-17 21:50:39 +08:00
parent 8930731ccc
commit c4e658057e
5 changed files with 64 additions and 85 deletions

View File

@@ -1,7 +1,7 @@
{{ define "main" }}
{{ .Scratch.Set "scope" "list" }}
{{ if .Site.Params.taxonomy.showHero | default false }}
{{ $heroStyle := print "hero/" .Site.Params.taxonomy.heroStyle ".html" }}
{{ if site.Params.taxonomy.showHero | default false }}
{{ $heroStyle := print "hero/" site.Params.taxonomy.heroStyle ".html" }}
{{ if templates.Exists ( printf "partials/%s" $heroStyle ) }}
{{ partial $heroStyle . }}
{{ else }}
@@ -9,13 +9,9 @@
{{ end }}
{{- end -}}
{{ $toc := and (.Params.showTableOfContents | default (.Site.Params.taxonomy.showTableOfContents | default false)) (in
.TableOfContents "<ul")
}}
<header>
{{ if .Params.showBreadcrumbs | default (.Site.Params.taxonomy.showBreadcrumbs | default false) }}
{{ if .Params.showBreadcrumbs | default (site.Params.taxonomy.showBreadcrumbs | default false) }}
{{ partial "breadcrumbs.html" . }}
{{ end }}
<h1 class="mt-5 text-4xl font-extrabold text-neutral-900 dark:text-neutral">{{ .Title }}</h1>
@@ -30,7 +26,7 @@
</div>
</section>
{{ $jsPage := resources.Get "js/page.js" }}
{{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }}
{{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint (site.Params.fingerprintAlgorithm | default "sha512") }}
<script
type="text/javascript"
src="{{ $jsPage.RelPermalink }}"
@@ -39,7 +35,7 @@
data-oid-likes="likes_taxonomy_{{ .Data.Plural }}"></script>
{{ end }}
{{ if .Site.Params.taxonomy.cardView }}
{{ if site.Params.taxonomy.cardView }}
<section class="w-full grid gap-4 sm:grid-cols-2 md:grid-cols-3">
{{ range .Data.Terms }}
{{ partial "term-link/card.html" . }}