diff options
| author | Eltrac <hi@guhub.cn> | 2025-04-25 22:50:05 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-04-25 22:50:05 +0800 |
| commit | 176bcb5e829dff6247075f47b6f7ef37c0c4c062 (patch) | |
| tree | 2c1060231ae3be716fe223b6378f3d53b50238f5 /layouts | |
| parent | 655ce76bbaf6b39b026f5f9065922178a80fc7e4 (diff) | |
feat: open first month's post section
Former-commit-id: 190312f35c50ee0726e213ea0297ead16bd52d3e
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/_default/section.html | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/layouts/_default/section.html b/layouts/_default/section.html index d6553f28..1a0471ca 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -4,6 +4,7 @@ <div id="posts-archive" class="posts-list"> {{ partial "components/heatmap.html" . }} <!-- Post Archive List --> + {{ $first := true }} <!-- 在循环外定义一次 $first 变量 --> {{ range (where site.RegularPages "Type" "eq" "posts").GroupByDate "2006" -}} <section class="posts-year-archive"> <h1 class="posts-year-title"> @@ -11,40 +12,40 @@ <small class="font-mono">{{ T "archivePage.postCountAnnual" (len .Pages) }}</small> </h1> - {{ range .Pages.GroupByDate "January" }} - <details class="posts-month-archive"> - <summary> - <h2 class="posts-month-title"> - {{ .Key }} - <small class="font-mono">{{ T "archivePage.postCountMonthly" (len .Pages) }}</small> - </h2> - </summary> - <div class="term-list"> - <ul class="term-list-posts"> - {{ range .Pages }} - <li> - <div style="display: flex; gap: 1rem;"> - <time class="font-mono"> - {{ .Date.Format "Jan 06" }} - </time> - <a href="{{ .Permalink }}"> - {{ .Title }} - </a> - </div> - <div class="posts-item-category"> - {{ with .Params.categories }} - <a href="/categories/{{ . }}"> - {{ . }} - </a> - {{ end }} - </div> - </li> - {{ end }} - </ul> - </div> - </details> - {{ end }} - + {{ range .Pages.GroupByDate "January" }} <!-- 这里每个月的循环 --> + <details class="posts-month-archive"{{ if $first }} open{{ end }}> + <summary> + <h2 class="posts-month-title"> + {{ .Key }} + <small class="font-mono">{{ T "archivePage.postCountMonthly" (len .Pages) }}</small> + </h2> + </summary> + <div class="term-list"> + <ul class="term-list-posts"> + {{ range .Pages }} + <li> + <div style="display: flex; gap: 1rem;"> + <time class="font-mono"> + {{ .Date.Format "Jan 06" }} + </time> + <a href="{{ .Permalink }}"> + {{ .Title }} + </a> + </div> + <div class="posts-item-category"> + {{ with .Params.categories }} + <a href="/categories/{{ . }}"> + {{ . }} + </a> + {{ end }} + </div> + </li> + {{ end }} + </ul> + </div> + </details> + {{ $first = false }} <!-- 将 $first 设置为 false 只在第一个月份显示后 --> + {{ end }} </section> {{ end }} </div> |
