summaryrefslogtreecommitdiff
path: root/layouts/partials/docs/menu-filetree.html
blob: 5c1f11bb35d931f7025541ee2d3fc2dbd2c3a6a8 (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
<!-- Put configured sections list to .Scratch -->
{{ template "book-get-root-section" . }} 

{{- range .Scratch.Get "BookSections" -}}
  {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
{{- end -}}

{{ define "book-section" }} <!-- Single section of menu (recursive) -->
  <ul>
    {{ range .Section.Sections }}
    <li {{- if .Params.bookflatsection}} class="flat" {{ end }}>
      {{- if .Content -}}
        {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
      {{- else -}}
        {{- template "title" . -}}
      {{- end -}}

      {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage) }}
    </li>
    {{ end }}

    {{ range .Section.Pages }}
    <li>
      {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
    </li>
    {{ end }}
  </ul>
{{ end }}

{{ define "book-page-link" }}
{{- 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 }}