navbar.html 5.3 KB

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