docs_sidebar.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {{ $current_page := . }}
  2. {{/* Dynamically load menu for this docs page. */}}
  3. {{/* Attempt to get menu name from `menu_name` param, Hugo's front matter menu config, or the last dir of filepath. */}}
  4. {{ $menu_name := "" }}
  5. {{ if .Params.menu | and (not (reflect.IsMap .Params.menu)) | and (not (reflect.IsSlice .Params.menu)) }}
  6. {{ $menu_name = .Params.menu }}
  7. {{ else if .Params.menu | and (or (reflect.IsMap .Params.menu) (reflect.IsSlice .Params.menu)) }}
  8. {{ range $k, $v := .Params.menu }}
  9. {{ $menu_name = $k }}
  10. {{ end }}
  11. {{ end }}
  12. {{ $menu_name = .Params.menu_name | default $menu_name | default (path.Base (path.Split .File).Dir) }}
  13. {{ if not (index site.Menus $menu_name) }}
  14. {{ errorf "Please define menu items named `menu: %s:` in your %s front matter or define `[[menu.%s]]` in `config/default/menus.toml`. See https://wowchemy.com/docs/managing-content/#menus" $menu_name .Path $menu_name }}
  15. {{ end }}
  16. <form class="docs-search d-flex align-items-center">
  17. <button class="btn docs-toggle d-md-none p-0 mr-3" type="button" data-toggle="collapse" data-target="#docs-nav" aria-controls="docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
  18. <span><i class="fas fa-bars"></i></span>
  19. </button>
  20. {{ if eq site.Params.search.engine 1 }}
  21. <input name="q" type="search" class="form-control" placeholder="{{ i18n "search_placeholder" }}" autocomplete="off">
  22. {{ end }}
  23. </form>
  24. <nav class="collapse docs-links" id="docs-nav">
  25. {{ with (index site.Menus $menu_name) }}
  26. {{/* Enable Updates layout to order by descending version name. */}}
  27. {{ $menu := (index site.Menus $menu_name) }}
  28. {{ if eq ($.Scratch.Get "docs_menu_sort" | default "weight") "name_reverse" }}
  29. {{ $menu = sort $menu "Title" "desc" }}
  30. {{ else }}
  31. {{ $menu = $menu.ByWeight }}
  32. {{end}}
  33. {{ range $menu }}
  34. <div class="docs-toc-item{{ if $current_page.IsMenuCurrent $menu_name . }} active{{ end }}">
  35. <a class="docs-toc-link" {{ if .URL }}href="{{ .URL }}"{{else if .HasChildren }}href="{{ (index .Children 0).URL }}"{{end}}>{{ .Name }}</a>
  36. {{- if .HasChildren }}
  37. <ul class="nav docs-sidenav">
  38. {{ range .Children }}
  39. <li {{ if $current_page.IsMenuCurrent $menu_name . }}class="active"{{ end }}>
  40. <a href="{{ .URL }}">{{ .Name }}</a>
  41. </li>
  42. {{ end }}
  43. </ul>
  44. {{ end }}
  45. </div>
  46. {{ end }}
  47. {{ end }}
  48. </nav>