hugo-book/layouts/partials/docs/menu-filetree.html

47 lines
1.4 KiB
HTML
Raw Normal View History

<!-- Put configured sections list to .Scratch -->
2018-09-17 23:35:54 +00:00
{{ template "book-get-root-section" . }}
2018-09-05 14:22:04 +00:00
2018-09-17 23:35:54 +00:00
{{- range .Scratch.Get "BookSections" -}}
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
{{- end -}}
2018-09-17 23:35:54 +00:00
{{ define "book-section" }} <!-- Single section of menu (recursive) -->
<ul>
{{ range .Section.Sections }}
<li {{- if .Params.bookflatsection}} class="flat-section" {{ end }}>
{{- if .Content -}}
2018-09-17 23:35:54 +00:00
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
{{- else -}}
{{- template "title" . -}}
{{- end -}}
2018-09-17 23:35:54 +00:00
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
</li>
{{ end }}
{{ range .Section.Pages }}
<li>
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
</li>
{{ end }}
2018-09-17 23:35:54 +00:00
</ul>
{{ end }}
2018-09-17 23:35:54 +00:00
{{ define "book-page-link" }}
{{- with .Page -}}
<a href="{{ .RelPermalink }}" {{- if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
{{- template "title" . -}}
</a>
{{- end -}}
2018-09-05 14:22:04 +00:00
{{ end }}
{{ define "book-get-root-section" }}
2018-09-17 23:35:54 +00:00
<!-- 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 12:36:16 +00:00
{{ else }}
{{ $bookSections := where .Site.Sections "Section" $bookSection }}
{{ .Scratch.Set "BookSections" $bookSections }}
{{ end }}
{{ end }}