book_sidebar.html 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <form class="docs-search d-flex align-items-center">
  2. <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">
  3. <span><i class="fas fa-bars"></i></span>
  4. </button>
  5. {{ if eq site.Params.search.engine 1 }}
  6. <input name="q" type="search" class="form-control" placeholder="{{ i18n "search_placeholder" }}" autocomplete="off">
  7. {{ end }}
  8. </form>
  9. <nav class="collapse docs-links" id="docs-nav">
  10. {{ $current_node := . }}
  11. {{ $menu_name := "" }}
  12. {{ $order_by := site.Params.books.order_by | default "weight" }}
  13. {{ $query := "" }}
  14. {{ $root_page := .GetPage "/_index.md" }}
  15. {{ $is_root := false}}
  16. {{/* Case where homepage is a book */}}
  17. {{ if $root_page | and (eq $root_page.Type "book") }}
  18. {{ $is_root = true}}
  19. <ul class="nav docs-sidenav">
  20. <li class="{{ if .IsHome }}active{{ end }}"><a href="{{ $root_page.RelPermalink }}">{{$root_page.Title}}</a></li>
  21. </ul>
  22. {{- if eq $order_by "title" -}}
  23. {{- $query = .Site.Home.Sections.ByTitle -}}
  24. {{- else if eq $order_by "title_desc" -}}
  25. {{- $query = .Site.Home.Sections.ByTitle.Reverse -}}
  26. {{- else -}}
  27. {{- $query = .Site.Home.Sections.ByWeight -}}
  28. {{- end}}
  29. {{else}}
  30. {{/* Case where homepage is NOT a book */}}
  31. {{ if eq .FirstSection.Type "book" }}
  32. {{/* Case where first section is a book. */}}
  33. {{ $menu_name = (path.Base (path.Split .FirstSection).Dir) }}
  34. {{/* For any folder named `updates`, use descending title order (e.g. latest release note first). */}}
  35. {{ $order_by = cond (eq $menu_name "updates") "title_desc" $order_by }}
  36. {{- if eq $order_by "title" -}}
  37. {{- $query = where .Site.Home.Sections.ByTitle "Section" $menu_name -}}
  38. {{- else if eq $order_by "title_desc" -}}
  39. {{- $query = where .Site.Home.Sections.ByTitle.Reverse "Section" $menu_name -}}
  40. {{- else -}}
  41. {{- $query = where .Site.Home.Sections.ByWeight "Section" $menu_name -}}
  42. {{- end -}}
  43. {{- range $query -}}
  44. {{ template "book-menu" dict "sect" . "current_node" $current_node "order_by" $order_by "is_root" $is_root }}
  45. {{- end -}}
  46. {{ else }}
  47. {{/* Case where first section is a general page (e.g. book of books). */}}
  48. {{ $first_node := $current_node }}
  49. {{ if ne .Parent .FirstSection }}
  50. {{ if ne .Parent.Parent .FirstSection }}
  51. {{ $first_node = $current_node.Parent.Parent }}
  52. {{else}}
  53. {{ $first_node = $current_node.Parent }}
  54. {{end}}
  55. {{end}}
  56. {{- if eq $order_by "title" -}}
  57. {{- $query = $first_node.Pages.ByTitle -}}
  58. {{- else if eq $order_by "title_desc" -}}
  59. {{- $query = $first_node.Pages.ByTitle.Reverse -}}
  60. {{- else -}}
  61. {{- $query = $first_node.Pages.ByWeight -}}
  62. {{- end -}}
  63. {{ template "book-menu" dict "sect" $first_node "current_node" $current_node "order_by" $order_by "is_root" $is_root }}
  64. {{end}}
  65. {{end}}
  66. </nav>