navbar.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. {{/* variables for enabling/disabling various features */}}
  2. {{ $blogEnabled := site.Params.features.blog.enable | default false }}
  3. {{ $blogTitle := site.Params.features.blog.title | default (i18n "posts") }}
  4. {{ $notesEnabled := site.Params.features.notes.enable | default false }}
  5. {{ $notesTitle := site.Params.features.notes.title | default (i18n "notes") }}
  6. {{ $maxVisibleSections := site.Params.topNavbar.maxVisibleSections | default 5 }}
  7. {{/* keep backward compatibility for blog post */}}
  8. {{ if site.Params.enableBlogPost }}
  9. {{ $blogEnabled = true }}
  10. {{ end }}
  11. {{/* by default, don't use any logo */}}
  12. {{ $mainLogo := "" }}
  13. {{ $invertedLogo := "" }}
  14. {{ $darkLogo := "" }}
  15. {{/* if custom logo has been provided, use them */}}
  16. {{ if site.Params.logo.main }}
  17. {{ $mainLogo = site.Params.logo.main }}
  18. {{ end }}
  19. {{ if site.Params.logo.inverted }}
  20. {{ $invertedLogo = site.Params.logo.inverted }}
  21. {{ end }}
  22. {{ if site.Params.logo.dark }}
  23. {{ $darkLogo = site.Params.logo.dark }}
  24. {{ end }}
  25. {{/* resize the logos. don't resize svg because it is not supported */}}
  26. {{ if $mainLogo }}
  27. {{ $mainLogo = resources.Get $mainLogo}}
  28. {{ if and $mainLogo (not (or (eq $mainLogo.MediaType.SubType "svg") (eq $mainLogo.MediaType.SubType "gif"))) }}
  29. {{ $mainLogo = $mainLogo.Resize "42x" }}
  30. {{ end }}
  31. {{ $mainLogo = $mainLogo.RelPermalink}}
  32. {{ end }}
  33. {{ if $invertedLogo }}
  34. {{ $invertedLogo = resources.Get $invertedLogo}}
  35. {{ if and $invertedLogo (not (or (eq $invertedLogo.MediaType.SubType "svg") (eq $invertedLogo.MediaType.SubType "gif"))) }}
  36. {{ $invertedLogo = $invertedLogo.Resize "42x" }}
  37. {{ end }}
  38. {{ $invertedLogo = $invertedLogo.RelPermalink}}
  39. {{ end }}
  40. {{ if $darkLogo }}
  41. {{ $darkLogo = resources.Get $darkLogo}}
  42. {{ if and $darkLogo (not (or (eq $darkLogo.MediaType.SubType "svg") (eq $darkLogo.MediaType.SubType "gif"))) }}
  43. {{ $darkLogo = $darkLogo.Resize "42x" }}
  44. {{ end }}
  45. {{ $darkLogo = $darkLogo.RelPermalink}}
  46. {{ end }}
  47. {{ $logo := $mainLogo }}
  48. {{ if .IsHome }}
  49. {{ $logo = $invertedLogo }}
  50. {{ end }}
  51. {{ $customMenus := site.Params.customMenus }}
  52. {{ if (index site.Data site.Language.Lang).site.customMenus }}
  53. {{ $customMenus = (index site.Data site.Language.Lang).site.customMenus }}
  54. {{ end }}
  55. {{ $sections := site.Data.sections }}
  56. {{ if (index site.Data site.Language.Lang).sections }}
  57. {{ $sections = (index site.Data site.Language.Lang).sections }}
  58. {{ end }}
  59. {{ $navBarTitle := (index site.Data site.Language.Lang).site.navBarTitle }}
  60. {{ if not $navBarTitle }}
  61. {{ $navBarTitle = site.Title }}
  62. {{ end }}
  63. <nav class="navbar navbar-expand-xl top-navbar shadow {{ if .IsHome}}transparent-navbar homepage{{end}}" id="top-navbar">
  64. <div class="container">
  65. {{ if not .IsHome }}
  66. <button class="navbar-toggler navbar-light" id="sidebar-toggler" type="button">
  67. <i data-feather="sidebar"></i>
  68. </button>
  69. {{ end }}
  70. <a class="navbar-brand" href="{{ site.BaseURL | relLangURL }}">
  71. {{ if $logo }}
  72. <img src="{{ $logo }}" id="logo" alt="Logo">
  73. {{ end }}
  74. {{- $navBarTitle -}}
  75. </a>
  76. <button
  77. class="navbar-toggler {{if .IsHome}}navbar-dark{{else}}navbar-light{{end}}"
  78. id="navbar-toggler"
  79. type="button"
  80. data-bs-toggle="collapse"
  81. data-bs-target="#top-nav-items"
  82. aria-label="menu"
  83. >
  84. <i data-feather="menu"></i>
  85. </button>
  86. <div class="collapse navbar-collapse dynamic-navbar" id="top-nav-items">
  87. <ul class="nav navbar-nav ms-auto">
  88. <li class="nav-item">
  89. <a class="nav-link" href="{{ if .IsHome }}#home{{else}}{{ site.BaseURL | relLangURL }}#home{{end}}">{{ i18n "home" }}</a>
  90. </li>
  91. {{ if $sections }}
  92. {{ $sectionCount := 1 }}
  93. {{ range sort $sections "section.weight" }}
  94. {{ if and (.section.enable) (.section.showOnNavbar)}}
  95. {{ $sectionCount = add $sectionCount 1}}
  96. {{ if le $sectionCount $maxVisibleSections }}
  97. <li class="nav-item">
  98. <a class="nav-link" href="{{ partial "helpers/get-section-url.html" . }}">{{ .section.name }}</a>
  99. </li>
  100. {{ end }}
  101. {{ end }}
  102. {{- end }}
  103. {{ if gt $sectionCount $maxVisibleSections }}
  104. <li class="nav-item dropdown">
  105. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{i18n "more" }}</a>
  106. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  107. {{ $sectionCount := 1 }}
  108. {{ range sort $sections "section.weight" }}
  109. {{ if and (.section.enable) (.section.showOnNavbar) }}
  110. {{ $sectionCount = add $sectionCount 1}}
  111. {{ if gt $sectionCount $maxVisibleSections }}
  112. <a class="dropdown-item" href="{{ partial "helpers/get-section-url.html" . }}">{{ .section.name }}</a>
  113. {{ end }}
  114. {{ end }}
  115. {{- end }}
  116. </div>
  117. </li>
  118. {{ end }}
  119. {{- end }}
  120. {{ $shouldAddSeparator:= partial "helpers/add-navbar-separator.html" . }}
  121. {{ if $shouldAddSeparator }}
  122. <div id="top-navbar-divider"></div>
  123. {{ end }}
  124. {{ if $blogEnabled }}
  125. <li class="nav-item">
  126. <a class="nav-link" id="blog-link" href="{{ path.Join (site.BaseURL | relLangURL) "posts" }}">{{ $blogTitle }}</a>
  127. </li>
  128. {{ end }}
  129. {{ if $notesEnabled }}
  130. <li class="nav-item">
  131. <a class="nav-link" id="note-link" href="{{ path.Join (site.BaseURL | relLangURL) "notes" }}">{{ $notesTitle }}</a>
  132. </li>
  133. {{ end }}
  134. {{ range $customMenus }}
  135. {{ if (not .hideFromNavbar) }}
  136. <li class="nav-item">
  137. <a class="nav-link" href="{{ .url }}">{{ .name }}</a>
  138. </li>
  139. {{ end }}
  140. {{ end }}
  141. {{ if .IsTranslated }}
  142. {{ partial "navigators/lang-selector.html" . }}
  143. {{ end }}
  144. {{ if or site.Params.features.darkMode.enable site.Params.features.theme.enable }}
  145. {{ partial "navigators/theme-selector.html" . }}
  146. {{ end }}
  147. </ul>
  148. </div>
  149. </div>
  150. <!-- Store the logo information in a hidden img for the JS -->
  151. {{ if $mainLogo }}
  152. <img src="{{ $mainLogo }}" class="d-none" id="main-logo" alt="Logo">
  153. {{ end }}
  154. {{ if $invertedLogo }}
  155. <img src="{{ $invertedLogo }}" class="d-none" id="inverted-logo" alt="Inverted Logo">
  156. {{ end }}
  157. {{ if $darkLogo }}
  158. <img src="{{ $darkLogo }}" class="d-none" id="dark-logo" alt="Dark Logo">
  159. {{ end }}
  160. </nav>