Skip to content

Commit 734670c

Browse files
committed
feat: group posts with any layout in archives page
Close #322
1 parent 98ce592 commit 734670c

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

docs/pages/_meta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"social-comments": "Social Comments",
1515
"post-page": "Post Page",
1616
"about-page": "About Page",
17+
"archives-page": "Archives Page",
1718
"search": "Search",
1819
"summary-images": "Summary Images",
1920
"syntax-highlighting": "Syntax Highlighting",
2021
"custom-archives-header": "Custom Archives Header",
2122
"social-links": "Social Links",
22-
"custom-nav-items": "Custom Nav Items",
2323
"light-and-dark-mode": "Light and Dark Mode",
2424
"custom": "Custom Theme",
2525
"decap-cms": "Decap CMS",

docs/pages/archives-page.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Archives Page
2+
3+
Archives page is a list of all posts by timeline. It will be rendered as `/posts`.
4+
5+
## Custom Header
6+
7+
You can custom your archives page's header by placing a `_index.md` in `content/posts`.
8+
9+
For example, paste below in `_index.md`:
10+
11+
```markdown
12+
---
13+
title: Archives
14+
---
15+
16+
All posts by timeline.
17+
```
18+
19+
These will be rendered as:
20+
21+
```html
22+
<h1 class="text-3xl">Archives</h1>
23+
<p class="text-sm">All posts by timeline.</p>
24+
```
25+
26+
One is the title, and the other is the description.
27+
28+
## Custom Group Layout
29+
30+
The timeline is grouped by year by default. You can use a custom layout to group by month or any other way.
31+
This can be done by adding a `groupLayout` field in the front matter of the `_index.md` file.
32+
33+
For example, in `content/posts/_index.md`:
34+
35+
```markdown
36+
---
37+
groupLayout: Jan 2006
38+
---
39+
```
40+
41+
For how to define the layout, please refer to [layout string](https://gohugo.io/methods/pages/groupbydate/#layout-string).

docs/pages/custom-archives-header.md

-24
This file was deleted.

layouts/section/posts.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ <h1 class="text-3xl">
1616

1717
<div class="max-w-[65ch] mx-auto mt-8 lg:mt-12">
1818
<ul class="timeline timeline-vertical">
19-
{{ range .Pages.GroupByDate "2006" }}
19+
{{ $groupLayout := default "2006" .Params.groupLayout }}
20+
{{ range .Pages.GroupByDate $groupLayout }}
2021
<li class="[--timeline-col-start:64px]">
2122
<hr class="dark:bg-base-content" />
2223
<div class="timeline-start !justify-self-start">

0 commit comments

Comments
 (0)