(sub)menu order if no weight assigned

I’m running the hugo-learn-theme ( not sure whether there are newer ones that are recommended to get into hugo?) and I’m trying to figure out how my submenu items are ordered.

I’ve set weights for my main menu items, so I obviously don’t want to switch to SortByTitle in the Site.Params / config.toml

I’ve assumed that once no weights are given to my pages, hugo would default to alphabetical listing, but that did not happen, rather I found an order like this:

Edit: mahoromax / anonym-stories · GitLab trimmed repository clone for local testing. See the “Church” menu entry’s submenu items.
I renamed “Community” to “Choir” in the anonymization process.

[Main menu item]

  • Community B…44
  • Ing…
  • Community M…44
  • Community B…42
  • Community S…

I’ve looked into the dates, linktitle, description. Some items (the second Community B and leo… are pages with folder/index.md while the others are just title.md or /folder/title.md
But the order in the submenu does even split the two pages that start with Community 44.

So the questions I have are:

  • Can I sort the submenu differently than the main items?
  • What does this sorting order follow?

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

I was thinking about it, but since I was interested in the principle - not a practical solution to the example, I did skip it.

Here is a anonymized repo of this project (deleted images and probably broke lots of stuff, but it does redner with hugo serve - the CI/CD won’t work I suppose.

mahoromax / anonym-stories · GitLab

The question here remains, what logic does the order of those 2nd level entries follow?

The order of the first level is determined here:
https://gitlab.com/mahoromax/anonym-stories/-/blob/master/hugo/themes/hugo-theme-learn/layouts/partials/menu.html#L26-34

The order of the second level is determine here:
https://gitlab.com/mahoromax/anonym-stories/-/blob/master/hugo/themes/hugo-theme-learn/layouts/partials/menu.html#L139

So, if you want a determinate sort, you need to add weight to the front matter of the pages in the second level.

Note that weight can be positive or negative, but not zero (indeterminate).

I learnt something new today. I had to ‘hack’ a completed project that needed a few articles before others arranged by weight. The negative weight will come in handy.

Thank you for the answer. I indeed did not find where it the order was decided - I did figure out to add weights to create an order though, but I forgot to add it to the original post.

What I think is still unanswered is: what is the order that happened when I did not use weights on the second level ? What did Hugo default to then?

By .Date (descending).

https://gohugo.io/templates/lists#default-weight--date--linktitle--filepath

Oh I see. Thank you.
I still need to work myself into hugo (and Go) way more, I did not consider the submenu as a list.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.