Generating list pages for content in subdirectories?

Hey all – apologies if this is a dumb question, I’m a newbie building my first Hugo site and threads like this one and this one have me confused. I’m using version 0.18.1.

Let’s say I have my content organized like this:

├─ Section
|     |── Bucket A
│     |    ├── article1.md
│     |    ├── article2.md  
│     |    └── article3.md
|     |── Bucket B
│     |    ├── article4.md
│     |    ├── article5.md  
│     |    └── article6.md

What I want to be able to do is this:

  1. Have an index.html page under “Section” that lists all six articles from across both buckets.
  2. Have index.html pages under “Bucket A” and “Bucket B” that list all articles within their bucket.
  3. Have a menu on all pages that lists Bucket A and Bucket B, with each linked to the index.html listing the contents of that bucket.

This seems like it should be easier to do than it’s turning out to be.

I’ve been able to get the menu (#3) sort of working, by setting an _index.md file in the directory of each Bucket that adds its identifier and weight as an entry in a Hugo menu, and then in the front matter of each article assigning the relevant Bucket’s identifier as the parent for that article. That gives me a listing page for “Section” that includes all sub-articles across all Buckets. But it doesn’t result in index.html pages being created within each Bucket, and the menu items both link to that top-level listing page.

I can make Hugo generate index.html files within each Bucket by renaming those _index.md files to index.md (no leading underscore), and adding url fields to the menu item set in those index.md files for each Bucket. But the resulting index.html files are generated as single content pages, not list pages, so they inherit the wrong template from the theme.

My guess (and I should say up front that it’s an extremely uneducated guess) is that I’m running into a gap between code and documentation resulting from the switch in version 0.18 to the “everything’s a page” content model as described in “Content for home page and other list pages” in the docs. But I’m not sure how to go about organizing things in current versions of Hugo to work as I described at the top, and haven’t been able to piece that together from Googling and searching the forums on my own. So I figured I’d come to the experts.

Again, apologies if this is a dumb question or has already been answered elsewhere. And thanks in advance for any help you can provide!

Following up on my own question – further perusal of the docs makes it sound like my problem may have been expecting to use a list template at all in this scenario, as (if I’m reading them correctly) it sounds like they only come into play in a few specifically-defined places, namely sections and taxonomies.

If that’s the case it would explain why the subdirectories aren’t getting index pages, since they’re not taxonomies and sections are top-level-only (right?). So the only templates that would ever apply to pages in those subdirectories are the various single content templates.

So maybe the solution is to abandon my current subdirectory-based approach to organizing my content entirely and replace it with taxonomies? I dunno. It seems weird to not be able to point Hugo at a directory and have it build a list of all the content in that directory, but that could just be me not having fully wrapped my brain around the way Hugo works yet…

Yes…

OK, so at least I’m understanding that part correctly. Good to know, thanks!

So is there an official word on how to approach content organization and/or template development to set things up in this fashion? Or is it just a case of Hugo doesn’t work like that?

This has been discussed endlessly before, so use the search.