58 lines
1.8 KiB
HTML
58 lines
1.8 KiB
HTML
{{- /*
|
|
Renders a menu for the given menu ID.
|
|
|
|
@context {page} page The current page.
|
|
@context {string} menuID The menu ID.
|
|
|
|
@example: {{ partial "menu.html" (dict "menuID" "main" "page" .) }}
|
|
*/}}
|
|
|
|
{{- $page := .page }}
|
|
{{- $menuID := .menuID }}
|
|
|
|
{{- with index site.Menus $menuID }}
|
|
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="#">Here be logo</a>
|
|
<button
|
|
class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
|
data-bs-target="#navbarCollapse" aria-controls="navbarCollapse"
|
|
aria-expanded="false" aria-label="Toggle navigation"
|
|
>
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarCollapse">
|
|
<ul class="navbar-nav- me-auto mb-2 mb-md-0">
|
|
{{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
{{- end }}
|
|
|
|
{{- define "partials/inline/menu/walk.html" }}
|
|
{{- $page := .page }}
|
|
{{- range .menuEntries }}
|
|
{{- $attrs := dict "href" .URL }}
|
|
{{- if $page.IsMenuCurrent .Menu . }}
|
|
{{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
|
|
{{- else if $page.HasMenuCurrent .Menu .}}
|
|
{{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
|
|
{{- end }}
|
|
<li class="nav-item">
|
|
<a class="nav-link" aria-current="page"
|
|
{{- range $k, $v := $attrs }}
|
|
{{- with $v }}
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
|
{{- end }}
|
|
{{- end -}}
|
|
>{{ or (T .Identifier) .Name | safeHTML }}</a>
|
|
{{- with .Children }}
|
|
<ul>
|
|
{{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
|
|
</ul>
|
|
{{- end }}
|
|
</li>
|
|
{{- end }}
|
|
{{- end }}
|