book_sidebar.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <form class="docs-search d-flex align-items-center">
  2. <button class="btn docs-toggle d-md-none p-0 mr-md-3 w-100" type="button" data-toggle="collapse" data-target="#docs-nav" aria-controls="docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
  3. <div class="d-flex">
  4. <span class="d-md-none pl-1 flex-grow-1 text-left overflow-hidden">
  5. {{ if .Parent | and .Parent.IsHome }}
  6. {{ .LinkTitle | emojify }}
  7. {{ else if .Parent | and (not .Parent.IsHome) }}
  8. {{ .Parent.LinkTitle | emojify }}
  9. {{ else }}
  10. {{ (i18n "home" | default "Home") | emojify }}
  11. {{ end }}
  12. </span>
  13. <span><i class="fas fa-chevron-down"></i></span>
  14. </div>
  15. </button>
  16. {{ if in (slice "wowchemy" "algolia") (lower site.Params.features.search.provider) }}
  17. <button class="form-control sidebar-search js-search d-none d-md-flex">
  18. <i class="fas fa-search pr-2"></i>
  19. <span class="sidebar-search-text">{{ i18n "search_placeholder" }}</span>
  20. <span class="sidebar-search-shortcut">/</span>
  21. </button>
  22. {{ end }}
  23. </form>
  24. <nav class="collapse docs-links" id="docs-nav">
  25. {{ $current_node := . }}
  26. {{ $menu_name := "" }}
  27. {{ $order_by := site.Params.books.order_by | default "weight" }}
  28. {{ $query := "" }}
  29. {{ $root_page := .GetPage "/_index.md" }}
  30. {{ $is_root := false}}
  31. {{/* Case where homepage is a book */}}
  32. {{ if $root_page | and (eq $root_page.Type "book") }}
  33. {{ $is_root = true}}
  34. <ul class="nav docs-sidenav">
  35. <li class="{{ if .IsHome }}active{{ end }}"><a href="{{ $root_page.RelPermalink }}">{{$root_page.Title}}</a></li>
  36. </ul>
  37. {{- if eq $order_by "title" -}}
  38. {{- $query = .Site.Home.Sections.ByTitle -}}
  39. {{- else if eq $order_by "title_desc" -}}
  40. {{- $query = .Site.Home.Sections.ByTitle.Reverse -}}
  41. {{- else -}}
  42. {{- $query = .Site.Home.Sections.ByWeight -}}
  43. {{- end}}
  44. {{else}}
  45. {{/* Case where homepage is NOT a book */}}
  46. {{ if eq .FirstSection.Type "book" }}
  47. {{/* Case where first section is a book. */}}
  48. {{ $menu_name = (path.Base (path.Split .FirstSection).Dir) }}
  49. {{- if eq $order_by "title" -}}
  50. {{- $query = where .Site.Home.Sections.ByTitle "Section" $menu_name -}}
  51. {{- else if eq $order_by "title_desc" -}}
  52. {{- $query = where .Site.Home.Sections.ByTitle.Reverse "Section" $menu_name -}}
  53. {{- else -}}
  54. {{- $query = where .Site.Home.Sections.ByWeight "Section" $menu_name -}}
  55. {{- end -}}
  56. {{- range $query -}}
  57. {{ template "book-menu" dict "sect" . "current_node" $current_node "order_by" $order_by "is_root" $is_root }}
  58. {{- end -}}
  59. {{ else }}
  60. {{/* Case where first section is a general page (e.g. book of books). */}}
  61. <ul class="nav docs-sidenav">
  62. <li><a href="{{.FirstSection.RelPermalink}}"><i class="fas fa-arrow-left pr-1"></i>{{.FirstSection.LinkTitle | emojify}}</a></li>
  63. </ul>
  64. {{ $first_node := $current_node }}
  65. {{ if ne .Parent .FirstSection }}
  66. {{ if ne .Parent.Parent .FirstSection }}
  67. {{ $first_node = $current_node.Parent.Parent }}
  68. {{else}}
  69. {{ $first_node = $current_node.Parent }}
  70. {{end}}
  71. {{end}}
  72. {{- if eq $order_by "title" -}}
  73. {{- $query = $first_node.Pages.ByTitle -}}
  74. {{- else if eq $order_by "title_desc" -}}
  75. {{- $query = $first_node.Pages.ByTitle.Reverse -}}
  76. {{- else -}}
  77. {{- $query = $first_node.Pages.ByWeight -}}
  78. {{- end -}}
  79. {{ template "book-menu" dict "sect" $first_node "current_node" $current_node "order_by" $order_by "is_root" $is_root }}
  80. {{end}}
  81. {{end}}
  82. </nav>