navbar.html 9.5 KB

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