single-menu.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. <span class="menu__title--collapse {{ if $active }}active{{ end }}" data-depth="{{ $depth }}">
  28. {{ $ctx.Title }}
  29. <span class="menu__title--icon {{ if $active }}{{ if eq ($root.Param "languagedir") "rtl" }}downrtl{{ else }}down{{ end }}{{ else }}right{{ end }}">
  30. {{ if eq ($root.Param "languagedir") "rtl" }}
  31. {{ partial "svgs/arrow-left.svg" (dict "width" 22 "height" 22) }}
  32. {{ else }}
  33. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  34. {{ end }}
  35. </span>
  36. </span>
  37. <ul class="menu__list {{ if $active }}active{{ else if (in $ctx.Permalink (print "/" $sectionName1 "/")) }}{{ end }}" data-data={{ print "/" $sectionName1 "/"}} data-link={{ .root.Permalink }}>
  38. {{ range $ctx.Pages.ByWeight }}
  39. {{ if .Params.Collapsible }}
  40. {{ template "render-menu" (dict "ctx" . "root" $root "depth" (add $depth 1)) }}
  41. {{ else }}
  42. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  43. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  44. <li>
  45. <a href="{{ .Permalink }}" class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}" data-depth="{{ $depth }}">{{ .Title }}</a>
  46. </li>
  47. {{ end }}
  48. {{ end }}
  49. </ul>
  50. {{ else }}
  51. {{ $lastUrlElement1 := index (last 1 (split (delimit (split $ctx.Permalink "/") "," "") ",")) 0 }}
  52. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  53. <li class="{{ if $active }}active{{ end }}">
  54. <a href="{{ $ctx.Permalink }}"
  55. class="menu__title {{ if $active }}active{{ end }}">{{ $ctx.Title }}</a>
  56. </li>
  57. {{ end }}
  58. {{ end }}