mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-12-01 23:45:58 +00:00
68 lines
2.0 KiB
HTML
68 lines
2.0 KiB
HTML
{{ $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 }}
|
|
|
|
|
|
{{ $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" $) }}
|
|
{{ end }}
|
|
{{ else }}
|
|
<ul>
|
|
{{ range where $sections "Params.bookHidden" "!=" true }}
|
|
{{ template "book-section" (dict "Section" . "CurrentPage" $) }}
|
|
{{ end }}
|
|
</ul>
|
|
{{ end }}
|
|
|
|
{{ define "book-section" }}
|
|
{{ with .Section }}
|
|
<li {{- if .Params.BookFlatSection }} class="book-section-flat" {{ end }}>
|
|
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
|
|
{{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
|
</li>
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ define "book-section-children" }}
|
|
{{ $ancestor := .Section.IsAncestor .CurrentPage }}
|
|
{{ $collapsed := .Section.Params.bookCollapseSection }}
|
|
|
|
{{ if or $ancestor (not $collapsed) }}
|
|
{{ with .Section }}
|
|
<ul>
|
|
{{ range where .Pages "Params.bookhidden" "!=" "true" }}
|
|
{{ if eq .Kind "section" }}
|
|
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
|
{{ else if and (eq .Kind "page") .Content }}
|
|
<li>
|
|
{{- template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) -}}
|
|
</li>
|
|
{{ end }}
|
|
{{ end }}
|
|
</ul>
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ end }}
|
|
|
|
{{ define "book-page-link" }}
|
|
{{ with .Page }}
|
|
{{ if .Content }}
|
|
<a href="{{ .RelPermalink }}" class="
|
|
{{- if and .Params.bookCollapseSection .IsSection }}collapsed {{ end }}
|
|
{{- if eq $.CurrentPage . }}active{{ end }}">
|
|
{{- partial "docs/title" . -}}
|
|
</a>
|
|
{{ else }}
|
|
<span>{{- partial "docs/title" . -}}</span>
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|