List section titles alphabetically?


#1

Sorry to post, I have looked through the whole Hugo doc and cannot find a clear answer. I am not dev, more a power user with some HTML/CSS and am using Hugo to organize some internal docs. So far so good, think I understand the basic concepts. I am using the Learn theme. This gives a list of section titles on the left, which match the folder titles in the content section. Took a day to work out where to configure non pluralization of these titles (but that now works).
Now the problem is, these titles are not in alphabetical order. I am guessing they are ordered by date or weight. I looked here https://gohugo.io/templates/lists/ but cannot see how to config the site to do this ordering alphabetically. I tried (probably stupidly) adding a “by-title.html” file containing:

    {{ range .Data.Pages.ByTitle }}
  • {{ .Title }}

    {{ .Date.Format "Mon, Jan 2, 2006" }}
  • {{ end }}

in my_site\layouts\partials but that has no effect.
The theme has a file in layouts_default, called list.html, containing :slight_smile:{{ partial “header.html” . }}

{{ .Content }}

{{with .Params.LastModifierDisplayName}} {{ . }} {{with $.Date}} {{ .Format "02/01/2006" }}{{end}} {{end}}

{{ partial “footer.html” . }}

I feel this may be the file that controls my section list but I don’t understand its content and I am nervous about messing it up. Can anyone suggest what I should modify and how to achieve my goal? I am frustrated that this is so difficult for me, as this seems to be a task that should be easy to fix . The documents within the sections are also not ordered alphabetically but at this point, I am past caring about those.
I am sorry that I cannot post the site, as it is internal doc. A big thanks to anyone who at least sees what the heck I am trying to do!


#2

You should try the sort function.

But if this is for a language with accents alphabetical sorting doesn’t work and there is an open Github issue

I stumbled upon this once and I simply assigned weight in my sections’ _index.md to get the order I needed.


#3

No, it’s for English. But I am unsure if this is what I want as I am referring to the main table of contents for all the section titles. I was thinking there was a configuration file for this and I just needed to change the parameters it uses? But I have no idea where it is located.