navbar.html 4.4 KB

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