Last active
August 30, 2020 15:00
-
-
Save myobie/00c1c51b18dde80b078e93ff06be17ed to your computer and use it in GitHub Desktop.
Recursively list out sections and pages for a nice hugo navigation for a section or site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ define "main" }} | |
<div id="wrapper"> | |
<div id="sidebar"> | |
{{ partial "sidebar-sections-list.html" .Site.Sections }} | |
</div> | |
<div id="content"> | |
<!-- ... --> | |
</div> | |
</div> | |
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ if gt (len .) 0 }} | |
<ol class="list list-section"> | |
{{ range sort $section_pages "File.Path" }} | |
<li class="list-section-page"> | |
<a href="{{ .Permalink }}">{{ .Title }}</a> | |
{{ partial "sidebar-sections-list.html" (union .Pages .Sections) }} | |
</li> | |
{{ end }} | |
</ol> | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did not know about
len .
, thanks. I was able to solve a totally different problem by trying out your code and using that 👍