menu-bundle.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {{ $current := .current }}
  2. {{ template "menu-file" dict "sect" .source "current" $current "site" $current.Site }}
  3. <!-- template -->
  4. {{ define "menu-file" }}
  5. {{ $current := .current }}
  6. {{ $site := .site }}
  7. <ul class="gdoc-nav__list">
  8. {{ range sort (default (seq 0) .sect) "weight" }}
  9. {{ $name := .name }}
  10. {{ if reflect.IsMap .name }}
  11. {{ $name = (index .name $site.Language.Lang) }}
  12. {{ end }}
  13. <li>
  14. {{ $ref := default false .ref }}
  15. {{ if $ref }}
  16. {{ $this := $site.GetPage .ref }}
  17. {{ $icon := default false .icon }}
  18. {{ $numberOfPages := (add (len $this.Pages) (len $this.Sections)) }}
  19. {{ $isCurrent := eq $current $this }}
  20. {{ $isAncestor := $this.IsAncestor $current }}
  21. {{ $id := substr (sha1 $this.Permalink) 0 8 }}
  22. {{ $doCollapse := and (isset . "sub") (or $this.Params.geekdocCollapseSection (default false .Site.Params.geekdocCollapseAllSections)) }}
  23. {{ $anchor := default "" .anchor }}
  24. {{ if $anchor }}
  25. {{ $anchor = printf "#%s" $anchor }}
  26. {{ end }}
  27. {{ if or .external ($this.RelPermalink) }}
  28. <input
  29. type="checkbox"
  30. {{ if $doCollapse }}
  31. class="gdoc-nav__toggle" id="{{ printf "navtree-%s" $id }}"
  32. {{ if or $isCurrent $isAncestor }}checked{{ end }}
  33. {{ else }}
  34. class="hidden"
  35. {{ end }}
  36. />
  37. <label
  38. {{ if $doCollapse }}
  39. for="{{ printf "navtree-%s" $id }}" class="flex justify-between align-center"
  40. {{ end }}
  41. >
  42. <span class="flex">
  43. {{ if $icon }}
  44. <svg class="gdoc-icon {{ .icon }}"><use xlink:href="#{{ .icon }}"></use></svg>
  45. {{ end }}
  46. <a
  47. href="{{ if .external -}}
  48. {{ .ref }}
  49. {{- else -}}
  50. {{ path.Join $this.RelPermalink $anchor }}
  51. {{- end }}"
  52. class="gdoc-nav__entry{{- if not .external }}
  53. {{- if $isCurrent }}{{ printf " is-active" }}{{ end }}
  54. {{- end }}"
  55. >
  56. {{ $name }}
  57. </a>
  58. </span>
  59. {{ if $doCollapse }}
  60. <svg class="gdoc-icon toggle gdoc_keyboard_arrow_left">
  61. <use xlink:href="#gdoc_keyboard_arrow_left"></use>
  62. </svg>
  63. <svg class="gdoc-icon toggle gdoc_keyboard_arrow_down">
  64. <use xlink:href="#gdoc_keyboard_arrow_down"></use>
  65. </svg>
  66. {{ end }}
  67. </label>
  68. {{ end }}
  69. {{ else }}
  70. <span class="flex">{{ $name }}</span>
  71. {{ end }}
  72. {{ with .sub }}
  73. {{ template "menu-file" dict "sect" . "current" $current "site" $site }}
  74. {{ end }}
  75. </li>
  76. {{ end }}
  77. </ul>
  78. {{ end }}