navbar.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {{ $show_navbar := site.Params.main_menu.enable | default true }}
  2. {{ if $show_navbar }}
  3. {{ $current_page := . }}
  4. {{ $highlight_active_link := site.Params.main_menu.highlight_active_link | default true }}
  5. {{ $show_current_language := site.Params.main_menu.show_language | default false }}
  6. {{/* Get site logo. */}}
  7. {{ $show_logo := site.Params.main_menu.show_logo | default true }}
  8. {{ $has_logo := fileExists "assets/media/logo.png" | or (fileExists "assets/media/logo.svg") }}
  9. {{ $logo := "" }}
  10. {{ if $has_logo }}
  11. {{ $logo = (partial "functions/get_logo" (dict "constraint" "max_height" "size" 70)) }}
  12. {{ end }}
  13. <nav class="navbar navbar-expand-lg navbar-light compensate-for-scrollbar" id="navbar-main">
  14. <div class="container-xl">
  15. {{if $show_logo}}
  16. <div class="d-none d-lg-inline-flex">
  17. <a class="navbar-brand" href="{{ "/" | relLangURL }}">
  18. {{- if $has_logo -}}
  19. <img src="{{ $logo.RelPermalink }}" alt="{{ site.Title }}">
  20. {{- else -}}
  21. {{- site.Title -}}
  22. {{- end -}}
  23. </a>
  24. </div>
  25. {{end}}
  26. {{ if site.Menus.main }}
  27. <button type="button" class="navbar-toggler" data-toggle="collapse"
  28. data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="{{ i18n "toggle_navigation" }}">
  29. <span><i class="fas fa-bars"></i></span>
  30. </button>
  31. {{ end }}
  32. {{if $show_logo}}
  33. <div class="navbar-brand-mobile-wrapper d-inline-flex d-lg-none">
  34. <a class="navbar-brand" href="{{ "/" | relLangURL }}">
  35. {{- if $has_logo -}}
  36. <img src="{{ $logo.RelPermalink }}" alt="{{ site.Title }}">
  37. {{- else -}}
  38. {{- site.Title -}}
  39. {{- end -}}
  40. </a>
  41. </div>
  42. {{end}}
  43. <!-- Collect the nav links, forms, and other content for toggling -->
  44. {{ $align_menu := site.Params.main_menu.align | default "l" }}
  45. <div class="navbar-collapse main-menu-item collapse {{ if eq $align_menu "c" }}justify-content-center{{ else if eq $align_menu "r" }}justify-content-end{{else}}justify-content-start{{ end }}" id="navbar-content">
  46. <!-- Left Nav Bar -->
  47. <ul class="navbar-nav d-md-inline-flex">
  48. {{ range site.Menus.main }}
  49. {{ if .HasChildren }}
  50. <li class="nav-item dropdown">
  51. <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true">
  52. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  53. <span class="caret"></span>
  54. </a>
  55. <div class="dropdown-menu">
  56. {{ range .Children }}
  57. <a class="dropdown-item" href="{{ .URL | relLangURL }}"{{ if $.IsHome }} data-target="{{ .URL }}"{{ end }}>
  58. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  59. </a>
  60. {{ end }}
  61. </div>
  62. </li>
  63. {{ else }}
  64. {{/* Set target for link. */}}
  65. {{ $.Scratch.Set "target" "" }}
  66. {{ if gt (len .URL) 4 }}
  67. {{ if eq "http" (slicestr .URL 0 4) }}
  68. {{ $.Scratch.Set "target" " target=\"_blank\" rel=\"noopener\"" }}
  69. {{ end }}
  70. {{ end }}
  71. {{/* Get active page. */}}
  72. {{ $is_link_in_current_path := false }}
  73. {{ $is_widget_page := or $current_page.IsHome (eq $current_page.Type "widget_page") }}
  74. {{ $is_same_page := false }}
  75. {{ $hash := findRE "#(.+)" .URL }}
  76. {{ if $current_page.IsHome | and (or (eq .URL "/") (eq .URL "")) }}
  77. {{ $is_link_in_current_path = true }}
  78. {{else}}
  79. {{ if gt (len .URL) 1 }}{{/* Ignore root URL */}}
  80. {{ $is_link_in_current_path = in $current_page.RelPermalink .URL }}
  81. {{ $is_same_page = $is_link_in_current_path }}
  82. {{end}}
  83. {{ if gt (len $hash) 0 }}
  84. {{ $hash = index $hash 0 }}
  85. {{ $hash_removed := replace .URL $hash "" }}
  86. {{ if eq (len $hash_removed) 0 }}
  87. {{ $hash_removed = "/" }}{{/* Add robustness for `/#SECTION` or `#SECTION` in `menus.toml`. */}}
  88. {{ end }}
  89. {{ $is_same_page = eq (path.Dir $current_page.RelPermalink) (path.Dir ($hash_removed|relLangURL)) }}
  90. {{ end }}
  91. {{end}}
  92. <li class="nav-item">
  93. <a class="nav-link {{if and $highlight_active_link $is_link_in_current_path }} active{{end}}" href="{{.URL | relLangURL}}"{{ if and $is_widget_page $is_same_page }} data-target="{{$hash}}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
  94. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  95. </a>
  96. </li>
  97. {{ end }}
  98. {{ end }}
  99. {{ if site.Menus.main_right | and (eq $align_menu "l") }}
  100. </ul>
  101. <ul class="navbar-nav ml-md-auto">
  102. {{ end }}
  103. {{ range site.Menus.main_right }}
  104. {{/* Set target for link. */}}
  105. {{ $.Scratch.Set "target" "" }}
  106. {{ if gt (len .URL) 4 }}
  107. {{ if eq "http" (slicestr .URL 0 4) }}
  108. {{ $.Scratch.Set "target" " target=\"_blank\" rel=\"noopener\"" }}
  109. {{ end }}
  110. {{ end }}
  111. <li class="nav-item">
  112. <a class="nav-link" href="{{ .URL | relLangURL }}"{{ if $.IsHome }} data-target="{{ .URL }}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
  113. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  114. </a>
  115. </li>
  116. {{ end }}
  117. </ul>
  118. </div><!-- /.navbar-collapse -->
  119. <ul class="nav-icons navbar-nav flex-row ml-auto d-flex pl-md-2">
  120. {{/* Display any social links that the superuser chose to display in the header. */}}
  121. {{ range where (where (where site.Pages "Section" "authors") ".Params.superuser" true) ".Params.social" "!=" nil }}
  122. {{ range where .Params.social ".display.header" true }}
  123. {{ $social_link := partial "functions/get_social_link" . }}
  124. <li class="nav-item d-none d-lg-inline-flex">
  125. <a class="nav-link" href="{{ $social_link.link | safeURL }}"{{ with $social_link.tooltip }} data-toggle="tooltip" data-placement="bottom" title="{{.}}"{{ end }} {{ $social_link.target | safeHTMLAttr }} aria-label="{{ $social_link.aria_label }}">
  126. <i class="{{ $social_link.icon_pack }} {{ $social_link.pack_prefix }}-{{ $social_link.icon }}" aria-hidden="true"></i>
  127. </a>
  128. </li>
  129. {{ end }}
  130. {{ end }}
  131. {{ $show_search := site.Params.main_menu.show_search | default true }}
  132. {{ if and site.Params.search.provider $show_search }}
  133. <li class="nav-item">
  134. <a class="nav-link js-search" href="#" aria-label="{{ i18n "search" }}"><i class="fas fa-search" aria-hidden="true"></i></a>
  135. </li>
  136. {{ end }}
  137. {{ $show_day_night := site.Params.main_menu.show_day_night | default true }}
  138. {{ if and site.Params.day_night $show_day_night }}
  139. <li class="nav-item dropdown theme-dropdown">
  140. <a href="#" class="nav-link" data-toggle="dropdown" aria-haspopup="true" aria-label="{{ i18n "theme_selector" | default "Display preferences" }}">
  141. <i class="fas fa-moon" aria-hidden="true"></i>
  142. </a>
  143. <div class="dropdown-menu">
  144. <a href="#" class="dropdown-item js-set-theme-light">
  145. <span>{{ i18n "theme_light" | default "Light" }}</span>
  146. </a>
  147. <a href="#" class="dropdown-item js-set-theme-dark">
  148. <span>{{ i18n "theme_dark" | default "Dark" }}</span>
  149. </a>
  150. <a href="#" class="dropdown-item js-set-theme-auto">
  151. <span>{{ i18n "theme_auto" | default "Automatic" }}</span>
  152. </a>
  153. </div>
  154. </li>
  155. {{ end }}
  156. {{ $show_translations := site.Params.main_menu.show_translations | default true }}
  157. {{ if .IsTranslated | and $show_translations }}
  158. <li class="nav-item dropdown i18n-dropdown">
  159. <a href="#" class="nav-link {{ if $show_current_language }}dropdown-toggle{{end}}" data-toggle="dropdown"
  160. aria-haspopup="true" aria-label="{{ i18n "languages" | default "Languages" }}">
  161. <i class="fas fa-globe mr-1" aria-hidden="true"></i>
  162. {{- if $show_current_language -}}
  163. <span class="d-none d-lg-inline">{{ index site.Data.i18n.languages .Lang }}</span>
  164. {{- end -}}
  165. </a>
  166. <div class="dropdown-menu">
  167. <div class="dropdown-item dropdown-item-active">
  168. <span>{{ index site.Data.i18n.languages .Lang }}</span>
  169. </div>
  170. {{ range .Translations }}
  171. <a class="dropdown-item" href="{{ .Permalink }}"{{ if $.IsHome }} data-target="{{ .RelPermalink }}"{{ end }}>
  172. <span>{{ index site.Data.i18n.languages .Lang }}</span>
  173. </a>
  174. {{ end }}
  175. </div>
  176. </li>
  177. {{ end }}
  178. </ul>
  179. </div><!-- /.container -->
  180. </nav>
  181. {{end}}{{/* End show navbar. */}}