summaryrefslogtreecommitdiff
path: root/layouts/library/section.html
blob: 7d4ad3306df2a19d7c3f9b403b58ddc3d9154611 (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
{{ 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" . }}
    {{ 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">
            <a href="/library/2025" class="small-button">
                {{ T "library.viewAllThisYear" }}
                <span class="text-secondary">→</span>
            </a>
            <p class="my-0 mx-4">
              {{ $currentYear := printf "%d" now.Year }}
              {{ range $years }}
                {{ if ne . $currentYear }}<a class="text-secondary" href="{{ printf "/library/%s/" . }}">{{ . }} 年</a>{{ 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 }}