Some Sections not showing in Hugo

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 }}

sections should have an _index.md file and content!

Why not using the menu system??

@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

Can you share the repository? If not, look at each possible failure point. Here’s the above code simplified:

{{ range x }}
  {{ if foo }}
    {{ range y }}
      {{ range z }}
        {{ ... }}
      {{ end }}
    {{ end }}
  {{ end }}
{{ end }}

Which range is failing: x, y, or z?
Is the conditional (if) returning the expected value?

@jmooring This is the link to the repository: https://github.com/thisisobate/thanos/tree/docs-version/website

Please comment:

Which range is failing: x, y, or z?
Is the conditional ( if ) returning the expected value?

@jmooring from the illustration you gave, range y is failing

Yes, the condition (if) is returning the correct value

@jmooring A much better link to the repository: https://github.com/thisisobate/thanos/blob/docs-version/website/layouts/partials/_default/sidemenu.html

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:

  1. Try adding a menu param to your _index.md files, or
  2. 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

Did you try to troubleshoot the errors?

@jmooring not really. The error message weren’t that informative. Would share a snippet shortly

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

Now visit http://localhost:1313/v0.12/thanos/getting-started.md/. The left menu has only two sections: Thanos and Contributing.

Now modify line 13 of website/layouts/partials/_default/sidemenu.html, replacing:

{{ range (.Pages.GroupByParam "menu").Reverse }}

With:

{{ range (.RegularPagesRecursive.GroupByParam "menu").Reverse }}

Then refresh your browser and visit http://localhost:1313/v0.12/thanos/getting-started.md/ again. The left menu now contains all of the sections: Thanos, Proposals, Operating, Contributing, and Components.

Also visit http://localhost:1313/v0.12/components/ and note that the page is not blank.

I’m not sure why your testing of .RegularPagesRecursive failed on Friday of last week, but it’s working for me.

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.

Thanks for all you do @jmooring!

You are welcome. RegularPagesRecursive has been available since v0.68 according to https://gohugo.io/news/0.68.0-relnotes/.

wow…I guess it’s not a Hugo version issue

@jmooring It’s still printing same error message

Error: Error building site: failed to render pages: 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:36": execute of template failed: template: partials/_default/sidemenu.html:13:36: executing "partials/_default/sidemenu.html" at <.RegularPagesRecursive.GroupByParam>: can't evaluate field RegularPagesRecursive in type page.Page
make: *** [Makefile:310: web-serve] Error 255

I just ran this instead of the usual make web-serve and it worked!

I guess it’s an issue that has to do with our make command I guess…

Thank you so much @jmooring
Really appreciate all the help

Thank goodness. This one was complicated. I’m glad it is behind us!