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

47 lines
1.4 KiB
HTML
Raw Normal View History

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