I’m trying to create a sidemenu that list out sections in all version of docs. It currently list out some sections and leaves out others. I noticed these other sections that fail to list in sidemenu contain _index.md in their root. For experimental purposes, I deleted those_index.md files and sidemenu was able to list all sections appropriately.How do we make sidemenu list out all the sections without deleting these_index.md files?
My code below:
{{ range .Site.Sections }}
{{ $versionDocsPage := . }}
{{ $versionDocsUrl := .RelPermalink}}
<nav class="docs-menu collapse d-lg-block">
{{ if in $currentPageUrl $versionDocsUrl }}
{{ range (.Pages.GroupByParam "menu").Reverse }}
<div class="sidemenu-docs">
<input type="checkbox" id="menuinput-{{ .Key }}" class="menuinput" {{if eq .Key "thanos"}} checked {{end}}/>
<label for="menuinput-{{ .Key }}" class="menulabel-docs">
<h5 >{{ .Key }}</h5>
<img class="caret-expand" src="/expand.svg" alt="expand" />
</label>
{{ range .Pages }}
<div class="list-group list-group-flush">
<a class="list-group-item list-group-item-action list-group-item-docs py-1" href="{{ .Permalink }}">{{ .Title }}</a>
</div>
{{ end }}
</div>
{{ end }}
{{ end }}
</nav>
{{ end }}
@ju52 Because we have different versions of docs, using the menu system results to an error message because Hugo naturally does not support multiple versions of docs
I had hoped to clone the site and run hugo server to reproduce the problem, but your project is complex, as is its structure. I do not have the time immerse myself in the details.
You indicated that the failure occurs here:
{{ range (.Pages.GroupByParam "menu").Reverse }}
Looking through your content, I see that:
docs/components/compact.md has a menu param
docs/components/_index.md does not have a menu param
A couple of thoughts:
Try adding a menu param to your _index.md files, or
Range through .RegularPages or .RegularPagesRecursive instead of .Pages
@jmooring Thanks for the suggestions. I just tried out all the solutions you pointed out for me but unfortunately, none of them worked. Ranging through .RegularPages and .RegularPagesRecursive were all giving me errors thus stoping the build process. I tried manually adding a menu param to _index.md but it didn’t solve the problem
ERROR 2020/08/21 13:47:31 render of "page" failed: execute of template failed: template: _default/single.html:5:19: executing "main" at <partial "_default/sidemenu.html" .>: error calling partial: "/mnt/c/go-projects/src/github.com/thanos-io/thanos/website/layouts/partials/_default/sidemenu.html:13:29": execute of template failed: template: partials/_default/sidemenu.html:13:29: executing "partials/_default/sidemenu.html" at <.RegularPages.GroupByParam>: can't evaluate field RegularPages in type page.Page
I saw that you worked-around this problem by removing _index.md files in scripts/website/websitepreprocess.sh. However, that creates an additional problem: browsing to a URL such as http://localhost:1313/v0.12/thanos/components/ results in a blank page.
Ranging through .RegularPagesRecursive works for me.
Here’s what I did a few moments ago:
# Clone repository.
git clone https://github.com/thisisobate/thanos
cd thanos
git checkout docs-version
# Revert cbd5ba62656715d609de44867d027a56c2a00485
sed -i 's/^\s\+find.*delete$/:/' "scripts/website/websitepreprocess.sh"
# Preprocess.
./scripts/website/websitepreprocess.sh
# Verify that we have an _index.md to test with.
cat website/docs-pre-processed/v0.12/components/_index.md
# Run hugo server.
cd website
hugo --config hugo.yaml server
Hi @jmooring
I’m wondering the same as to why .RegularPagesRecursive didn’t work for me. I’m thinking maybe it’s due to the fact my Hugo version is v0.72. I will update my Hugo version and try this approach once again. Would definitely get back to you on the result.