{{ define "main" }} {{ $isLibraryHome := eq .RelPermalink "/library/" }} {{ $books := .RegularPages }} {{ if $isLibraryHome }} {{ $sections := (sort .Sections "value" "asc") }} {{ range $sections }} {{ $books = $books | append .RegularPages }} {{ end }} {{ end }} {{ $years := slice }} {{ range .Sections }} {{ $years = $years | append .Title }} {{ end }} {{ $years = $years | collections.Reverse }}
{{ .Content }}
{{ if $isLibraryHome }} {{ partial "components/section-title" (dict "Left" "最近读的书" "Right" (printf "共 %d 篇书评" (len $books)) )}} {{ end }}
{{ $booksToShow := $books }} {{ if $isLibraryHome }} {{ $booksToShow = first 18 $books }} {{ end }} {{ range $i, $book := $booksToShow }}
{{ partial "components/book" (dict "ctx" $book ) }}
{{ end }}
{{ if $isLibraryHome }}
{{ T "library.viewAllThisYear" }} →

{{ $currentYear := printf "%d" now.Year }} {{ range $i, $year := $years }} {{ if ne $year $currentYear }} {{ $year }} 年 {{ if not (eq $i (sub (len $years) 1)) }}·{{ end }} {{ end }} {{ end }}

{{ $goodBooks := where $books ".Params.rating" "==" 5 }} {{ partial "components/section-title" (dict "Left" "推荐好书" "Right" (printf "共 %d 本" (len $goodBooks)) )}}
{{ range $goodBooks }} {{ partial "components/book" (dict "ctx" . "NoViewTransition" true ) }} {{ end }}
{{ end }}
{{ end }}