single-menu.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <div class="menu">
  2. <h6 class="menu__label">
  3. {{ if .IsHome }}
  4. {{ .Site.Title }}
  5. {{ else }}
  6. {{ .Type }}
  7. {{ end }}
  8. </h6>
  9. <ul>
  10. {{ $currentURL := .Permalink }}
  11. {{ range (.Site.GetPage "section" .Type).Pages }}
  12. {{ $sectionName1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  13. {{ $sectionName2 := index (last 2 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  14. {{ if .Params.Collapsible }}
  15. <span class="menu__title--collapse {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}active{{ end }}">
  16. {{ .Title }}
  17. <span class="menu__title--icon {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}down{{ else }}right{{ end }}">
  18. {{ partial "svgs/arrow-right.svg" (dict "width" 22 "height" 22) }}
  19. </span>
  20. </span>
  21. <ul class="menu__list {{ if and (in $currentURL .Permalink) (eq $sectionName1 $sectionName2) }}active{{ end }}">
  22. {{ range .Pages.ByWeight }}
  23. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  24. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  25. <li>
  26. <a href="{{ .Permalink }}" class="menu__title {{ if and (eq $lastUrlElement1 $lastUrlElement2) (eq $sectionName1 $sectionName2) }}active{{ end }}">{{ .Title }}</a>
  27. </li>
  28. {{ end }}
  29. </ul>
  30. {{ else }}
  31. {{ $lastUrlElement1 := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  32. {{ $lastUrlElement2 := index (last 1 (split (delimit (split $currentURL "/") "," "") ",")) 0 }}
  33. <li>
  34. <a href="{{ .Permalink }}" class="menu__title {{ if in $lastUrlElement1 $lastUrlElement2 }}active{{ end }}">{{ .Title }}</a>
  35. </li>
  36. {{ end }}
  37. {{ end }}
  38. </ul>
  39. </div>