From 9bf09a8a3ff89c703099eb6084e151c912feb1ac Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:02:04 +0800 Subject: [PATCH 1/8] refactor(list.html): correct indention --- layouts/_default/list.html | 249 ++++++++++++++++++------------------- 1 file changed, 121 insertions(+), 128 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index db52acd1..465c4f97 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,139 +1,132 @@ {{ define "main" }} - -{{ .Scratch.Set "scope" "list" }} -{{ if .Site.Params.list.showHero | default false }} -{{ $heroStyle := print "hero/" .Site.Params.list.heroStyle ".html" }} -{{ if templates.Exists ( printf "partials/%s" $heroStyle ) }} -{{ partial $heroStyle . }} -{{ else }} -{{ partial "hero/basic.html" . }} -{{ end }} -{{- end -}} - -{{ $toc := and (.Params.showTableOfContents | default (.Site.Params.list.showTableOfContents | default false)) (in -.TableOfContents " - {{ if .Params.showBreadcrumbs | default (.Site.Params.list.showBreadcrumbs | default false) }} - {{ partial "breadcrumbs.html" . }} - {{ end }} -

{{ .Title }}

-
- {{ partial "article-meta/list.html" (dict "context" . "scope" "single") }} -
- {{ $translations := .AllTranslations }} - {{ with .File }} - {{ $path := .Path }} - {{range $translations}} - {{ $lang := print "." .Lang ".md" }} - {{ $path = replace $path $lang ".md" }} - {{end}} - {{ $jsPage := resources.Get "js/page.js" }} - {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - - {{ end }} - -
- {{ if $toc }} -
-
- {{ partial "toc.html" . }} -
-
+ {{ .Scratch.Set "scope" "list" }} + {{ if .Site.Params.list.showHero | default false }} + {{ $heroStyle := print "hero/" .Site.Params.list.heroStyle ".html" }} + {{ if templates.Exists ( printf "partials/%s" $heroStyle ) }} + {{ partial $heroStyle . }} + {{ else }} + {{ partial "hero/basic.html" . }} {{ end }} -
- {{ .Content }} + {{- end -}} + + {{ $toc := and (.Params.showTableOfContents | default (.Site.Params.list.showTableOfContents | default false)) (in .TableOfContents " + {{ if .Params.showBreadcrumbs | default (.Site.Params.list.showBreadcrumbs | default false) }} + {{ partial "breadcrumbs.html" . }} + {{ end }} +

{{ .Title }}

+
+ {{ partial "article-meta/list.html" (dict "context" . "scope" "single") }}
- - - - -
- {{ if gt .Pages 0 }} - - {{ $cardView := .Params.cardView | default (.Site.Params.list.cardView | default false) }} - {{ $cardViewScreenWidth := .Params.cardViewScreenWidth | default (.Site.Params.list.cardViewScreenWidth | default false) }} - {{ $groupByYear := .Params.groupByYear | default ($.Site.Params.list.groupByYear | default false) }} - {{ $orderByWeight := .Params.orderByWeight | default ($.Site.Params.list.orderByWeight | default false) }} - {{ $groupByYear := and (not $orderByWeight) $groupByYear }} - - {{ if not $cardView }} - -
- {{ if not $orderByWeight }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ if $groupByYear }} -

- {{ .Key }} -

- {{ end }} - {{ range .Pages }} - {{ partial "article-link/simple.html" . }} - {{ end }} - {{ end }} - {{ else }} - {{ range (.Paginate (.Pages.ByWeight)).Pages }} - {{ partial "article-link/simple.html" . }} - {{ end }} + {{ $translations := .AllTranslations }} + {{ with .File }} + {{ $path := .Path }} + {{ range $translations }} + {{ $lang := print "." .Lang ".md" }} + {{ $path = replace $path $lang ".md" }} {{ end }} + {{ $jsPage := resources.Get "js/page.js" }} + {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} + + {{ end }} + +
+ {{ if $toc }} +
+
+ {{ partial "toc.html" . }} +
+
+ {{ end }} +
+ {{ .Content }} +
- {{ else }} + {{ if gt .Pages 0 }} + {{ $cardView := .Params.cardView | default (.Site.Params.list.cardView | default false) }} + {{ $cardViewScreenWidth := .Params.cardViewScreenWidth | default (.Site.Params.list.cardViewScreenWidth | default false) }} + {{ $groupByYear := .Params.groupByYear | default ($.Site.Params.list.groupByYear | default false) }} + {{ $orderByWeight := .Params.orderByWeight | default ($.Site.Params.list.orderByWeight | default false) }} + {{ $groupByYear := and (not $orderByWeight) $groupByYear }} - {{ if $groupByYear }} - - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ if $cardViewScreenWidth }} -
- {{ end }} -

- {{ .Key }} -

-
- {{ range .Pages }} - {{ partial "article-link/card.html" . }} + {{ if not $cardView }} +
+ {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ if $groupByYear }} +

+ {{ .Key }} +

+ {{ end }} + {{ range .Pages }} + {{ partial "article-link/simple.html" . }} + {{ end }} + {{ end }} + {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/simple.html" . }} + {{ end }} {{ end }}
- {{ if $cardViewScreenWidth }}
{{ end }} + + {{ else }} + + {{ if $groupByYear }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ if $cardViewScreenWidth }} +
+ {{ end }} +

+ {{ .Key }} +

+
+ {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} +
+ {{ if $cardViewScreenWidth }} +
+ {{ end }} + {{ end }} + + {{ else }} + + {{ if $cardViewScreenWidth }} +
+
+ {{ else }} +
+ {{ end }} + {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} + {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} +
+ {{ if $cardViewScreenWidth }} +
+ {{ end }} + {{ end }} + {{ end }} - - {{ else }} - - {{ if $cardViewScreenWidth }} -
-
- {{ else }} -
- {{ end }} - {{ if not $orderByWeight }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ range .Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} - {{ else }} - {{ range (.Paginate (.Pages.ByWeight)).Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} -
- {{ if $cardViewScreenWidth }}
{{ end }} - + {{ else }} +
+

+ {{ i18n "list.no_articles" | emojify }} +

+
{{ end }} - - {{end}} - - {{ else }} -
-

- {{ i18n "list.no_articles" | emojify }} -

-
- {{ end }} - - {{ partial "pagination.html" . }} - - {{ end }} + {{ partial "pagination.html" . }} +{{ end }} From b0c3ac1321bc063eb50525514d4710920fc737b7 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:48:18 +0800 Subject: [PATCH 2/8] refactor(list.html): make list.html formattable --- .prettierignore | 1 - layouts/_default/list.html | 67 ++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.prettierignore b/.prettierignore index 0a829920..d26f8b34 100644 --- a/.prettierignore +++ b/.prettierignore @@ -27,7 +27,6 @@ static layouts/_default/_markup/render-heading.html layouts/_default/index.json -layouts/_default/list.html layouts/shortcodes/screenshot.html layouts/shortcodes/figure.html layouts/partials/hugo-embedded/shortcodes/figure-default.html diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 465c4f97..18d60f54 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -81,17 +81,24 @@ {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} {{ if $cardViewScreenWidth }}
- {{ end }} -

- {{ .Key }} -

-
- {{ range .Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} -
- {{ if $cardViewScreenWidth }} +

+ {{ .Key }} +

+
+ {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} +
+ {{ else }} +

+ {{ .Key }} +

+
+ {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} +
{{ end }} {{ end }} @@ -99,24 +106,34 @@ {{ if $cardViewScreenWidth }}
-
+
+ {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} + {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} +
+
{{ else }}
- {{ end }} - {{ if not $orderByWeight }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ range .Pages }} - {{ partial "article-link/card.html" . }} + {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} + {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} {{ end }} - {{ end }} - {{ else }} - {{ range (.Paginate (.Pages.ByWeight)).Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} -
- {{ if $cardViewScreenWidth }} - +
{{ end }} {{ end }} From 80927fb37a30bf64ddece30acb8b61d387d17b98 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:48:41 +0800 Subject: [PATCH 3/8] style(list.html): prettier format --- layouts/_default/list.html | 212 ++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 99 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 18d60f54..a6df0714 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -25,125 +25,139 @@ {{ $lang := print "." .Lang ".md" }} {{ $path = replace $path $lang ".md" }} {{ end }} - {{ $jsPage := resources.Get "js/page.js" }} - {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{ $jsPage := resources.Get "js/page.js" }} + {{ $jsPage = $jsPage | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} + {{ end }} -
- {{ if $toc }} +
+ {{ if $toc }}
-
+
{{ partial "toc.html" . }}
- {{ end }} -
- {{ .Content }} -
-
+ {{ end }} +
+ {{ .Content }} +
+
- {{ if gt .Pages 0 }} - {{ $cardView := .Params.cardView | default (.Site.Params.list.cardView | default false) }} - {{ $cardViewScreenWidth := .Params.cardViewScreenWidth | default (.Site.Params.list.cardViewScreenWidth | default false) }} - {{ $groupByYear := .Params.groupByYear | default ($.Site.Params.list.groupByYear | default false) }} - {{ $orderByWeight := .Params.orderByWeight | default ($.Site.Params.list.orderByWeight | default false) }} - {{ $groupByYear := and (not $orderByWeight) $groupByYear }} + {{ if gt .Pages 0 }} + {{ $cardView := .Params.cardView | default (.Site.Params.list.cardView | default false) }} + {{ $cardViewScreenWidth := .Params.cardViewScreenWidth | default (.Site.Params.list.cardViewScreenWidth | default false) }} + {{ $groupByYear := .Params.groupByYear | default ($.Site.Params.list.groupByYear | default false) }} + {{ $orderByWeight := .Params.orderByWeight | default ($.Site.Params.list.orderByWeight | default false) }} + {{ $groupByYear := and (not $orderByWeight) $groupByYear }} - {{ if not $cardView }} -
- {{ if not $orderByWeight }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ if $groupByYear }} -

- {{ .Key }} -

- {{ end }} - {{ range .Pages }} - {{ partial "article-link/simple.html" . }} - {{ end }} + {{ if not $cardView }} +
+ {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ if $groupByYear }} +

+ {{ .Key }} +

{{ end }} - {{ else }} - {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ range .Pages }} {{ partial "article-link/simple.html" . }} {{ end }} {{ end }} -
- {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/simple.html" . }} + {{ end }} + {{ end }} +
+ {{ else }} - {{ if $groupByYear }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ if $cardViewScreenWidth }} -
-

- {{ .Key }} -

-
- {{ range .Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} -
-
- {{ else }} -

- {{ .Key }} -

-
+ {{ if $groupByYear }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ if $cardViewScreenWidth }} +
+

+ {{ .Key }} +

+
+ {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} +
+
+ {{ else }} +

+ {{ .Key }} +

+
+ {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} +
+ {{ end }} + {{ end }} + + {{ else }} + {{ if $cardViewScreenWidth }} +
+
+ {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} {{ range .Pages }} {{ partial "article-link/card.html" . }} {{ end }} -
+ {{ end }} + {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} +
+ + {{ else }} +
+ {{ if not $orderByWeight }} + {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} + {{ range .Pages }} + {{ partial "article-link/card.html" . }} + {{ end }} + {{ end }} + {{ else }} + {{ range (.Paginate (.Pages.ByWeight)).Pages }} + {{ partial "article-link/card.html" . }} {{ end }} {{ end }} - - {{ else }} - - {{ if $cardViewScreenWidth }} -
-
- {{ if not $orderByWeight }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ range .Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} - {{ else }} - {{ range (.Paginate (.Pages.ByWeight)).Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} -
-
- {{ else }} -
- {{ if not $orderByWeight }} - {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} - {{ range .Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} - {{ else }} - {{ range (.Paginate (.Pages.ByWeight)).Pages }} - {{ partial "article-link/card.html" . }} - {{ end }} - {{ end }} -
- {{ end }} - {{ end }} - +
+ {{ end }} {{ end }} - {{ else }} -
-

- {{ i18n "list.no_articles" | emojify }} -

-
+ {{ end }} + {{ else }} +
+

+ {{ i18n "list.no_articles" | emojify }} +

+
+ {{ end }} {{ partial "pagination.html" . }} {{ end }} From c8265de81335a10ac15dded9e2229083d36e6b10 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:51:34 +0800 Subject: [PATCH 4/8] refactor(list.html): use intermediate variable for complex condition --- layouts/_default/list.html | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index a6df0714..117c8045 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -9,7 +9,8 @@ {{ end }} {{- end -}} - {{ $toc := and (.Params.showTableOfContents | default (.Site.Params.list.showTableOfContents | default false)) (in .TableOfContents " {{ if .Params.showBreadcrumbs | default (.Site.Params.list.showBreadcrumbs | default false) }} {{ partial "breadcrumbs.html" . }} @@ -35,20 +36,12 @@ data-oid-likes="likes_{{ $path }}"> {{ end }} -
+ {{ $tocMargin := cond $toc "mt-12" "mt-0" -}} + {{ $topClass := cond (hasPrefix .Site.Params.header.layout "fixed") "lg:top-[140px]" "lg:top-10" }} +
{{ if $toc }}
-
+
{{ partial "toc.html" . }}
@@ -94,9 +87,7 @@ {{ .Key }}
+ class="w-full grid gap-4 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5"> {{ range .Pages }} {{ partial "article-link/card.html" . }} {{ end }} @@ -107,9 +98,7 @@ {{ .Key }}
+ class="w-full grid gap-4 sm:grid-cols-2 md:grid-cols-3"> {{ range .Pages }} {{ partial "article-link/card.html" . }} {{ end }} From c362f4a488b6ad85e8f3cb4902ec0f26f2ca3a29 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:21:30 +0800 Subject: [PATCH 5/8] style(list.html): add proper code comments --- layouts/_default/list.html | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index 117c8045..c6a50e77 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,5 +1,9 @@ {{ define "main" }} {{ .Scratch.Set "scope" "list" }} + {{ $enableToc := .Params.showTableOfContents | default (.Site.Params.list.showTableOfContents | default false) }} + {{ $showToc := and $enableToc (in .TableOfContents " {{ if .Params.showBreadcrumbs | default (.Site.Params.list.showBreadcrumbs | default false) }} {{ partial "breadcrumbs.html" . }} @@ -36,10 +39,12 @@ data-oid-likes="likes_{{ $path }}"> {{ end }} - {{ $tocMargin := cond $toc "mt-12" "mt-0" -}} + + {{/* Description (markdown content) */}} + {{ $tocMargin := cond $showToc "mt-12" "mt-0" }} {{ $topClass := cond (hasPrefix .Site.Params.header.layout "fixed") "lg:top-[140px]" "lg:top-10" }}
- {{ if $toc }} + {{ if $showToc }}
{{ partial "toc.html" . }} @@ -51,6 +56,7 @@
+ {{/* Article Grid */}} {{ if gt .Pages 0 }} {{ $cardView := .Params.cardView | default (.Site.Params.list.cardView | default false) }} {{ $cardViewScreenWidth := .Params.cardViewScreenWidth | default (.Site.Params.list.cardViewScreenWidth | default false) }} @@ -77,8 +83,8 @@ {{ end }} {{ end }}
+ {{/* else: is cardView */}} {{ else }} - {{ if $groupByYear }} {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} {{ if $cardViewScreenWidth }} @@ -86,8 +92,7 @@

{{ .Key }}

-
+
{{ range .Pages }} {{ partial "article-link/card.html" . }} {{ end }} @@ -97,8 +102,7 @@

{{ .Key }}

-
+
{{ range .Pages }} {{ partial "article-link/card.html" . }} {{ end }} @@ -106,6 +110,7 @@ {{ end }} {{ end }} + {{/* else: not groupByYear */}} {{ else }} {{ if $cardViewScreenWidth }}
@@ -137,10 +142,10 @@ {{ end }} {{ end }}
- {{ end }} - {{ end }} - - {{ end }} + {{ end }}{{/* End of cardViewScreenWidth */}} + {{ end }}{{/* End of groupByYear */}} + {{ end }}{{/* End of cardView */}} + {{/* else: .Pages not greater to zero */}} {{ else }}

From bda68f96a8b6c7813bfb19468fc9d4dec29c373c Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:37:27 +0800 Subject: [PATCH 6/8] style(baseof.html): manually format --- layouts/_default/baseof.html | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 0b71d2ce..3f037b8a 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -17,11 +17,10 @@

{{ i18n - "nav.skip_to_main" - }} + href="#main-content"> + + {{ i18n "nav.skip_to_main" }} +
{{ $header := print "header/" .Site.Params.header.layout ".html" }} {{ if templates.Exists ( printf "partials/%s" $header ) }} From 8930731ccc6cbdc12a636e07a0e4642a24f0c372 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 17 Jul 2025 20:38:51 +0800 Subject: [PATCH 7/8] refactor(single.html): modularize author and fix the multilingual link when author is at bottom --- layouts/_default/single.html | 108 +++++++++++++++-------------------- 1 file changed, 45 insertions(+), 63 deletions(-) diff --git a/layouts/_default/single.html b/layouts/_default/single.html index d9378bb2..0487403c 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -26,48 +26,8 @@ {{ partial "article-meta/basic.html" (dict "context" . "scope" "single") }}
- {{ $authorsData := .Site.Data.authors }} - {{ $taxonomies := .Site.Taxonomies.authors }} - {{ $baseURL := .Site.BaseURL }} - {{ $taxonomyLink := 0 }} - {{ $showAuthor := 0 }} - - {{ if not (strings.HasSuffix $baseURL "/") }} - {{ $baseURL = delimit (slice $baseURL "/") "" }} - {{ end }} - {{ if not (.Params.showAuthorBottom | default ( .Site.Params.article.showAuthorBottom | default false)) }} - - {{ if .Params.showAuthor | default (.Site.Params.article.showAuthor | default true) }} - {{ $showAuthor = 1 }} - {{ partial "author.html" . }} - {{ end }} - - {{ range $author := .Page.Params.authors }} - {{ $authorData := index $authorsData $author }} - {{- if $authorData -}} - {{ range $taxonomyname, $taxonomy := $taxonomies }} - {{ if (eq $taxonomyname $author) }} - {{ $taxonomyLink = delimit (slice $baseURL "authors/" $author "/") "" }} - {{ end }} - {{ end }} - - {{ $finalLink := $taxonomyLink }} - {{ $currentLang := $.Site.Language.Lang }} - {{ if eq $.Site.LanguagePrefix "" }} - {{ $finalLink = printf "%sauthors/%s/" $baseURL $author }} - {{ else }} - {{ $finalLink = printf "%s%s/authors/%s/" $baseURL $currentLang $author }} - {{ end }} - - {{ partial "author-extra.html" (dict "context" . "data" $authorData "link" $finalLink) }} - {{- end -}} - {{ end }} - - {{ if or $taxonomyLink $showAuthor }} -
- {{ end }} - + {{ template "SingleAuthor" . }} {{ end }} @@ -120,28 +80,7 @@ {{ if (.Params.showAuthorBottom | default ( .Site.Params.article.showAuthorBottom | default false)) }} - - {{ if .Params.showAuthor | default (.Site.Params.article.showAuthor | default true) }} - {{ $showAuthor = 1 }} - {{ partial "author.html" . }} - {{ end }} - - {{ range $author := .Page.Params.authors }} - {{ $authorData := index $authorsData $author }} - {{- if $authorData -}} - {{ range $taxonomyname, $taxonomy := $taxonomies }} - {{ if (eq $taxonomyname $author) }} - {{ $taxonomyLink = delimit (slice $baseURL "authors/" $author "/") "" }} - {{ end }} - {{ end }} - {{ partial "author-extra.html" (dict "context" . "data" $authorData "link" $taxonomyLink) }} - {{- end -}} - {{ end }} - - {{ if or $taxonomyLink $showAuthor }} -
- {{ end }} - + {{ template "SingleAuthor" . }} {{ end }} {{ partial "series/series-closed.html" . }} @@ -184,3 +123,46 @@ {{ end }} + +{{ define "SingleAuthor" }} + {{ $authorsData := .Site.Data.authors }} + {{ $taxonomies := .Site.Taxonomies.authors }} + {{ $baseURL := .Site.BaseURL }} + {{ $taxonomyLink := 0 }} + {{ $showAuthor := 0 }} + {{ $isAuthorBottom := (.Params.showAuthorBottom | default ( .Site.Params.article.showAuthorBottom | default false)) }} + + {{ if not (strings.HasSuffix $baseURL "/") }} + {{ $baseURL = delimit (slice $baseURL "/") "" }} + {{ end }} + + {{ if .Params.showAuthor | default (.Site.Params.article.showAuthor | default true) }} + {{ $showAuthor = 1 }} + {{ partial "author.html" . }} + {{ end }} + + {{ range $author := .Page.Params.authors }} + {{ $authorData := index $authorsData $author }} + {{- if $authorData -}} + {{ range $taxonomyname, $taxonomy := $taxonomies }} + {{ if (eq $taxonomyname $author) }} + {{ $taxonomyLink = delimit (slice $baseURL "authors/" $author "/") "" }} + {{ end }} + {{ end }} + + {{ $finalLink := $taxonomyLink }} + {{ $currentLang := $.Site.Language.Lang }} + {{ if eq $.Site.LanguagePrefix "" }} + {{ $finalLink = printf "%sauthors/%s/" $baseURL $author }} + {{ else }} + {{ $finalLink = printf "%s%s/authors/%s/" $baseURL $currentLang $author }} + {{ end }} + + {{ partial "author-extra.html" (dict "context" . "data" $authorData "link" $finalLink) }} + {{- end -}} + {{ end }} + + {{ if or $taxonomyLink $showAuthor }} +
+ {{ end }} +{{ end }} From c4e658057eecb4d3547c60eea27611582717c89d Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:50:39 +0800 Subject: [PATCH 8/8] refactor: polish base templates - use intermediate variable for complex condition - replace .Site with global function site --- layouts/_default/baseof.html | 24 ++++++------ layouts/_default/list.html | 20 +++++----- layouts/_default/single.html | 72 +++++++++++++++--------------------- layouts/_default/term.html | 19 ++++------ layouts/_default/terms.html | 14 +++---- 5 files changed, 64 insertions(+), 85 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 3f037b8a..b746f93e 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,14 +1,14 @@ + data-default-appearance="{{ site.Params.defaultAppearance | default " light" }}" + data-auto-appearance="{{ site.Params.autoSwitchAppearance | default " true" }}"> {{- partial "head.html" . -}} @@ -22,7 +22,7 @@ {{ i18n "nav.skip_to_main" }} - {{ $header := print "header/" .Site.Params.header.layout ".html" }} + {{ $header := print "header/" site.Params.header.layout ".html" }} {{ if templates.Exists ( printf "partials/%s" $header ) }} {{ partial $header . }} {{ else }} @@ -31,26 +31,26 @@
{{ block "main" . }}{{ end }} - {{ if and (.Site.Params.footer.showScrollToTop | default true) (gt .WordCount 1) }} + {{ if and (site.Params.footer.showScrollToTop | default true) (gt .WordCount 1) }} {{- partial "scroll-to-top.html" . -}} {{ end }}
{{- partial "footer.html" . -}} - {{ if .Site.Params.enableSearch | default false }} + {{ if site.Params.enableSearch | default false }} {{- partial "search.html" . -}} {{ end }}
- {{ if .Site.Params.buymeacoffee.globalWidget | default false }} + {{ if site.Params.buymeacoffee.globalWidget | default false }} {{ end }} diff --git a/layouts/_default/list.html b/layouts/_default/list.html index c6a50e77..10d78f1a 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -1,11 +1,11 @@ {{ define "main" }} {{ .Scratch.Set "scope" "list" }} - {{ $enableToc := .Params.showTableOfContents | default (.Site.Params.list.showTableOfContents | default false) }} + {{ $enableToc := .Params.showTableOfContents | default (site.Params.list.showTableOfContents | default false) }} {{ $showToc := and $enableToc (in .TableOfContents " - {{ if .Params.showBreadcrumbs | default (.Site.Params.list.showBreadcrumbs | default false) }} + {{ if .Params.showBreadcrumbs | default (site.Params.list.showBreadcrumbs | default false) }} {{ partial "breadcrumbs.html" . }} {{ end }}

{{ .Title }}

@@ -30,7 +30,7 @@ {{ $path = replace $path $lang ".md" }} {{ end }} {{ $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") }} {{ end }} -
+ + {{/* Footer */}}