From 185280709f8f767d40f9601d389d28e83eb3a32e Mon Sep 17 00:00:00 2001 From: verdant Date: Sat, 28 Feb 2026 21:35:46 +0800 Subject: refactor: archives page - group by year and use
to hide posts by default --- layouts/archives/single.html | 118 ++++++++++++------------------------------- 1 file changed, 32 insertions(+), 86 deletions(-) diff --git a/layouts/archives/single.html b/layouts/archives/single.html index 698fc46..efafdca 100644 --- a/layouts/archives/single.html +++ b/layouts/archives/single.html @@ -1,96 +1,42 @@ {{ define "main" }}
{{- partial "header.html" . -}}
- {{ if .Site.Params.postSearch }} - - - {{ end }} {{ $allPosts := where .Site.RegularPages "Type" "eq" "posts" }} + {{ $allPosts := where .Site.RegularPages "Type" "eq" "posts" }} {{ $excludePosts := where $allPosts "Params.categories" "intersect" (slice "1") }} + {{ $postPages := $allPosts | complement $excludePosts }} - {{ $postPages := $allPosts | complement $excludePosts }} {{ if - .Site.Params.showPostCount }} -

共有 {{ len $postPages }} 篇文章

+ {{ if .Site.Params.showPostCount }} +

共 {{ len $postPages }} 篇文章

{{ end }} -
    - {{ if gt (len $postPages) 0 }} {{ $pagesToShow := $postPages.ByDate.Reverse - }} {{ $currentYear := 0 }} {{ range $pagesToShow }} {{ if .Date }} {{ $year - := .Date.Year }} {{ if and (.Site.Params.groupByYear) (ne $year - $currentYear) }} -

    {{ $year }}

    - {{ $currentYear = $year }} {{ end }} {{ end }} - -
  • - - - - - - {{ .Title }} -
  • - {{ end }} {{ else }} -
  • 暂无文章
  • +
    + {{ if gt (len $postPages) 0 }} + {{ range $postPages.GroupByDate "2006" }} +
    + +

    {{ .Key }} 年 ({{ len .Pages }})

    +
    + +
      + {{ range .Pages }} +
    • + + + + + + {{ .Title }} +
    • + {{ end }} +
    +
    + {{ end }} + {{ else }} +

    暂无文章

    {{ end }} -
+

-{{ end }} +{{ end }} \ No newline at end of file -- cgit v1.2.3