Hierarchal list template?

So I have content that is hierarchal in nature - volumes / sections / pages

I could use nested content to set this up, that part makes sense. But then how do I set up a list template that would have appropriate titles for each. Lets take the following example

Files are organized as:

  • volume 01
    — section 01
    ----- page 01
    ----- page 02
    — section 02
    ----- page 01
  • volume 02
    — section 01
    ----- page 01

and so on…

But when I set up a list function, I would like it to display the following

Volume 01 - This is my first volume

  • Section 01 - This is a section title
    – Page title for page 01
    – Page title for page 02

and so on… I could use some sort of hierarchal taxonomy for this, but I also feel that would get a bit crazy to manage.

So the questions I have are:

  1. Should I be using nested sections for this?
  2. How do I get the list function to provide names to the different levels that don’t necessarily match the section folder titles - or do i have to give each folder title a complicated name?
content/
├── volume-01/
│   ├── section-01/
│   │   ├── _index.md   <-- section page
│   │   ├── page-01.md
│   │   └── page-02.md
│   └── _index.md       <-- section page
└── _index.md           <-- home page

Adjust the title in front matter of the section pages as needed.

OK, that kind of works.

(1) Subnested breaks my Latest post code - is there a way to look for the latest post easily?
(2) What list code do I need to get a full hierarchal layout?

Otherwise it just displays the top hieararchy, you click through to the next and so on. I want them to just appear as an indented list.

How many levels? Is it just volume, section, page, or do you anticipate subsections beneath sections?

Just those three

list template (recursive)

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  {{ .Content }}
  <ul>
    {{ range .Sections }}
      {{ template "walk" . }}
    {{ end }}
  </ul>
{{ end }}

{{- define "walk" }}
  <li>
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
    {{- with .Pages }}
      <ul>
        {{- range . -}}
          {{- template "walk" . -}}
        {{- end }}
      </ul>
    {{- end }}
  </li>
{{- end -}}

Awesome - thanks…

Now just to figure out how to pull the latest post from the subnested categories for a latest post on the front page.

{{ with index site.RegularPages.ByDate.Reverse 0 }}
  <a href="{{ .RelPermalink }}">{{ .Title }}</a>
{{ end }}

You might have to limit that with a where clause depending on site structure.

Hmm - looks like the theme I am using is using a widget for that. Guess this is my crash course in how the widget system works.

I have it mostly working - thanks @jmooring

The only issue is when I try and list where there are no subsections, the page list doesn’t; seem to trigger at that level.

So if the folder layout is:


Posts
+-- Story
+---- Volume 1
+------ Chapter 1.md
+------ Chapter 2.md
+------ Chapter 3.md
+-- Reference
+------ Chapter 4.md

The subnesting works for Story, but not for Reference where the pages are not subnested; they do not list and I get a blank

{{ define "main" }}

  <div class="w-full max-w-screen-xl lg:px-4 xl:px-8 mx-auto">
    <div class="grid grid-cols-2 lg:grid-cols-8 gap-4 lg:pt-12">
      <div class="col-span-2 lg:col-start-2 lg:col-span-6 bg-secondary-bg rounded px-6 py-8">
        <div class="content">
              <ul>
                {{ range .Sections }}
                  {{ template "walk" . }}
                {{ end }}
              </ul>
  </div></div></div></div></div>
{{ end }}

{{- define "walk" }}
  <li>
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
    {{- with .Pages.ByTitle }}
      <ul>
        {{- range . -}}
          {{- template "walk" . -}}
        {{- end }}
      </ul>
    {{- end }}
  </li>
{{- end -}}

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Hmm - I have it set to private and have the gh action publish to a public one.

I am looking into how to check my security first for pushes and then can open it.