blob: cb7e1734729d1d7c04f24472fe70e48b15d937f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
{{ 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 }}
<article class="pagefind-exclude">
{{ partial "header.html" . }}
{{ partial "home/home-nav" . }}
<div class="markdown-body">{{ .Content }}</div>
<div>
{{ if $isLibraryHome }}
{{ partial "components/section-title" (dict
"Left" "最近读的书"
"Right" (printf "共 %d 篇书评" (len $books))
)}}
{{ end }}
<div class="grid grid-cols-4 md:grid-cols-6 items-center gap-4 my-4">
{{ $booksToShow := $books }}
{{ if $isLibraryHome }}
{{ $booksToShow = first 18 $books }}
{{ end }}
{{ range $i, $book := $booksToShow }}
<div class="{{ if gt $i 15 }}hidden md:block{{ end }}">
{{ partial "items/book" (dict
"ctx" $book
) }}
</div>
{{ end }}
</div>
<!-- ONLY SHOW IN HOME SECTION / START -->
{{ if $isLibraryHome }}
<!-- === year list === -->
<div class="flex items-center my-8 justify-between gap-4">
<a href="/library/{{ now.Year }}" class="small-button">
{{ T "library.viewAllThisYear" }}
<span class="text-secondary">→</span>
</a>
<p class="my-0">
{{ $currentYear := printf "%d" now.Year }}
{{ range $i, $year := $years }}
{{ if ne $year $currentYear }}
<a class="text-secondary" href="{{ printf "/library/%s/" $year }}">{{ $year }} 年</a>
{{ if not (eq $i (sub (len $years) 1)) }}·{{ end }}
{{ end }}
{{ end }}
</p>
</div>
<!-- === good books section === -->
{{ $goodBooks := where $books ".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 $goodBooks }}
{{ partial "items/book" (dict
"ctx" .
"NoViewTransition" true
) }}
{{ end }}
</div>
{{ end }}
<!-- ONLY SHOW IN HOME SECTION / END -->
</div>
</article>
{{ partial "footer.html" . }}
{{ end }}
|