menu-filetree.html 1.8 KB

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