aboutsummaryrefslogtreecommitdiff
path: root/layouts/partials/docs/menu-filetree.html
blob: 8384f0f59d793268b8d8eea1b0ad9aa4a2e6540a (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
{{ $bookSection := default "docs" .Site.Params.BookSection  }}
{{ if eq $bookSection "*" }}
  {{ $bookSection = "/" }}{{/* Backward compatibility */}}
{{ end }}

{{ with .Site.GetPage $bookSection }}
  {{ template "book-section-children" (dict "Section" . "CurrentPage" $) }}
{{ end }}

{{ define "book-section-children" }}{{/* (dict "Section" .Section "CurrentPage" .CurrentPage) */}}
  <ul>
    {{ range (where .Section.Pages "Params.bookhidden" "ne" true) }}
      {{ if .IsSection }}
        <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>
      {{ else if and .IsPage  }}
        <li>
          {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
        </li>
      {{ end }}
    {{ end }}
  </ul>
{{ end }}

{{ define "book-page-link" }}{{/* (dict "Page" .Page "CurrentPage" .CurrentPage) */}}
  {{ $current := eq .CurrentPage .Page }}
  {{ $ancestor := .Page.IsAncestor .CurrentPage }}

  {{ if .Page.Params.bookCollapseSection }}
    <input type="checkbox" id="section-{{ md5 .Page }}" class="toggle" {{ if or $current $ancestor }}checked{{ end }} />
    <label for="section-{{ md5 .Page }}" class="flex justify-between">
      <a {{ if .Page.Content }}href="{{ .Page.RelPermalink }}"{{ else }}role="button"{{ end }} class="{{ if $current }}active{{ end }}">
        {{- partial "docs/title" .Page -}}
      </a>
    </label>
  {{ else if .Page.Content }}
    <a href="{{ .Page.RelPermalink }}" class="{{ if $current }} active{{ end }}">
      {{- partial "docs/title" .Page -}}
    </a>
  {{ else if .Page.Params.bookHref }}
    <a href="{{ .Page.Params.bookHref }}" role="button" class="{{ if $current }} active{{ end }}" target="_blank" rel="noopener">
      {{- partial "docs/title" .Page -}}
    </a>
  {{ else }}
    <span>{{- partial "docs/title" .Page -}}</span>
  {{ end }}
{{ end }}