summaryrefslogtreecommitdiff
path: root/layouts/partials/docs/menu-filetree.html
blob: e3db53b0e8e7e1ec9aafd4ac471eea0d88be58b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{{ $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 .IsSection }}
        {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
      {{ else if and .IsPage .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.RelPermalink .RelPermalink }}active{{ end }}">
    {{- partial "docs/title" . -}}
  </a>
  {{ else }}
  <span>{{- partial "docs/title" . -}}</span>
  {{ end }}
{{ end }}
{{ end }}