diff options
| author | BigCoke233 <hi@guhub.cn> | 2025-12-06 16:10:43 +0800 |
|---|---|---|
| committer | BigCoke233 <hi@guhub.cn> | 2025-12-06 16:10:43 +0800 |
| commit | cec8a299a36ea029f8fe2469f68071313ebdde1f (patch) | |
| tree | e61a67a718496607cd2d115b3324ba2594fcab93 /layouts/library/section.html | |
| parent | 630fa5c20dee795a9eb64bda76f478d3b826b625 (diff) | |
refactor: library section template
- use Context to get pages, instead of filter the whole site's pages
- use one tempalte `section.html` for both library home and year lists
Former-commit-id: e7e01fedce0c4a5b7e6e5eec41ed5e97a1bf1979
Diffstat (limited to 'layouts/library/section.html')
| -rw-r--r-- | layouts/library/section.html | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/layouts/library/section.html b/layouts/library/section.html index a7df419a..cab61e51 100644 --- a/layouts/library/section.html +++ b/layouts/library/section.html @@ -1,17 +1,34 @@ {{ define "main" }} + +{{ $isLibraryHome := eq .RelPermalink "/library/" }} +{{ $books := .RegularPages }} +{{ if $isLibraryHome }} + {{ range .Sections }} + {{ $books = $books | append .RegularPages }} + {{ end }} +{{ end }} + +{{ $years := slice }} +{{ range .Sections }} + {{ $years = $years | append .Title }} +{{ end }} <article class="pagefind-exclude"> {{ partial "header.html" . }} <div> - {{ $booksThisYear := where (where .Site.RegularPages "Section" "library") "Date.Year" now.Year }} + {{ if $isLibraryHome }} {{ partial "components/section-title" (dict - "Left" now.Year - "Right" (printf "共 %d 篇书评" (len $booksThisYear)) + "Left" "最近读的书" + "Right" (printf "共 %d 篇书评" (len $books)) )}} + {{ end }} <div class="grid grid-cols-4 md:grid-cols-6 items-center gap-4 my-4"> - {{ $first18BooksThisYear := first 18 $booksThisYear }} - {{ range $i, $book := $first18BooksThisYear }} + {{ $booksToShow := $books }} + {{ if $isLibraryHome }} + {{ $booksToShow = first 18 $books }} + {{ end }} + {{ range $i, $book := $booksToShow }} <div class="{{ if gt $i 15 }}hidden md:block{{ end }}" data-tooltip="{{ $book.Title }}"> {{ partial "items/book" (dict @@ -21,14 +38,11 @@ {{ end }} </div> - {{ $years := slice }} - {{ range where .Site.RegularPages "Section" "library" }} - {{ $year := string .Date.Year }} - {{ if not (in $years $year) }} - {{ $years = $years | append $year }} - {{ end }} - {{ end }} + <!-- ONLY SHOW IN HOME SECTION / START --> + {{ if $isLibraryHome }} + + <!-- === year list === --> <div class="flex items-center my-8"> <a href="/library/2025" class="small-button"> {{ T "library.viewAllThisYear" }} @@ -42,7 +56,8 @@ </p> </div> - {{ $goodBooks := where (where .Site.RegularPages "Section" "library") ".Params.rating" "==" 5 }} + <!-- === good books section === --> + {{ $goodBooks := where $books ".Params.rating" "==" 5 }} {{ partial "components/section-title" (dict "Left" "推荐好书" "Right" (printf "共 %d 本" (len $goodBooks)) @@ -57,6 +72,10 @@ </div> {{ end }} </div> + + {{ end }} + <!-- ONLY SHOW IN HOME SECTION / END --> + </div> </article> {{ partial "footer.html" . }} |
