#51, Add experimental bookCollapseSection page param to hide nested sections

This commit is contained in:
Alex Shpak
2019-10-09 01:00:26 +02:00
parent 071e069d92
commit e2188136e1
7 changed files with 73 additions and 14 deletions
+11 -5
View File
@@ -11,19 +11,19 @@
{{/* 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) }}
{{ template "book-section-children" (dict "Section" . "CurrentPage" $) }}
{{ end }}
{{ else }}
<ul>
{{ range where $sections "Params.bookhidden" "!=" true }}
{{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
{{ template "book-section" (dict "Section" . "CurrentPage" $) }}
{{ end }}
</ul>
{{ end }}
{{ define "book-section" }}
{{ with .Section }}
<li {{ if .Params.BookFlatSection}} class="book-section-flat" {{ end }}>
<li {{ if .Params.BookFlatSection }} class="book-section-flat" {{ end }}>
{{ if .Content }}
{{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
{{ else }}
@@ -36,7 +36,11 @@
{{ end }}
{{ define "book-section-children" }}
{{ with .Section }}
{{ $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" }}
@@ -48,12 +52,14 @@
{{ end }}
{{ end }}
</ul>
{{ end }}
{{ end }}
{{ end }}
{{ define "book-page-link" }}
{{ with .Page }}
<a href="{{ .RelPermalink }}" {{ if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
<a href="{{ .RelPermalink }}" {{ if eq $.CurrentPage . }} class="active"{{ end }}>
{{ partial "docs/title" . }}
</a>
{{ end }}