63 lines
1.8 KiB
HTML
63 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 }}
|
||
|
{{- $menuClass := .class }}
|
||
|
|
||
|
{{- with index site.Menus $menuID }}
|
||
|
<ul class="{{ $menuClass }}">
|
||
|
{{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
|
||
|
</ul>
|
||
|
{{- end }}
|
||
|
|
||
|
{{- define "_partials/inline/menu/walk.html" }}
|
||
|
{{- $page := .page }}
|
||
|
{{- range .menuEntries }}
|
||
|
{{- $attrs := dict "href" .URL "class" "" }}
|
||
|
{{- 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 }}
|
||
|
{{- $attrs = merge $attrs (dict "class" (print $attrs.class " contrast")) }}
|
||
|
{{- if (ne .Params.class nil) }}
|
||
|
{{- $attrs = merge $attrs (dict "class" (print $attrs.class " " .Params.class)) }}
|
||
|
{{- end }}
|
||
|
{{- if (ne .Params.rel nil) }}
|
||
|
{{- $attrs = merge $attrs (dict "rel" .Params.rel) }}
|
||
|
{{- end }}
|
||
|
{{- $name := .Name }}
|
||
|
{{- with .Identifier }}
|
||
|
{{- with T . }}
|
||
|
{{- $name = . }}
|
||
|
{{- end }}
|
||
|
{{- end }}
|
||
|
<li>
|
||
|
<a
|
||
|
{{- range $k, $v := $attrs }}
|
||
|
{{- with $v }}
|
||
|
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
|
||
|
{{- end }}
|
||
|
{{- end -}}
|
||
|
>
|
||
|
{{- if (ne .Params.iconName nil) }}
|
||
|
{{partial "icon.html" (dict "icon" .Params.iconName "label" .Params.iconTitle)}}
|
||
|
{{- end }}
|
||
|
{{ $name }}
|
||
|
</a>
|
||
|
{{- with .Children }}
|
||
|
<ul>
|
||
|
{{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
|
||
|
</ul>
|
||
|
{{- end }}
|
||
|
</li>
|
||
|
{{- end }}
|
||
|
{{- end }}
|