navbar.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. >
  43. <span class="navbar-toggler-icon"></span>
  44. </button>
  45. <div class="collapse navbar-collapse" id="top-nav-items">
  46. <ul class="navbar-nav ml-auto">
  47. <li class="nav-item">
  48. <a class="nav-link" href="#home">{{ i18n "home" }}</a>
  49. </li>
  50. {{ if $sections }}
  51. {{ $sectionCount := 0}}
  52. {{ range sort $sections "section.weight" }}
  53. {{ if and (.section.enable) (.section.showOnNavbar)}}
  54. {{ $sectionCount = add $sectionCount 1}}
  55. {{ if le $sectionCount 5 }}
  56. <li class="nav-item">
  57. <a class="nav-link" href="#{{ partial "helpers/get-section-id.html" . }}">{{ .section.name }}</a>
  58. </li>
  59. {{ end }}
  60. {{ end }}
  61. {{- end }}
  62. {{ if gt $sectionCount 5 }}
  63. <li class="nav-item dropdown">
  64. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{i18n "more" }}</a>
  65. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  66. {{ $sectionCount := 0 }}
  67. {{ range sort $sections "section.weight" }}
  68. {{ if and (.section.enable) (.section.showOnNavbar) }}
  69. {{ $sectionCount = add $sectionCount 1}}
  70. {{ if gt $sectionCount 5 }}
  71. <a class="dropdown-item" href="#{{ partial "helpers/get-section-id.html" . }}">{{ .section.name }}</a>
  72. {{ end }}
  73. {{ end }}
  74. {{- end }}
  75. </div>
  76. </li>
  77. {{ end }}
  78. {{- end }}
  79. {{ $hasCustomMenus:= false }}
  80. {{ if $customMenus }}
  81. {{ if gt (len $customMenus) 0 }}
  82. {{ $hasCustomMenus = true }}
  83. {{ end }}
  84. {{ end }}
  85. {{ if (or site.Params.enableBlogPost $hasCustomMenus) }}
  86. <div class="dropdown-divider" id="top-navbar-divider"></div>
  87. {{ end }}
  88. {{ if site.Params.enableBlogPost }}
  89. <li class="nav-item">
  90. <a class="nav-link" id="blog-link" href="{{ "/posts" | relLangURL }}">{{ i18n "posts" }}</a>
  91. </li>
  92. {{ end }}
  93. {{ range $customMenus }}
  94. <li class="nav-item">
  95. <a class="nav-link" href="{{ .url }}">{{ .name }}</a>
  96. </li>
  97. {{ end }}
  98. {{ if .IsTranslated }}
  99. {{ partial "navigators/lang-selector.html" . }}
  100. {{ end }}
  101. </ul>
  102. </div>
  103. </div>
  104. <!-- Store the logo information in a hidden img for the JS -->
  105. <img src="{{ $mainLogo }}" class="d-none" id="main-logo" alt="Logo">
  106. <img src="{{ $invertedLogo }}" class="d-none" id="inverted-logo" alt="Inverted Logo">
  107. </nav>