navbar.html 8.9 KB

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