Use unified navbar for all pages

Signed-off-by: hossainemruz <hossainemruz@gmail.com>
This commit is contained in:
hossainemruz 2023-09-26 03:58:32 +06:00
parent 5a9af3cc46
commit cb0ae29984
24 changed files with 243 additions and 298 deletions

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" (dict "baseURL" site.BaseURL "title" site.Title "hasToggleButton" false) }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "content" }}

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}

View file

@ -3,7 +3,7 @@
{{ end }}
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}
@ -155,9 +155,6 @@
</div>
<!--scroll back to top-->
<a id="scroll-to-top" class="btn"><i class="fas fa-chevron-circle-up"></i></a>
{{ if .IsTranslated }}
{{ partial "navigators/floating-lang-selector.html" . }}
{{ end }}
</section>
{{ end }}

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}

View file

@ -1,25 +0,0 @@
{{ $pageURL:= .RelPermalink }}
{{ if site.IsMultiLingual }}
{{ $pageURL = strings.TrimPrefix (path.Join "/" .Language.Lang) $pageURL }}
{{ end }}
<div class="dropdown languageSelector">
<a class="btn dropdown-toggle" href="#" id="languageSelector" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ if ne site.Params.features.flags.enable false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ site.Language.LanguageName }}
</a>
<div class="dropdown-menu" aria-labelledby="languageSelector">
{{ range .Translations }}
<a class="dropdown-item nav-link languages-item" href="{{ path.Join "/" (cond (eq .Language.Lang "en") "" .Language.Lang) $pageURL }}">
{{ if ne site.Params.features.flags.enable false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ .Language.LanguageName }}
</a>
{{ end }}
</div>
</div>

View file

@ -1,25 +0,0 @@
{{ $pageURL:= .RelPermalink }}
{{ if site.IsMultiLingual }}
{{ $pageURL = strings.TrimPrefix (path.Join "/" .Language.Lang) $pageURL }}
{{ end }}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="languageSelector" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ if ne site.Params.features.flags.enable false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ site.Language.LanguageName }}
</a>
<div class="dropdown-menu" aria-labelledby="languageSelector">
{{ range .Translations }}
<a class="dropdown-item nav-link languages-item" href="{{ path.Join "/" (cond (eq .Language.Lang "en") "" .Language.Lang) $pageURL }}">
{{ if ne site.Params.features.flags.enable false }}
{{ $countryCode := partial "helpers/country-code.html" . }}
<span class="flag-icon flag-icon-{{$countryCode}}"></span>
{{ end }}
{{ .Language.LanguageName }}
</a>
{{ end }}
</div>
</li>

View file

@ -1,63 +0,0 @@
{{/* by default, don't use any logo */}}
{{ $mainLogo := "" }}
{{ $invertedLogo := "" }}
{{/* if custom logo has been provided, use them */}}
{{ if site.Params.logo.main }}
{{ $mainLogo = site.Params.logo.main }}
{{ end }}
{{ if site.Params.logo.inverted }}
{{ $invertedLogo = site.Params.logo.inverted }}
{{ end }}
{{/* resize the logos. don't resize svg because it is not supported */}}
{{ if $mainLogo }}
{{ $mainLogo = resources.Get $mainLogo}}
{{ if and $mainLogo (ne $mainLogo.MediaType.SubType "svg") }}
{{ $mainLogo = $mainLogo.Resize "42x" }}
{{ end }}
{{ $mainLogo = $mainLogo.RelPermalink}}
{{ end }}
{{ if $invertedLogo }}
{{ $invertedLogo = resources.Get $invertedLogo}}
{{ if and $invertedLogo (ne $invertedLogo.MediaType.SubType "svg")}}
{{ $invertedLogo = $invertedLogo.Resize "42x" }}
{{ end }}
{{ $invertedLogo = $invertedLogo.RelPermalink}}
{{ end }}
<nav class="navbar navbar-expand-xl top-navbar final-navbar shadow">
<div class="container">
<button class="navbar-toggler navbar-light" id="sidebar-toggler" type="button">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="{{ site.BaseURL | relLangURL }}">
{{ if $mainLogo }}
<img src="{{ $mainLogo }}" alt="Logo">
{{ end }}
{{- site.Title -}}
</a>
<button class="navbar-toggler navbar-light" id="toc-toggler" type="button">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse lang-selector" id="top-nav-items">
<ul class="navbar-nav ml-auto">
{{ if .IsTranslated }}
{{ partial "navigators/lang-selector-2.html" . }}
{{ end }}
{{ if site.Params.features.darkMode.enable }}
{{ partial "navigators/theme-selector.html" . }}
{{ end }}
</ul>
</div>
</div>
<!-- Store the logo information in a hidden img for the JS -->
{{ if $mainLogo }}
<img src="{{ $mainLogo }}" class="d-none" id="main-logo" alt="Logo">
{{ end }}
{{ if $invertedLogo }}
<img src="{{ $invertedLogo }}" class="d-none" id="inverted-logo" alt="Inverted Logo">
{{ end }}
</nav>

View file

@ -37,6 +37,11 @@
{{ $invertedLogo = $invertedLogo.RelPermalink}}
{{ end }}
{{ $logo := $mainLogo }}
{{ if .IsHome }}
{{ $logo = $invertedLogo }}
{{ end }}
{{ $customMenus := site.Params.customMenus }}
{{ if (index site.Data site.Language.Lang).site.customMenus }}
{{ $customMenus = (index site.Data site.Language.Lang).site.customMenus }}
@ -47,29 +52,34 @@
{{ $sections = (index site.Data site.Language.Lang).sections }}
{{ end }}
<nav class="navbar navbar-expand-xl top-navbar initial-navbar" id="top-navbar">
<nav class="navbar navbar-expand-xl top-navbar shadow {{ if .IsHome}}transparent-navbar homepage{{end}}" id="top-navbar">
<div class="container">
{{ if not .IsHome }}
<button class="navbar-toggler navbar-light" id="sidebar-toggler" type="button">
<i data-feather="sidebar"></i>
</button>
{{ end }}
<a class="navbar-brand" href="{{ site.BaseURL | relLangURL }}">
{{ if $invertedLogo }}
<img src="{{ $invertedLogo }}" id="logo" alt="Logo">
{{ if $logo }}
<img src="{{ $logo }}" id="logo" alt="Logo">
{{ end }}
{{- site.Title -}}
</a>
<button
class="navbar-toggler navbar-dark"
class="navbar-toggler {{if .IsHome}}navbar-dark{{else}}navbar-light{{end}}"
id="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#top-nav-items"
aria-label="menu"
>
<span class="navbar-toggler-icon"></span>
<i data-feather="menu"></i>
</button>
<div class="collapse navbar-collapse dynamic-navbar" id="top-nav-items">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#home">{{ i18n "home" }}</a>
<a class="nav-link" href="{{ site.BaseURL | relLangURL }}#home">{{ i18n "home" }}</a>
</li>
{{ if $sections }}
{{ $sectionCount := 1 }}
@ -78,7 +88,7 @@
{{ $sectionCount = add $sectionCount 1}}
{{ if le $sectionCount $maxVisibleSections }}
<li class="nav-item">
<a class="nav-link" href="#{{ partial "helpers/get-section-id.html" . }}">{{ .section.name }}</a>
<a class="nav-link" href="{{ site.BaseURL | relLangURL }}#{{ partial "helpers/get-section-id.html" . }}">{{ .section.name }}</a>
</li>
{{ end }}
{{ end }}
@ -92,7 +102,7 @@
{{ if and (.section.enable) (.section.showOnNavbar) }}
{{ $sectionCount = add $sectionCount 1}}
{{ if gt $sectionCount $maxVisibleSections }}
<a class="dropdown-item" href="#{{ partial "helpers/get-section-id.html" . }}">{{ .section.name }}</a>
<a class="dropdown-item" href="{{ site.BaseURL | relLangURL }}#{{ partial "helpers/get-section-id.html" . }}">{{ .section.name }}</a>
{{ end }}
{{ end }}
{{- end }}
@ -106,12 +116,12 @@
{{ end }}
{{ if $blogEnabled }}
<li class="nav-item">
<a class="nav-link" id="blog-link" href="{{ "/posts/" | relLangURL }}">{{ i18n "posts" }}</a>
<a class="nav-link" id="blog-link" href="{{ path.Join (site.BaseURL | relLangURL) "posts" }}">{{ i18n "posts" }}</a>
</li>
{{ end }}
{{ if $notesEnabled }}
<li class="nav-item">
<a class="nav-link" id="note-link" href="{{ "/notes/" | relLangURL }}">{{ i18n "notes" }}</a>
<a class="nav-link" id="note-link" href="{{ path.Join (site.BaseURL | relLangURL) "notes" }}">{{ i18n "notes" }}</a>
</li>
{{ end }}
{{ range $customMenus }}

View file

@ -1,15 +1,15 @@
{{ range .menuItems }}
{{ $class:= "" }}
{{ $icon:= "fa-plus-circle" }}
{{ $icon:= "plus-circle" }}
<!-- If the current menu is the selected menu or it contain the selected menu, set expand icon and set "active" class -->
{{ if or ($.ctx.HasMenuCurrent $.menuName .) ($.ctx.IsMenuCurrent $.menuName .)}}
{{ $icon = "fa-minus-circle"}}
{{ $icon = "minus-circle"}}
{{ $class = "active" }}
{{end}}
{{ if .HasChildren }}
<!-- Add current entry -->
<li>
<i class="fas {{ $icon }}"></i><a class="{{$class}} list-link" href="{{ .URL }}"> {{.Name}}</a>
<i data-feather="{{ $icon }}"></i><a class="{{$class}} list-link" href="{{ .URL }}"> {{.Name}}</a>
<!-- Add sub-tree -->
<ul class="{{ $class }}">
{{ partial "navigators/sidebar.html" (dict "menuName" $.menuName "menuItems" .Children "ctx" $.ctx) }}

View file

@ -1 +1 @@
{{ partial "helpers/script-bundle.html" }}
{{ partial "helpers/script-bundle.html" }}

View file

@ -1,5 +1,5 @@
{{ define "navbar" }}
{{ partial "navigators/navbar-2.html" . }}
{{ partial "navigators/navbar.html" . }}
{{ end }}
{{ define "sidebar" }}