PaperMod美化归档
主要就是修改归档页面为默认折叠显示,按年月展开 在 layouts\_default\archives.html 中添加 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 {{/* layouts/_default/archives.html —— 年→月二级归档 · 默认全部折叠 · 标题在前 · MM-DD后缀 */}} {{define "main" }} <header class="page-header"> <h1>{{ .Title }}</h1> {{if .Description }}<div class="post-description">{{ .Description | markdownify }}</div>{{end }} </header> {{- $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} {{if site.Params.ShowAllPagesInArchive }}{{ $pages := site.RegularPages }}{{ end }} {{- $monthMap := dict "January" "01" "February" "02" "March" "03" "April" "04" "May" "05" "June" "06" "July" "07" "August" "08" "September" "09" "October" "10" "November" "11" "December" "12" }} {{range $pages.GroupByPublishDate "2006" }} {{if ne .Key "0001" }} <section class="archive-year"> <!-- ★ 把所有 open 属性删掉 = 默认折叠 ★ --> <details> <summary class="archive-year-header" id="{{ .Key }}"> <span class="archive-toggle"></span> {{ .Key }} 年 <sup class="archive-count">{{ len .Pages }} 篇</sup> </summary> <div class="archive-year-content"> {{range .Pages.GroupByDate "January" }} {{- $monthNum := index $monthMap .Key }} {{- $monthID := printf "%s-%s" $.Key $monthNum }} <details> <summary class="archive-month-header" id="{{ $monthID }}"> <span class="archive-toggle"></span> {{ .Key }} <sup class="archive-count">{{ len .Pages }} 篇</sup> </summary> <div class="archive-posts"> {{range .Pages.ByPublishDate.Reverse }} {{if eq .Kind "page" }} <article class="archive-entry"> <h3 class="archive-entry-title entry-hint-parent"> <a href="{{ .Permalink }}">{{ .Title | markdownify }}</a> {{if .Draft }}<span class="entry-hint" title="Draft">[草稿]</span>{{end }} <span class="archive-date-postfix"> ・ {{ .PublishDate.Format "01-02" }} </span> </h3> <div class="archive-meta">{{partial "post_meta.html" . -}}</div> <a class="entry-link" aria-label="post link to {{ .Title }}" href="{{ .Permalink }}"></a> </article> {{end }} {{end }} </div> </details> {{end }} </div> </details> </section> {{end }} {{end }} <style> details summary { list-style: none; cursor: pointer; user-select: none; } details summary::-webkit-details-marker { display: none; } .archive-toggle { display: inline-block; width: 1.2em; font-size: 0.85em; margin-right: 0.3em; opacity: 0.8; transition: opacity 0.2s; } details>summary .archive-toggle::before { content: "▶"; } /* 折叠时右箭头 */ details[open]>summary .archive-toggle::before { content: "▼"; } /* 展开时下箭头 */ .archive-year-header { font-size: 1.9em; font-weight: 600; margin: 1.8em 0 0.4em; } .archive-month-header { font-size: 1.55em; font-weight: 600; margin: 1.2em 0 0.4em 1.5em; } .archive-year-content { margin-left: 1.5em; margin-top: -0.4em; } .archive-posts { margin: 0.6em 0 1.8em 3em; padding-left: 0.5em; } .archive-count { font-size: 0.75em; color: var(--secondary); margin-left: 0.5em; font-weight: 500; vertical-align: middle; opacity: 0.9; } .archive-entry-title { font-size: 1.25em !important; margin: 0 0 0.35em !important; font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 0.8em; } .archive-entry+.archive-entry { margin-top: 1rem; } .archive-date-postfix { font-size: 0.9em; color: var(--secondary); font-weight: normal; opacity: 0.9; flex-shrink: 0; } summary:hover { color: var(--tertiary); } summary:hover .archive-toggle { opacity: 1; } </style> {{end }}