Note: After posting the question, I noticed that I wasn’t using the most recent Hugo version. After updating (0.60.1 -> 0.69.2) my original problem went away but now I have a new one, so I edited the relevant parts of my question.
Let’s say I’m building a site about books. This is the structure I want:
fantasy
george-rr-martin
game-of-thrones.md
clash-of-kings.md
jrr-tolkien
lord-of-the-rings.md
adventure
daniel-defoe
robinson-crusoe.md
So far, I have read:
- https://gohugo.io/getting-started/quick-start/
- https://gohugo.io/content-management/sections/
- https://gohugo.io/content-management/menus/
My understanding so far is that fantasy/adventure are sections in Hugo terminology, and the author names below should probably be sub-sections.
And “Menus” says: “If all you want is a simple menu for your sections, see the Section Menu for Lazy Bloggers”, this is exactly what I want.
Based on all this, here’s what I currently have:
hugo new site hugo-menu-example
cd hugo-menu-example
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo 'theme = "ananke"' >> config.toml
echo 'sectionPagesMenu = "main "' >> config.toml
hugo new fantasy/_index.md
hugo new fantasy/george-rr-martin/_index.md
hugo new fantasy/george-rr-martin/game-of-thrones.md
hugo new fantasy/george-rr-martin/clash-of-kings.md
hugo new fantasy/jrr-tolkien/_index.md
hugo new fantasy/jrr-tolkien/lord-of-the-rings.md
hugo new adventure/_index.md
hugo new adventure/daniel-defoe/_index.md
hugo new adventure/daniel-defoe/robinson-crusoe.md
hugo server --buildDrafts
This gives me a top navigation bar with links named “Adventure” and “Fantasy”.
But when I click on those links, I get to sub-pages with the correct headline (e.g. http://localhost:1313/fantasy/, “Fantasy”), but otherwise the page is empty.
How can I create a list of sub-sections there?
What I like to have is similar to the sub sections page showing a list of its child .md files, like http://localhost:1313/fantasy/george-rr-martin/ showing auto-generated links to game-of-thrones.md
and clash-of-kings.md
.
And maybe a basic question, but it’s not clear to me yet:
At Section Menu for Lazy Bloggers, there’s also this code example:
<nav class="sidebar-nav">
{{ $currentPage := . }}
{{ range .Site.Menus.main }}
<a class="sidebar-nav-item{{if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} active{{end}}" href="{{ .URL }}" title="{{ .Title }}">{{ .Name }}</a>
{{ end }}
</nav>
This sounds like I have to copy and paste it somewhere into my templates…but there are no templates created by me, since I’m using a ready-made theme (Ananke) from Hugo’s theme gallery.