Build menus from .Site.Menus.main if it exists, otherwise build it automatically with home and sections as before.
This commit is contained in:
parent
6b0f3caf6c
commit
27d3d64e50
2 changed files with 28 additions and 6 deletions
|
|
@ -1,15 +1,26 @@
|
|||
{{ $currentSection := .Section -}}
|
||||
{{ $currentID := "" -}}
|
||||
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
|
||||
<nav class="main-menu layout__navigation">
|
||||
<h2 class="visually-hidden">{{ i18n "menu_title" }}</h2>
|
||||
<ul class="navbar">
|
||||
{{ if .Site.Menus.main -}}
|
||||
|
||||
{{ $currentPage := . -}}
|
||||
{{ range .Site.Menus.main -}}
|
||||
<li><a href="{{ .URL }}"{{ if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} class="active" aria-current="page"{{ end }}>{{ .Name }}</a></li>
|
||||
{{ end -}}
|
||||
|
||||
{{ else -}}
|
||||
|
||||
{{ $currentSection := .Section -}}
|
||||
{{ $currentID := "" -}}
|
||||
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
|
||||
{{ with .Site.Home }}<li><a href="{{ .RelPermalink }}"{{ if eq $currentID .File.UniqueID }} class="active" aria-current="page"{{ end }}>{{ i18n "menu_home" }}</a></li>{{ end }}
|
||||
{{ range where .Site.RegularPages "Section" "" -}}
|
||||
<li><a href="{{ .RelPermalink }}"{{ if eq $currentID .File.UniqueID }} class="active" aria-current="page"{{ end }}>{{ .Title }}</a></li>
|
||||
{{ end -}}
|
||||
{{ range .Site.Sections -}}
|
||||
<li><a href="{{ .RelPermalink }}"{{ if eq $currentSection .Section }} class="active" aria-current="page"{{ end }}>{{ .Title }}</a></li>
|
||||
{{ end -}}
|
||||
|
||||
{{ end -}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
{{ $currentSection := .Section -}}
|
||||
{{ $currentID := "" -}}
|
||||
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
|
||||
<div class="mobile-nav" dir="ltr">
|
||||
<div class="mobile-nav__cover"></div>
|
||||
<a href="#navigation" class="mobile-nav__toggle" aria-haspopup="true" role="button">{{ i18n "menu_mobile" }}</a>
|
||||
|
|
@ -12,12 +9,26 @@
|
|||
<nav class="mobile-nav__main-menu">
|
||||
<h2 class="visually-hidden">{{ i18n "menu_title" }}</h2>
|
||||
<ul class="mobile-nav__navbar">
|
||||
{{ if .Site.Menus.main -}}
|
||||
|
||||
{{ $currentPage := . -}}
|
||||
{{ range .Site.Menus.main -}}
|
||||
<li><a href="{{ .URL }}"{{ if or ($currentPage.IsMenuCurrent "main" .) ($currentPage.HasMenuCurrent "main" .) }} class="active" aria-current="page"{{ end }}>{{ .Name }}</a></li>
|
||||
{{ end -}}
|
||||
|
||||
{{ else -}}
|
||||
|
||||
{{ $currentSection := .Section -}}
|
||||
{{ $currentID := "" -}}
|
||||
{{ with .File }}{{ $currentID = .UniqueID }}{{ end -}}
|
||||
{{ with .Site.Home }}<li><a href="{{ .RelPermalink }}"{{ if eq $currentID .File.UniqueID }} class="active" aria-current="page"{{ end }}>{{ i18n "menu_home" }}</a></li>{{ end }}
|
||||
{{ range where .Site.RegularPages "Section" "" -}}
|
||||
<li><a href="{{ .RelPermalink }}"{{ if eq $currentID .File.UniqueID }} class="active" aria-current="page"{{ end }}>{{ .Title }}</a></li>
|
||||
{{ end -}}
|
||||
{{ range .Site.Sections -}}
|
||||
<li><a href="{{ .RelPermalink }}"{{ if eq $currentSection .Section }} class="active" aria-current="page"{{ end }}>{{ .Title }}</a></li>
|
||||
{{ end -}}
|
||||
|
||||
{{ end -}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
|
|
|||
Loading…
Reference in a new issue