TOC based on pages in a specifc folder, not sections inside a page

I have the following two folders:

  • content/guides/chapter-one
  • content/guides/chapter-two

I want to write a partial that traverses content/guides and creates a TOC like this:

  • Chapter one
    – first md file in content/guides/chapter-one
    – second md file in content/guides/chapter-one
    – etc.
  • Chapter two
    – first md file in content/guides/chapter-two
    – second md file in content/guides/chapter-two
    – etc.

Every item in the above list would link to their corresponding .md file. That includes, “Chapter one” and “Chapter two” which serve as ‘homepages’ for each chapter and I am guessing they would need to be index.md files.

I am also aware I will need to use front matter to weight the individual files and control their order.

If someone could help me understand how I need to approach this to begin to bring it all together that would be very helpful. I think my file structure is the right way to approach it but I’m not really making progress.

As for the partial, I’ve played around with:

{{- range where .Site.RegularPages "Type" "guides" -}}

but can’t figure out how to traverse the files properly.

Thanks

Here’s an example:

git clone --single-branch -b hugo-forum-topic-44216 https://github.com/jmooring/hugo-testing hugo-forum-topic-44216
cd hugo-forum-topic-44216
hugo server

Files of interest:

  • layouts/partials/menus/section.html
  • layouts/_default/baseof.html (line 27)

Thanks a lot. I can’t claim to fully understand how that partial works but I’ve followed it enough to get it working for my specific application. Much appreciated.

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