navbar.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. {{ $sections := site.Data.sections }}
  23. {{ if (index site.Data site.Language.Lang).sections }}
  24. {{ $sections = (index site.Data site.Language.Lang).sections }}
  25. {{ end }}
  26. <nav class="navbar navbar-expand-xl top-navbar initial-navbar" id="top-navbar">
  27. <div class="container">
  28. <a class="navbar-brand" href="{{ site.BaseURL | relLangURL }}">
  29. <img src="{{ $invertedLogo }}" id="logo">
  30. {{- site.Title -}}
  31. </a>
  32. <button
  33. class="navbar-toggler navbar-dark"
  34. id="navbar-toggler"
  35. type="button"
  36. data-toggle="collapse"
  37. data-target="#top-nav-items"
  38. >
  39. <span class="navbar-toggler-icon"></span>
  40. </button>
  41. <div class="collapse navbar-collapse" id="top-nav-items">
  42. <ul class="navbar-nav ml-auto">
  43. <li class="nav-item">
  44. <a class="nav-link" href="#home">{{ i18n "home" }}</a>
  45. </li>
  46. {{ if $sections }}
  47. {{ range sort $sections "section.weight" }}
  48. {{ if and (.section.enable) (.section.showOnNavbar)}}
  49. {{ $sectionID := replace (lower .section.name) " " "-" }}
  50. {{ if .section.id }}
  51. {{ $sectionID = .section.id }}
  52. {{ end }}
  53. <li class="nav-item">
  54. <a class="nav-link" href="#{{ $sectionID }}">{{ .section.name }}</a>
  55. </li>
  56. {{ end }}
  57. {{- end }}
  58. {{- end }}
  59. {{ $hasCustomMenus:= false }}
  60. {{ if and site.Params.customMenus }}
  61. {{ if gt (len site.Params.customMenus) 0 }}
  62. {{ $hasCustomMenus = true }}
  63. {{ end }}
  64. {{ end }}
  65. {{ if (or site.Params.enableBlogPost $hasCustomMenus) }}
  66. <div class="dropdown-divider" id="top-navbar-divider"></div>
  67. {{ end }}
  68. {{ if site.Params.enableBlogPost }}
  69. <li class="nav-item">
  70. <a class="nav-link" id="blog-link" href="{{ "/posts" | relLangURL }}">{{ i18n "posts" }}</a>
  71. </li>
  72. {{ end }}
  73. {{ range (index site.Data site.Language.Lang).site.customMenus }}
  74. <li class="nav-item">
  75. <a class="nav-link" href="{{ .url }}">{{ .name }}</a>
  76. </li>
  77. {{ end }}
  78. {{ if .IsTranslated }}
  79. {{ partial "navigators/lang-selector.html" . }}
  80. {{ end }}
  81. </ul>
  82. </div>
  83. </div>
  84. <!-- Store the logo information in a hidden img for the JS -->
  85. <img src="{{ $mainLogo }}" class="d-none" id="main-logo">
  86. <img src="{{ $invertedLogo }}" class="d-none" id="inverted-logo">
  87. </nav>