navbar.html 4.9 KB

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