navbar.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. <nav class="navbar navbar-expand-xl top-navbar shadow {{ if .IsHome}}transparent-navbar homepage{{end}}" id="top-navbar">
  47. <div class="container">
  48. {{ if not .IsHome }}
  49. <button class="navbar-toggler navbar-light" id="sidebar-toggler" type="button">
  50. <i data-feather="sidebar"></i>
  51. </button>
  52. {{ end }}
  53. <a class="navbar-brand" href="{{ site.BaseURL | relLangURL }}">
  54. {{ if $logo }}
  55. <img src="{{ $logo }}" id="logo" alt="Logo">
  56. {{ end }}
  57. {{- site.Title -}}
  58. </a>
  59. <button
  60. class="navbar-toggler {{if .IsHome}}navbar-dark{{else}}navbar-light{{end}}"
  61. id="navbar-toggler"
  62. type="button"
  63. data-toggle="collapse"
  64. data-target="#top-nav-items"
  65. aria-label="menu"
  66. >
  67. <i data-feather="menu"></i>
  68. </button>
  69. <div class="collapse navbar-collapse dynamic-navbar" id="top-nav-items">
  70. <ul class="nav navbar-nav ml-auto">
  71. <li class="nav-item">
  72. <a class="nav-link" href="{{ if .IsHome }}#home{{else}}{{ site.BaseURL | relLangURL }}#home{{end}}">{{ i18n "home" }}</a>
  73. </li>
  74. {{ if $sections }}
  75. {{ $sectionCount := 1 }}
  76. {{ range sort $sections "section.weight" }}
  77. {{ if and (.section.enable) (.section.showOnNavbar)}}
  78. {{ $sectionCount = add $sectionCount 1}}
  79. {{ if le $sectionCount $maxVisibleSections }}
  80. <li class="nav-item">
  81. <a class="nav-link" href="{{ partial "helpers/get-section-url.html" . }}">{{ .section.name }}</a>
  82. </li>
  83. {{ end }}
  84. {{ end }}
  85. {{- end }}
  86. {{ if gt $sectionCount $maxVisibleSections }}
  87. <li class="nav-item dropdown">
  88. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{i18n "more" }}</a>
  89. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  90. {{ $sectionCount := 1 }}
  91. {{ range sort $sections "section.weight" }}
  92. {{ if and (.section.enable) (.section.showOnNavbar) }}
  93. {{ $sectionCount = add $sectionCount 1}}
  94. {{ if gt $sectionCount $maxVisibleSections }}
  95. <a class="dropdown-item" href="{{ partial "helpers/get-section-url.html" . }}">{{ .section.name }}</a>
  96. {{ end }}
  97. {{ end }}
  98. {{- end }}
  99. </div>
  100. </li>
  101. {{ end }}
  102. {{- end }}
  103. {{ $shouldAddSeparator:= partial "helpers/add-navbar-separator.html" . }}
  104. {{ if $shouldAddSeparator }}
  105. <div id="top-navbar-divider"></div>
  106. {{ end }}
  107. {{ if $blogEnabled }}
  108. <li class="nav-item">
  109. <a class="nav-link" id="blog-link" href="{{ path.Join (site.BaseURL | relLangURL) "posts" }}">{{ i18n "posts" }}</a>
  110. </li>
  111. {{ end }}
  112. {{ if $notesEnabled }}
  113. <li class="nav-item">
  114. <a class="nav-link" id="note-link" href="{{ path.Join (site.BaseURL | relLangURL) "notes" }}">{{ i18n "notes" }}</a>
  115. </li>
  116. {{ end }}
  117. {{ range $customMenus }}
  118. {{ if (not .hideFromNavbar) }}
  119. <li class="nav-item">
  120. <a class="nav-link" href="{{ .url }}">{{ .name }}</a>
  121. </li>
  122. {{ end }}
  123. {{ end }}
  124. {{ if .IsTranslated }}
  125. {{ partial "navigators/lang-selector.html" . }}
  126. {{ end }}
  127. {{ if site.Params.features.darkMode.enable }}
  128. {{ partial "navigators/theme-selector.html" . }}
  129. {{ end }}
  130. </ul>
  131. </div>
  132. </div>
  133. <!-- Store the logo information in a hidden img for the JS -->
  134. {{ if $mainLogo }}
  135. <img src="{{ $mainLogo }}" class="d-none" id="main-logo" alt="Logo">
  136. {{ end }}
  137. {{ if $invertedLogo }}
  138. <img src="{{ $invertedLogo }}" class="d-none" id="inverted-logo" alt="Inverted Logo">
  139. {{ end }}
  140. </nav>