navbar.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. {{ $current_page := . }}
  2. {{/* Get site logo. */}}
  3. {{ $show_logo := site.Params.main_menu.show_logo | default true }}
  4. {{ $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") }}
  5. {{ $logo := "" }}
  6. {{ if $has_logo }}
  7. {{ $logo = (partial "functions/get_logo" (dict "constraint" "max_height" "size" 70)) }}
  8. {{ end }}
  9. <nav class="navbar navbar-expand-lg navbar-light compensate-for-scrollbar" id="navbar-main">
  10. <div class="container">
  11. {{if $show_logo}}
  12. <div class="d-none d-lg-inline-flex">
  13. <a class="navbar-brand" href="{{ "/" | relLangURL }}">
  14. {{- if $has_logo -}}
  15. <img src="{{ $logo.RelPermalink }}" alt="{{ site.Title }}">
  16. {{- else -}}
  17. {{- site.Title -}}
  18. {{- end -}}
  19. </a>
  20. </div>
  21. {{end}}
  22. {{ if site.Menus.main }}
  23. <button type="button" class="navbar-toggler" data-toggle="collapse"
  24. data-target="#navbar-content" aria-controls="navbar" aria-expanded="false" aria-label="{{ i18n "toggle_navigation" }}">
  25. <span><i class="fas fa-bars"></i></span>
  26. </button>
  27. {{ end }}
  28. {{if $show_logo}}
  29. <div class="navbar-brand-mobile-wrapper d-inline-flex d-lg-none">
  30. <a class="navbar-brand" href="{{ "/" | relLangURL }}">
  31. {{- if $has_logo -}}
  32. <img src="{{ $logo.RelPermalink }}" alt="{{ site.Title }}">
  33. {{- else -}}
  34. {{- site.Title -}}
  35. {{- end -}}
  36. </a>
  37. </div>
  38. {{end}}
  39. <!-- Collect the nav links, forms, and other content for toggling -->
  40. {{ $align_menu := site.Params.main_menu.align | default "l" }}
  41. <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">
  42. <!-- Left Nav Bar -->
  43. <ul class="navbar-nav d-md-inline-flex">
  44. {{ range site.Menus.main }}
  45. {{ if .HasChildren }}
  46. <li class="nav-item dropdown">
  47. <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true">
  48. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  49. <span class="caret"></span>
  50. </a>
  51. <div class="dropdown-menu">
  52. {{ range .Children }}
  53. <a class="dropdown-item" href="{{ .URL | relLangURL }}"{{ if $.IsHome }} data-target="{{ .URL }}"{{ end }}>
  54. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  55. </a>
  56. {{ end }}
  57. </div>
  58. </li>
  59. {{ else }}
  60. {{/* Set target for link. */}}
  61. {{ $.Scratch.Set "target" "" }}
  62. {{ if gt (len .URL) 4 }}
  63. {{ if eq "http" (slicestr .URL 0 4) }}
  64. {{ $.Scratch.Set "target" " target=\"_blank\" rel=\"noopener\"" }}
  65. {{ end }}
  66. {{ end }}
  67. {{/* Get active page. */}}
  68. {{ $is_link_in_current_path := in $current_page.RelPermalink .URL }}
  69. {{ $is_widget_page := or $current_page.IsHome (eq $current_page.Type "widget_page") }}
  70. {{ $hash := findRE "#(.+)" .URL }}
  71. {{ $is_same_page := $is_link_in_current_path }}
  72. {{ if gt (len $hash) 0 }}
  73. {{ $hash = index $hash 0 }}
  74. {{ $hash_removed := replace .URL $hash "" }}
  75. {{ if eq (len $hash_removed) 0 }}
  76. {{ $hash_removed = "/" }}{{/* Add robustness for `/#SECTION` or `#SECTION` in `menus.toml`. */}}
  77. {{ end }}
  78. {{ $is_same_page = eq (path.Dir $current_page.RelPermalink) (path.Dir ($hash_removed|relLangURL)) }}
  79. {{ end }}
  80. <li class="nav-item">
  81. <a class="nav-link {{if $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 }}>
  82. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  83. </a>
  84. </li>
  85. {{ end }}
  86. {{ end }}
  87. {{ if site.Menus.main_right | and (eq $align_menu "l") }}
  88. </ul>
  89. <ul class="navbar-nav ml-md-auto">
  90. {{ end }}
  91. {{ range site.Menus.main_right }}
  92. {{/* Set target for link. */}}
  93. {{ $.Scratch.Set "target" "" }}
  94. {{ if gt (len .URL) 4 }}
  95. {{ if eq "http" (slicestr .URL 0 4) }}
  96. {{ $.Scratch.Set "target" " target=\"_blank\" rel=\"noopener\"" }}
  97. {{ end }}
  98. {{ end }}
  99. <li class="nav-item">
  100. <a class="nav-link" href="{{ .URL | relLangURL }}"{{ if $.IsHome }} data-target="{{ .URL }}"{{ end }}{{ ($.Scratch.Get "target") | safeHTMLAttr }}>
  101. {{- .Pre -}}<span>{{ .Name | safeHTML }}</span>{{- .Post -}}
  102. </a>
  103. </li>
  104. {{ end }}
  105. </ul>
  106. </div><!-- /.navbar-collapse -->
  107. <ul class="nav-icons navbar-nav flex-row ml-auto d-flex pl-md-2">
  108. {{ if site.Params.search.engine }}
  109. <li class="nav-item">
  110. <a class="nav-link js-search" href="#"><i class="fas fa-search" aria-hidden="true"></i></a>
  111. </li>
  112. {{ end }}
  113. {{ if site.Params.day_night }}
  114. <li class="nav-item dropdown theme-dropdown">
  115. <a href="#" class="nav-link js-theme-selector" data-toggle="dropdown" aria-haspopup="true">
  116. <i class="fas fa-palette" aria-hidden="true"></i>
  117. </a>
  118. <div class="dropdown-menu">
  119. <a href="#" class="dropdown-item js-set-theme-light">
  120. <span>{{ i18n "theme_light" | default "Light" }}</span>
  121. </a>
  122. <a href="#" class="dropdown-item js-set-theme-dark">
  123. <span>{{ i18n "theme_dark" | default "Dark" }}</span>
  124. </a>
  125. <a href="#" class="dropdown-item js-set-theme-auto">
  126. <span>{{ i18n "theme_auto" | default "Automatic" }}</span>
  127. </a>
  128. </div>
  129. </li>
  130. {{ end }}
  131. {{ if .IsTranslated }}
  132. <li class="nav-item dropdown i18n-dropdown">
  133. <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true">
  134. <i class="fas fa-globe mr-1" aria-hidden="true"></i><span class="d-none d-lg-inline">{{ index site.Data.i18n.languages .Lang }}</span>
  135. </a>
  136. <div class="dropdown-menu">
  137. <div class="dropdown-item dropdown-item-active">
  138. <span>{{ index site.Data.i18n.languages .Lang }}</span>
  139. </div>
  140. {{ range .Translations }}
  141. <a class="dropdown-item" href="{{ .Permalink }}"{{ if $.IsHome }} data-target="{{ .RelPermalink }}"{{ end }}>
  142. <span>{{ index site.Data.i18n.languages .Lang }}</span>
  143. </a>
  144. {{ end }}
  145. </div>
  146. </li>
  147. {{ end }}
  148. </ul>
  149. </div><!-- /.container -->
  150. </nav>