Sidebar menu from site content

This is about pointing me in the right direction - I don’t know which of the multitude of options to explore first.

Website structure is the classic topic hierarchy.
However, I want to be able to split a page into a subdirectory without having to redo the sidebar menu.
The rest sort-of follows from this:

  1. The standard use case is an article that started out small, then grew so large that it needs to be split. The file would be changed into a directory, with the file parts going into files in the directory. The goal is that no other editing is required to keep the menu consistent with the directory/file structure.
  2. I want the menu depth shown to be controlled in a hierarchical manner: Have a default depth, and if a directory specifies a different depth, that depth will be valid for that directory and subdirectories.
  3. The header lines inside the files should be included in the menu hierarchy. I.e. if a file is under a default menu depth of 2, the sidebar should display the file’s H1 and H2 headers but not H3, H4, etc.
  4. If a url is at, say, menu level 3, I want links to the previous and next url for levels 1 and 2. E.g. assuming urls are just sequentially numbered, the menu for volume 3.5.2 should roughly look like this:
- home
  - volume 2
    - volume 3.4
    - volume 3.5.2 (this page)
      - volume
    - volume 3.6
  - volume 4

I am not hung up on indent or other theming aspects, right now I just want to make sure that the menu gets the right links.

I believe this requires drawing titles from front matter, page front matter, and headers found inside files.
I have no idea how to deal with that.
I suppose something could be done via templating, but the template language seems scary. (After I had learned a dozen or so language, I found that learning yet another language starts to blur with the various always-similar-except-when-they-aren’t mechanisms from previously-learned language. Sucks to be me I guess… but if learning the template language is the way to go, I’ll just do it.)
Approach #2: Do not use headers at all. This should simplify menu construction greatly (it may even allow using standard menu commands). Instead, I’ll need some mechanism to tell Hugo that, well, the files in directory foo/bar/baz should really be combined into a single page with nice headers and subheaders.
Or maybe there is some different approach that I simply haven’t thought of. I am a huge Hugo noob after all.

What approach would you recommend?
What should I try first?


You can start to define your menu in the config file and in frontmatter, samples here

If your used theme does not support nested menus, you must change the menu template

In the (page) templates you can use the functions .IsMenuCurrent and .HasMenuCurrent

Search the themes for nested menues to use or learn from it.

Sorry, only a point to start from.