diff options
| author | Eltrac <hi@guhub.cn> | 2025-02-02 21:38:33 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-02-02 21:38:33 +0800 |
| commit | 633ed98ce80185fb7cb1f2fe751c1c359398b533 (patch) | |
| tree | 1a08b87dd2cd2c64e015fea56d80fe060289fe16 /layouts | |
| parent | 4b154e28516b51182b186f04348ea92901363005 (diff) | |
feat(theme): shorter index page
show only current year's posts on index page; show all posts in /posts with folded sections
Diffstat (limited to 'layouts')
| -rw-r--r-- | layouts/index.html | 11 | ||||
| -rw-r--r-- | layouts/section/posts.html | 57 |
2 files changed, 65 insertions, 3 deletions
diff --git a/layouts/index.html b/layouts/index.html index 6faabe06..a90d5712 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -53,12 +53,13 @@ </header> {{ end }} - <div id="posts-list"> + <div id="posts-list" class="posts-list"> {{ $currentYear := now.Format "2006" }} <!-- 获取当前年份 --> {{ $isFirstPost := true }} <!-- 用于标记首页的第一篇文章 --> - {{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "2006" -}} + {{ $currentYear := now.Format "2006" }} + {{ range (where (where site.RegularPages "Type" "in" site.Params.mainSections) "Date.Year" "eq" (int $currentYear)).GroupByDate "2006" -}} <section class="posts-year-section"> <h1 class="posts-year-title">{{ .Key }}</h1> @@ -107,7 +108,11 @@ {{ end }} </section> - <hr> + {{ end }} + {{ if eq .Site.Language.Lang "en" }} + <a href="/en/posts/" class="font-mono" id="previous-post-link">PREVIOUS POSTS</a> + {{ else if eq .Site.Language.Lang "zh" }} + <a href="/posts/" id="previous-post-link">往年的文章</a> {{ end }} </div> </article> diff --git a/layouts/section/posts.html b/layouts/section/posts.html new file mode 100644 index 00000000..3c2c862c --- /dev/null +++ b/layouts/section/posts.html @@ -0,0 +1,57 @@ +{{ partial "snippets/document-start.html" . }} + <article class="posts"> + {{ partial "header.html" . }} + <div id="posts-archive" class="posts-list"> + + {{ range (where site.RegularPages "Type" "in" site.Params.mainSections).GroupByDate "2006" -}} + <section class="posts-year-archive"> + <h1 class="posts-year-title"> + {{ .Key }} + <small class="font-mono">{{ len .Pages }} TOTAL POSTS</small> + </h1> + + {{ range .Pages.GroupByDate "January" }} + <details class="posts-month-archive"> + <summary> + <h2 class="posts-month-title"> + {{ .Key }} + <small class="font-mono">{{ len .Pages }} POSTS</small> + </h2> + </summary> + <ul> + {{ range .Pages }} + <li> + <div class="row posts-line"> + <div class="posts-date col-xs-3 col-sm-2"> + <time datetime="{{ .Date.Format "2006-01-02 15:04:05 MST" }}">{{ .Date.Format "Jan 02" }}</time> + </div> + <div class="posts-title col-xs-9 col-sm-10"> + <div class="row"> + <div class="col-xs-11 col-sm-10"> + <a + class="posts-title-link" + href="{{ .RelPermalink }}" + data-umami-event="Click Post Link from Index" + >{{ .Title }}</a> + </div> + <div class="col-xs-1 col-sm-2 posts-categories"> + {{ with .Params.categories }} + <div class="posts-category"> + <a href="/categories/{{ . }}/"><strong>{{ . }}</strong></a> + </div> + {{ end }} + </div> + </div> + </div> + </div> + </li> + {{ end }} + </ul> + </details> + {{ end }} + + </section> + {{ end }} + </div> + </article> +{{ partial "snippets/document-end.html" . }} |
