hugo-book-theme/layouts/partials/docs/nav-filetree.html

51 lines
1.5 KiB
HTML
Raw Normal View History

<!-- Put configured sections list to .Scratch -->
{{ template "book-get-root-section" . }}
2018-09-05 16:22:04 +02:00
2018-09-12 14:36:16 +02:00
<ul>
2018-09-05 16:22:04 +02:00
{{ range .Scratch.Get "BookSections" }}
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
{{ end }}
2018-09-12 14:36:16 +02:00
</ul>
2018-09-05 16:22:04 +02:00
<!-- Single section of menu (recursive) -->
{{ define "book-section" }}
<li {{ if .Section.Params.booktopsection }}class="book-nav-section"{{ end }}>
{{ with .Section}}
{{- if .Content -}}
<a href="{{ .RelPermalink }}">{{- template "title" . -}}</a>
{{- else -}}
{{- template "title" . -}}
{{- end -}}
{{ end }}
<ul>
2018-09-05 16:22:04 +02:00
{{ range .Section.Sections }}
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
{{ end }}
{{ range .Section.Pages }}
<li>
<a href="{{ .RelPermalink }}" class="{{ if eq $.CurrentPage .Permalink }}active{{ end }}">
{{- template "title" . -}}
2018-09-05 16:22:04 +02:00
</a>
</li>
{{ end }}
</ul>
</li>
{{ end }}
{{ define "book-get-root-section" }}
<!-- Complex logic to guess page title without .Title specified -->
{{ $bookSection := default "docs" .Site.Params.BookSection }}
{{ if eq $bookSection "*" }}
{{ .Scratch.Set "BookSections" .Site.Sections }}
2018-09-12 14:36:16 +02:00
{{ else }}
{{ $bookSections := where .Site.Sections "Section" $bookSection }}
{{ .Scratch.Set "BookSections" $bookSections }}
2018-09-05 16:22:04 +02:00
{{ if eq (len $bookSections) 1 }}
{{ $singleSection := index $bookSections 0 }}
{{ .Scratch.Set "BookSections" $singleSection.Sections }}
{{ end }}
{{ end }}
{{ end }}