navbar.html 4.7 KB

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