navbar.html 5.8 KB

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