summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-06 10:43:16 +0800
committerEltrac <hi@guhub.cn>2025-11-06 10:43:16 +0800
commitd5a29ffa1c93b3fded194400e62f118fb06c5df7 (patch)
tree3eb0780ea8e6d72930cc0283f0e32e12e8e00170
parent80eb9daba825a915cc9be40e8930ad815c6db9e4 (diff)
feat: unify section titles
-rw-r--r--layouts/_partials/components/section-title.html10
-rw-r--r--layouts/library/section.html23
-rw-r--r--layouts/section.html10
3 files changed, 29 insertions, 14 deletions
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 }}
+<h2 class="border-b-2 border-b-solid border-[var(--border-color)]
+ py-2 text-6 flex justify-between items-center
+ sticky top-0 bg-[var(--background-color)] z-1">
+ <span>{{ $left }}</span>
+ <span class="font-mono text-secondary text-3">
+ {{ $right }}
+ </span>
+</h2>
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 @@
<article class="pagefind-exclude">
{{ partial "header.html" . }}
<div>
- <h2>{{ now.Year }} 年读的书</h2>
+ {{ $booksThisYear := where (where .Site.RegularPages "Section" "library") "Date.Year" now.Year }}
+
+ {{ partial "components/section-title" (dict
+ "Left" now.Year
+ "Right" (printf "共 %d 篇书评" (len $booksThisYear))
+ )}}
+
<div class="grid grid-cols-4 md:grid-cols-6 items-center gap-4 my-4">
- {{ $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 }}
<div class="{{ if gt $i 15 }}hidden md:block{{ end }}"
data-tooltip="{{ $book.Title }}">
{{ partial "items/book" $book }}
</div>
- {{ end }}
{{ end }}
</div>
@@ -23,7 +27,6 @@
{{ end }}
{{ end }}
-
<div class="flex items-center my-8">
<a href="/library/2025" class="small-button">
{{ T "library.viewAllThisYear" }}
@@ -37,9 +40,13 @@
</p>
</div>
- <h2>推荐好书</h2>
+ {{ $goodBooks := where (where .Site.RegularPages "Section" "library") ".Params.rating" "==" 5 }}
+ {{ partial "components/section-title" (dict
+ "Left" "推荐好书"
+ "Right" (printf "共 %d 本" (len $goodBooks))
+ )}}
<div class="grid grid-cols-4 md:grid-cols-6 items-center gap-4 my-4">
- {{ range where (where .Site.RegularPages "Section" "library") ".Params.rating" "==" 5 }}
+ {{ range $goodBooks }}
<div data-tooltip="{{ .Title }}">{{ partial "items/book" . }}</div>
{{ end }}
</div>
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" -}}
<section class="w-full">
- <h1 class="border-b-2 border-b-solid border-[var(--border-color)]
- py-2 text-6 sticky top-0 bg-[var(--background-color)] z-1
- flex justify-between items-center">
- {{ .Key }}
- <small class="font-mono text-secondary text-3">{{ T "archivePage.postCountAnnual" (len .Pages) }}</small>
- </h1>
+ {{ partial "components/section-title" (dict
+ "Left" .Key
+ "Right" (T "archivePage.postCountAnnual" (len .Pages))
+ )}}
{{ range .Pages.GroupByDate "January" }}
<details class="posts-month-archive"{{ if gt $remainingMonthsToOpen 0 }} open{{ end }}>