Sorting Menu by weight and reversed

Apologies for the confusion, we generally discourage reviving old topics, as often the participants are no longer active. Hugo development also moves very fast, so usually the old discussion is no longer relevant.


As to the question: I am able to replicate this on a much simpler setup, repo here: https://github.com/pointyfar/hugo-menu-issue-27710

I believe this to be potentially a bug and I would recommend reporting to the issue tracker.

The expected result with

index / weight / name / page
{{ range $k, $v := .Site.Menus.main.ByWeight }}
    {{ $k }} / {{ $v.Weight }} / {{ $v.Name }} / <a href="{{.URL}}">{{ $v.Page }}</a>
    <br>
{{ end }}

should be the following:

index / weight / name / page
0 / 10 / A / Page(/posts/A.md)
1 / 20 / B / Page(/posts/B.md)
2 / 30 / C / Page(/posts/C.md)
3 / 40 / D / Page(/posts/D.md)
4 / 50 / E / Page(/posts/E.md)
5 / 100 / Home / Page(/_index.md)

However occasionally I would get results as below:

0 / 10 / A / Page(/posts/A.md)
1 / 20 / B / Page(/posts/E.md)
2 / 40 / D / Page(/posts/D.md)
3 / 30 / C / Page(/posts/C.md)
4 / 20 / B / Page(/posts/B.md)
5 / 10 / A / Page(/posts/A.md)  <-- appears twice, missing /_index.md
0 / 50 / E / Page(/posts/E.md)
1 / 30 / C / Page(/posts/C.md)
2 / 30 / C / Page(/posts/C.md)  <-- appears twice, missing D.md
3 / 100 / Home / Page(/_index.md)
4 / 10 / A / Page(/posts/A.md)
5 / 20 / B / Page(/posts/B.md)

I am able to reproduce up to at least Hugo version 0.55

1 Like