From 1fafbca42b787fa00767f7170666c24dd768a6da Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 6 Nov 2025 10:43:16 +0800 Subject: feat: unify section titles Former-commit-id: d5a29ffa1c93b3fded194400e62f118fb06c5df7 --- layouts/_partials/components/section-title.html | 10 ++++++++++ layouts/library/section.html | 23 +++++++++++++++-------- layouts/section.html | 10 ++++------ 3 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 layouts/_partials/components/section-title.html diff --git a/layouts/_partials/components/section-title.html b/layouts/_partials/components/section-title.html new file mode 100644 index 00000000..698f71e8 --- /dev/null +++ b/layouts/_partials/components/section-title.html @@ -0,0 +1,10 @@ +{{ $left := .Left }} +{{ $right := .Right }} +

+ {{ $left }} + + {{ $right }} + +

diff --git a/layouts/library/section.html b/layouts/library/section.html index cd95b8e8..973c6351 100644 --- a/layouts/library/section.html +++ b/layouts/library/section.html @@ -2,16 +2,20 @@
{{ partial "header.html" . }}
-

{{ now.Year }} 年读的书

+ {{ $booksThisYear := where (where .Site.RegularPages "Section" "library") "Date.Year" now.Year }} + + {{ partial "components/section-title" (dict + "Left" now.Year + "Right" (printf "共 %d 篇书评" (len $booksThisYear)) + )}} +
- {{ $books := first 18 (where .Site.RegularPages "Section" "library") }} - {{ range $i, $book := $books }} - {{ if eq .Date.Year now.Year }} + {{ $first18BooksThisYear := first 18 $booksThisYear }} + {{ range $i, $book := $first18BooksThisYear }}
{{ partial "items/book" $book }}
- {{ end }} {{ end }}
@@ -23,7 +27,6 @@ {{ end }} {{ end }} - -

推荐好书

+ {{ $goodBooks := where (where .Site.RegularPages "Section" "library") ".Params.rating" "==" 5 }} + {{ partial "components/section-title" (dict + "Left" "推荐好书" + "Right" (printf "共 %d 本" (len $goodBooks)) + )}}
- {{ range where (where .Site.RegularPages "Section" "library") ".Params.rating" "==" 5 }} + {{ range $goodBooks }}
{{ partial "items/book" . }}
{{ end }}
diff --git a/layouts/section.html b/layouts/section.html index 7cb4681a..05e3fb91 100644 --- a/layouts/section.html +++ b/layouts/section.html @@ -6,12 +6,10 @@ {{ $remainingMonthsToOpen := 3 }} {{ range (where site.RegularPages "Type" "eq" "posts").GroupByDate "2006" -}}
-

- {{ .Key }} - {{ T "archivePage.postCountAnnual" (len .Pages) }} -

+ {{ partial "components/section-title" (dict + "Left" .Key + "Right" (T "archivePage.postCountAnnual" (len .Pages)) + )}} {{ range .Pages.GroupByDate "January" }}
-- cgit v1.2.3