Add default menu

master
Will Faught 12 months ago
parent 457e74db4f
commit 7fef003163

@ -346,7 +346,7 @@ link = "https://youtu.be/dQw4w9WgXcQ" # The reference for an anchor around the t
### Menu
An optional menu can be configured.
The menu can be configured using the `main` menu.
The active menu item has a URL that is a prefix of the path of the current page.
A menu item with the URL `/` only matches a `/` path.

@ -6,7 +6,7 @@
{{ $first := templates.Exists "partials/paige/site-header-first.html" }}
{{ $last := templates.Exists "partials/paige/site-header-last.html" }}
{{ $links := false }}
{{ $menu := site.Menus.main | and ($page.Param "paige.site.disable_menu" | not) }}
{{ $menu := $page.Param "paige.site.disable_menu" | not }}
{{ $pills := false }}
{{ $tabs := false }}
{{ $title := $page.Param "paige.title" | default site.Title | markdownify | and ($page.Param "paige.site.disable_title" | not) }}
@ -46,7 +46,8 @@
<div class="lead paige-row-wide text-center" id="paige-site-description">{{ . }}</div>
{{ end }}
{{ with $menu }}
{{ if $menu }}
{{ with site.Menus.main }}
<nav aria-label="{{ i18n `paige_menu` }}" class="paige-row-wide" id="paige-menu">
<ul class="align-items-center justify-content-center nav {{ if $pills }} nav-pills {{ else if $tabs }} nav-tabs {{ else if $underline }} nav-underline {{ end }}">
{{ range . }}
@ -84,6 +85,33 @@
{{ end }}
</ul>
</nav>
{{ else }}
{{ $ordered := slice site.Home | append site.Sections }}
{{ range $name, $taxonomy := site.Taxonomies }}
{{ if and $taxonomy.Page $taxonomy.Page.RelPermalink }}
{{ $ordered = $ordered | append $taxonomy.Page }}
{{ end }}
{{ end }}
{{ $ordered = sort $ordered "Title" }}
<nav aria-label="{{ i18n `paige_menu` }}" class="paige-row-wide" id="paige-menu">
<ul class="align-items-center justify-content-center nav {{ if $pills }} nav-pills {{ else if $tabs }} nav-tabs {{ else if $underline }} nav-underline {{ end }}">
{{ range $ordered }}
{{ $menupath := strings.TrimPrefix $basepath .RelPermalink }}
{{ $home := and (eq $menupath "/") (eq $pagepath "/") }}
{{ $menuprefix := and (ne $menupath "/") (hasPrefix $pagepath $menupath) }}
{{ $sectionprefix := and (ne $menupath "/") (hasPrefix $menupath (printf "/%s/" $page.Section)) }}
{{ $active := or $home $menuprefix $sectionprefix }}
<li class="nav-item">
<a {{ if $active }} aria-current="page" {{ end }} class="{{ if $active }} active {{ if $links }} fw-bold text-body-emphasis {{ end }} {{ end }} nav-link {{ if $links }} text-decoration-underline {{ end }}" href="{{ .RelPermalink | safeURL }}" {{ with partial "paige/target.html" (dict "page" $page "url" .RelPermalink) }} target="{{ . }}" {{ end }}>{{ .Title }}</a>
</li>
{{ end }}
</ul>
</nav>
{{ end }}
{{ end }}
{{ with $breadcrumbs }}

Loading…
Cancel
Save