Skip to content

Commit 72c383e

Browse files
authored
feat: allow authors to set the value of reversePagination in page front matter (#674)
* Allow authors to set the reverse pagination setting of a page using front matter * Adding some documentation of the reversePagination front matter custom parameter along with an example of how to use it and why you might want to use it
1 parent 51b5de2 commit 72c383e

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

exampleSite/content/docs/guide/organize-files.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,76 @@ weight: 2
8282
It is recommended to keep the sidebar not too deep. If you have a lot of content, consider **splitting them into multiple sections**.
8383
{{< /callout >}}
8484

85+
## Section Navigation
86+
87+
88+
### Section Pagination Order
89+
90+
The order in which pages, accessed via [`PAGE.PrevInSection`](https://gohugo.io/methods/page/previnsection/) and [`PAGE.NextInSection`](https://gohugo.io/methods/page/nextinsection/) in a [page collection](https://gohugo.io/quick-reference/glossary/#page-collection), are ordered, is reversed by default.
91+
92+
To disable this reversed ordering you can set the `reversePagination` custom parameter in the page front matter to `false`. By default `reversePagination` is set to `true`.
93+
94+
#### Example
95+
96+
Given the following directory structure:
97+
98+
{{< filetree/container >}}
99+
{{< filetree/folder name="content" >}}
100+
{{< filetree/file name="_index.md" >}}
101+
{{< filetree/folder name="blog" state="open" >}}
102+
{{< filetree/file name="_index.md" >}}
103+
{{< filetree/folder name="my-blog-series" state="open" >}}
104+
{{< filetree/file name="_index.md" >}}
105+
{{< filetree/folder name="post-a" state="open" >}}
106+
{{< filetree/file name="index.md" >}}
107+
{{< /filetree/folder >}}
108+
{{< filetree/folder name="post-b" state="open" >}}
109+
{{< filetree/file name="index.md" >}}
110+
{{< /filetree/folder >}}
111+
{{< filetree/folder name="post-c" state="open" >}}
112+
{{< filetree/file name="index.md" >}}
113+
{{< /filetree/folder >}}
114+
{{< /filetree/folder >}}
115+
{{< /filetree/folder >}}
116+
{{< /filetree/folder >}}
117+
{{< /filetree/container >}}
118+
119+
And the following front matter in the posts:
120+
121+
```yaml {filename="content/blog/my-blog-series/post-a/index.md"}
122+
---
123+
title: Post A
124+
weight: 1
125+
---
126+
```
127+
```yaml {filename="content/blog/my-blog-series/post-b/index.md"}
128+
---
129+
title: Post B
130+
weight: 2
131+
---
132+
```
133+
```yaml {filename="content/blog/my-blog-series/post-c/index.md"}
134+
---
135+
title: Post C
136+
weight: 3
137+
---
138+
```
139+
140+
If the reader is at the bottom of `post-b/index.md`, they will see that the next page is `post-a`, and the previous page is `post-c`. This is due to `reversePagination` being set to `true` by default. This is ok when we want our posts to be displayed in chronological order from latest to oldest. However, in the case of a blog series where there are multiple parts, we typically want people to read the first post, and then move to the second and so on. So we want to disable the reversed ordering.
141+
142+
We can turn off `reversePagination` in every blog post in this series by adding the following front matter to `my-blog-series/_index.md`
143+
144+
```yaml {filename="content/blog/my-blog-series/_index.md"}
145+
---
146+
title: My Blog Series
147+
cascade:
148+
params:
149+
reversePagination: false
150+
---
151+
```
152+
153+
We are using [`cascade`](https://gohugo.io/content-management/front-matter/#cascade-1) here to propagate the setting to all posts in the `my-blog-series` so that `reversePagination` is set to `false` for all descendents. This will now ensure that when the reader is on `post-b/index.md` they will see that the next page is `post-c` and the previous page is `post-a`.
154+
85155
## Breadcrumb Navigation
86156

87157
Breadcrumbs are auto-generated based on the directory structure of `/content`.

layouts/blog/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</div>
4141
{{- partial "components/last-updated.html" . -}}
4242
{{- if (site.Params.blog.article.displayPagination | default true) -}}
43-
{{- .Scratch.Set "reversePagination" true -}}
43+
{{- .Scratch.Set "reversePagination" (.Params.reversePagination | default true) -}}
4444
{{- partial "components/pager.html" . -}}
4545
{{ end }}
4646
{{- partial "components/comments.html" . -}}

0 commit comments

Comments
 (0)