single-menu.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <div class="menu">
  2. <h6 class="menu__label">
  3. {{ if .IsHome }}
  4. {{ .Site.Title }}
  5. {{ else }}
  6. {{ $.Param "Title" }}
  7. {{ end }}
  8. </h6>
  9. <ul>
  10. {{ $root := . }}
  11. {{ range (.Site.GetPage "section" .Type).Pages }}
  12. {{ template "render-menu" (dict "ctx" . "root" $root "depth" 0)}}
  13. {{ end }}
  14. </ul>
  15. </div>
  16. {{ define "render-menu" }}
  17. {{ $root := .root }}
  18. {{ $ctx := .ctx }}
  19. {{ $depth := .depth }}
  20. {{ $currentURL := $root.Permalink }}
  21. {{ $sectionName1 := index (last 1 (split (delimit (split $ctx.Permalink "/") "," "") ",")) 0 }}
  22. {{ $sectionName2 := index (last 2 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  23. {{ $active := in $currentURL $ctx.Permalink }}
  24. {{ $active = or $active (eq $sectionName1 $sectionName2) }}
  25. {{ $active = or $active (in $currentURL $sectionName1) }}
  26. {{ if $ctx.Params.Collapsible }}
  27. <li class="menu__title--collapse {{ if $active }}active{{ end }}" data-depth="{{ $depth }}" data-permalink="{{ $ctx.Permalink }}">
  28. <span class="menu__title--collapse-text">
  29. {{ $ctx.Title }}
  30. </span>
  31. <span class="menu__title--icon {{ if $active }}{{ if eq ($root.Param "languagedir") "rtl" }}downrtl{{ else }}down{{ end }}{{ else }}right{{ end }}">
  32. {{ if eq ($root.Param "languagedir") "rtl" }}
  33. {{ partial "svgs/arrow-left.svg" (dict "width" 22 "height" 22) }}
  34. {{ else }}
  35. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  36. {{ end }}
  37. </span>
  38. </li>
  39. <ul class="menu__list {{ if $active }}active{{ else if (in $ctx.Permalink (print "/" $sectionName1 "/")) }}{{ end }}" data-data={{ print "/" $sectionName1 "/"}} data-link={{ .root.Permalink }}>
  40. {{ range $ctx.Pages.ByWeight }}
  41. {{ if .Params.Collapsible }}
  42. {{ template "render-menu" (dict "ctx" . "root" $root "depth" (add $depth 1)) }}
  43. {{ else }}
  44. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  45. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  46. <li>
  47. <a href="{{ .Permalink }}" class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}" data-depth="{{ $depth }}">{{ .Title }}</a>
  48. </li>
  49. {{ end }}
  50. {{ end }}
  51. </ul>
  52. {{ else }}
  53. {{ $lastUrlElement1 := index (last 1 (split (delimit (split $ctx.Permalink "/") "," "") ",")) 0 }}
  54. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  55. <li class="{{ if $active }}active{{ end }}">
  56. <a href="{{ $ctx.Permalink }}"
  57. class="menu__title {{ if $active }}active{{ end }}">{{ $ctx.Title }}</a>
  58. </li>
  59. {{ end }}
  60. {{ end }}