navbar.html 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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">
  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. {{ range sort $sections "section.weight" }}
  52. {{ if and (.section.enable) (.section.showOnNavbar)}}
  53. {{ $sectionID := replace (lower .section.name) " " "-" }}
  54. {{ if .section.id }}
  55. {{ $sectionID = .section.id }}
  56. {{ end }}
  57. <li class="nav-item">
  58. <a class="nav-link" href="#{{ $sectionID }}">{{ .section.name }}</a>
  59. </li>
  60. {{ end }}
  61. {{- end }}
  62. {{- end }}
  63. {{ $hasCustomMenus:= false }}
  64. {{ if $customMenus }}
  65. {{ if gt (len $customMenus) 0 }}
  66. {{ $hasCustomMenus = true }}
  67. {{ end }}
  68. {{ end }}
  69. {{ if (or site.Params.enableBlogPost $hasCustomMenus) }}
  70. <div class="dropdown-divider" id="top-navbar-divider"></div>
  71. {{ end }}
  72. {{ if site.Params.enableBlogPost }}
  73. <li class="nav-item">
  74. <a class="nav-link" id="blog-link" href="{{ "/posts" | relLangURL }}">{{ i18n "posts" }}</a>
  75. </li>
  76. {{ end }}
  77. {{ range $customMenus }}
  78. <li class="nav-item">
  79. <a class="nav-link" href="{{ .url }}">{{ .name }}</a>
  80. </li>
  81. {{ end }}
  82. {{ if .IsTranslated }}
  83. {{ partial "navigators/lang-selector.html" . }}
  84. {{ end }}
  85. </ul>
  86. </div>
  87. </div>
  88. <!-- Store the logo information in a hidden img for the JS -->
  89. <img src="{{ $mainLogo }}" class="d-none" id="main-logo">
  90. <img src="{{ $invertedLogo }}" class="d-none" id="inverted-logo">
  91. </nav>