navbar.html 8.8 KB

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