diff options
Diffstat (limited to 'layouts/partials/docs/menu-filetree.html')
-rw-r--r-- | layouts/partials/docs/menu-filetree.html | 76 |
1 files changed, 44 insertions, 32 deletions
diff --git a/layouts/partials/docs/menu-filetree.html b/layouts/partials/docs/menu-filetree.html index 8530656..b0f28c0 100644 --- a/layouts/partials/docs/menu-filetree.html +++ b/layouts/partials/docs/menu-filetree.html @@ -1,47 +1,59 @@ -<!-- Put configured sections list to .Scratch --> -{{ template "book-get-root-section" . }} +{{ $bookSection := default "docs" .Site.Params.BookSection }} +{{ if eq $bookSection "*" }} + {{ .Scratch.Set "BookSections" .Site.Sections }} +{{ else }} + {{ $bookSections := where .Site.Sections "Section" $bookSection }} + {{ .Scratch.Set "BookSections" $bookSections }} +{{ end }} -{{- range .Scratch.Get "BookSections" -}} - {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }} -{{- end -}} -{{ define "book-section" }} <!-- Single section of menu (recursive) --> +{{ $sections := .Scratch.Get "BookSections" }} +{{/* If there is only one section to render then render its children, else render all sections */}} +{{ if eq (len $sections) 1 }} + {{ with index $sections 0 }} + {{ template "book-section-children" (dict "Section" . "CurrentPage" $.Permalink) }} + {{ end }} +{{ else }} <ul> - {{ range .Section.Sections }} - <li {{- if .Params.bookflatsection}} class="flat-section" {{ end }}> - {{- if .Content -}} - {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} - {{- else -}} - {{- template "title" . -}} - {{- end -}} + {{ range $sections }} + {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }} + {{ end }} + </ul> +{{ end }} - {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }} - </li> +{{ define "book-section" }} +{{ with .Section }} + <li {{ if .Params.bookFlatSection}} class="book-section-flat" {{ end }}> + {{ if .Content }} + {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} + {{ else }} + <span>{{ template "title" . }}</span> {{ end }} - {{ range .Section.Pages }} + {{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }} + </li> +{{ end }} +{{ end }} + +{{ define "book-section-children" }} +{{ with .Section }} + <ul> + {{ range .Sections }} + {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }} + {{ end }} + {{ range .Pages }} <li> {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }} </li> {{ end }} </ul> {{ end }} +{{ end }} {{ define "book-page-link" }} -{{- with .Page -}} -<a href="{{ .RelPermalink }}" {{- if eq $.CurrentPage .Permalink }} class="active"{{ end }}> - {{- template "title" . -}} -</a> -{{- end -}} +{{ with .Page }} + <a href="{{ .RelPermalink }}" {{ if eq $.CurrentPage .Permalink }} class="active"{{ end }}> + {{ template "title" . }} + </a> +{{ end }} {{ 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 }} - {{ else }} - {{ $bookSections := where .Site.Sections "Section" $bookSection }} - {{ .Scratch.Set "BookSections" $bookSections }} - {{ end }} -{{ end }}
\ No newline at end of file |