In PAGES.Next, page order may not follow Weight depending on the directory structure

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?

Does anything change when you have only= and NOT := in the second line?

How exactly does your front matter look like? weight is on the first level of your front matter?

Do preface, quickstart, and setup have a weight? I think what is happening is that GoHugo first sorts by those, then within those.

site.Pages.ByWeight can still be used in connection with the same where that you are using. just don’t use $page.Site.RegularPages there, but the variable that you do the site.Pages.ByWeight with.

Thank you for your reply. Initially, my front matter looked like the following:

quickstart/index.md

+++
title = "Quick Start"
description = ""
date = "2023-07-15T20:50:34+09:00"
slug = "quickstart"
[menu.toc]
    weight = 200
    identifier = "quickstart"
+++

After changing weight to the first level as shown below, it started to work as intended. Thank you very much for pointing this out.

+++
title = "Quick Start"
description = ""
date = "2023-07-15T20:50:34+09:00"
slug = "quickstart"
weight = 200
[menu.toc]
    identifier = "quickstart"
+++