navbar.html 6.0 KB

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