mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2024-11-29 06:30:20 +00:00
60 lines
1.8 KiB
HTML
60 lines
1.8 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" $.Permalink) }}
|
|
{{ end }}
|
|
{{ else }}
|
|
<ul>
|
|
{{ range where $sections "Params.bookhidden" "!=" true }}
|
|
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
|
|
{{ end }}
|
|
</ul>
|
|
{{ end }}
|
|
|
|
{{ 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>{{ partial "docs/title" . }}</span>
|
|
{{ end }}
|
|
|
|
{{ template "book-section-children" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
|
</li>
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
{{ define "book-section-children" }}
|
|
{{ with .Section }}
|
|
<ul>
|
|
{{ range where .Sections "Params.bookhidden" "!=" true }}
|
|
{{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
|
|
{{ end }}
|
|
{{ range where .Pages "Params.bookhidden" "!=" true }}
|
|
<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 }}>
|
|
{{ partial "docs/title" . }}
|
|
</a>
|
|
{{ end }}
|
|
{{ end }}
|