Helo,
Currently, my contents directory is simplified as follows:
/contents
├─ tutorial
│ ├─ preface
│ │ ├─ 1_beginning.md <-- weight: 110
│ │ └─ 2_whatsthis
│ │ ├─ index.md <-- weight: 120
│ │ └─ img.png
│ ├─ quickstart
│ │ ├─ index.md <-- weight: 200
│ │ └─ img.png
│ └─ setup
│ ├─ 1_pre-install
│ │ ├─ index.md <-- weight: 310
│ │ └─ img.png
│ └─ 2_install.md <-- weight: 320
└─ tips
└─ some posts...
When rendering pages, I call the following pager template from the page template.
page.html
{{ partial "pager.html" (dict "criteria" "Weight" "order" "desc" "page" .) }}
pager.html
{{ $page := .page }}
{{ $criteria := .criteria }}
{{ $order := .order }}
{{ $section := $page.Section }}
{{ $pages := where $page.Site.RegularPages "Section" $section }}
{{ $pages := sort $pages $criteria $order }}
<nav class="pager">
<ul class="pager-list">
{{ with $pages.Prev $page }}
<li class="pager-list__link--prev">
<a href="{{ .RelPermalink }}">
{{ if eq $section "tutorial" }}
←{{ .Title }}
{{ else }}
Prev
{{ end }}
</a>
</li>
{{ end }}
{{ with $pages.Next $page }}
<li class="pager-list__link--next">
<a href="{{ .RelPermalink }}">
{{ if eq $section "tutorial" }}
{{ .Title }}→
{{ else }}
Next
{{ end }}
</a>
</li>
{{ end }}
</ul>
</nav>
In this situation, for the “2_whatsthis” page, I expect the “quickstart” page to appear in pager-list__link--next. However, the “quickstart” page is skipped, and instead the “1_pre-install” page ends up in pager-list__link--next. The link to the “quickstart” page appears as pager-list__link--next on the “2_install.md” page.
Each Markdown page is added to menu.toc in its front matter, and in the menu rendering the pages are ordered correctly by Weight (the “quickstart” page comes immediately after the “2_whatsthis” page). For menu rendering, I am using the official Menu templates almost as-is.
I would like the pages in the pager to also be ordered strictly according to Weight. I’d like only “tutorial” pages to be linked together in pager(without “tips”), so I can’t use .Site.Pages.ByWeight.
How can this be achieved?