single-menu.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. {{ $lastUrlElement := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  24. <li>
  25. <a href="{{ .Permalink }}" class="menu__title {{ if and (in $currentURL $lastUrlElement) (eq $sectionName1 $sectionName2) }}active{{ end }}">{{ .Title }}</a>
  26. </li>
  27. {{ end }}
  28. </ul>
  29. {{ else }}
  30. {{ $lastUrlElement := index (last 1 (split (delimit (split .Permalink "/") "," "") ",")) 0 }}
  31. <li class="{{ if in $currentURL $lastUrlElement }}active{{ end }}">
  32. <a href="{{ .Permalink }}" class="menu__title {{ if in $currentURL $lastUrlElement }}active{{ end }}">{{ .Title }}</a>
  33. </li>
  34. {{ end }}
  35. {{ end }}
  36. </ul>
  37. </div>