Nested sections without _index.md


#1

While I’ve seen nested sections covered in other posts, and I’ve got them to work according to the documentation by adding a _index.md file to the lower most sections, this is not ideal because it takes the simplicity out of the content folder and affects the .Title and prevents menus for the top section as well. I really just want a list for each nested section. I found an old example, but I can’t get it to work:

https://vjeantet.github.io/hugo-menu-show/

There may be a working example, but I can’t find one anywhere. I’d love to see this supported so that I can have a more simplified content structure.


#2

That is a 3 year example, long before Nested Sections.

Have a look at this repository instead:

It is by the maintainer of Hugo and last time I checked it had a Menu with the full Section Tree.


#3

Thanks… I’ve seen that, but from what I can tell it just displays a menu of the nested sections, instead of actually rendering them. Even in the source code it is still using _index.md in the lower most sections in order to create a list of the sections, so content/section1/section2/test.md without an _index.md will render baseurl/section1/section2/test/, but baseurl/section1/section2/ will be a blank page.


#4

Ok. Let me be clear. There can be no Nested Sections without _index.md because this is what activates them.

But do note that an _index.md is not needed to activate a top level Section or .FirstSection if you like.

The simplest way I found to create a conditional Nested Menu by Section is roughly outlined here:

To modify the layout of Nested Sections I use the following:


#5

Thank you, I’ve got that part working, but what I’m really trying to do is find a way around the _index.md requirement. Requiring _index.md in subsections is specific to Hugo and makes the content less portable overall. If you want to import a flat-file structure for Markdown notes, then normally you wouldn’t create these files. It would make more sense for Hugo to only use that file for creating custom titles and metadata for subsections, but still render the subsections without it if there is other markdown files present.


#6

And if the _index.md was only for front matter, would you use it selectively?
What kind of <title> do you think that a rendered Nested Section list would have without front matter?

I’ll tell you what it would be: Either the PATH hierarchy of the Nested Section or the parent .Section or the .Site.Title.

Regarding your comment about portability, I don’t quite grasp how the use of _index.md reduces it.

You can always use a script to batch delete every single _index.md recursively from the root of a Hugo project whenever you feel like moving your project to another framework.


#7

If _index.md was optional, then yes there may be times I would still use it to set a different title. I would want to use the filename/dirname generally. I’m currently using {{or .Title (replace .TranslationBaseName "-" " "|title)} to generate the title.

In terms of portability, I just don’t understand why you’d need that file. Many times you’re simply adding it so that your subsections work, when the first sections work as expected.


#8

Are you asking me about the rationale of Development decisions that were made after a process that took months?

Well… Here you go (it’s a bit of a long read):


#9

Since it isn’t supported, then consider my message a feature request. Hopefully my post made enough sense to consider it as a future enhancement. All other functionality of _index.md could remain the same.