menu-filetree.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!-- Put configured sections list to .Scratch -->
  2. {{ template "book-get-root-section" . }}
  3. {{- range .Scratch.Get "BookSections" -}}
  4. {{ template "book-section" (dict "Section" . "CurrentPage" $.Permalink) }}
  5. {{- end -}}
  6. {{ define "book-section" }} <!-- Single section of menu (recursive) -->
  7. <ul {{ if .Expanded }}class="expanded"{{ end }}>
  8. {{ range (.Section.Pages.ByParam "Title").ByParam "Weight" }}
  9. {{ if and (eq .Kind "section") (or (gt (len .Pages) 0) (gt (len .Sections) 0) ) }}
  10. <li class="section">
  11. {{ $expanded := in $.CurrentPage .Permalink }}
  12. <div class="section-link">
  13. <img src="{{ "svg/clr-icon-angle.svg" | relURL }}" class="section-icon {{ if $expanded}}expanded{{ end }}" />
  14. {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
  15. </div>
  16. {{ template "book-section" (dict "Section" . "CurrentPage" $.CurrentPage "Expanded" $expanded) }}
  17. </li>
  18. {{ else }}
  19. <li>
  20. {{ template "book-page-link" (dict "Page" . "CurrentPage" $.CurrentPage) }}
  21. </li>
  22. {{ end }}
  23. {{ end }}
  24. </ul>
  25. {{ end }}
  26. {{ define "book-page-link" }}
  27. {{- with .Page -}}
  28. <a href="{{ .RelPermalink }}" {{- if eq $.CurrentPage .Permalink }} class="active"{{ end }}>
  29. {{- template "title" . -}}
  30. </a>
  31. {{- end -}}
  32. {{ end }}
  33. {{ define "book-get-root-section" }}
  34. <!-- Complex logic to guess page title without .Title specified -->
  35. {{ $bookSection := default "docs" .Site.Params.BookSection }}
  36. {{ if eq $bookSection "*" }}
  37. {{ .Scratch.Set "BookSections" .Site.Sections }}
  38. {{ else }}
  39. {{ $bookSections := where .Site.Sections "Section" $bookSection }}
  40. {{ .Scratch.Set "BookSections" $bookSections }}
  41. {{ end }}
  42. {{ end }}