summaryrefslogtreecommitdiff
path: root/layouts/_partials/navmenu.html
diff options
context:
space:
mode:
authorArne Rief <riearn@proton.me>2026-01-09 12:24:05 +0100
committerArne Rief <riearn@proton.me>2026-01-09 12:24:05 +0100
commitf8541ef965ca22e746b523eb418e47cb4f78f2d8 (patch)
tree49e1540ed42595a44196817eadf97337587a2aea /layouts/_partials/navmenu.html
parent038054b8206a9c25e84adeb0f0f355abd22d6143 (diff)
Upgrade to new template system from Hugo v0.146.0
Diffstat (limited to 'layouts/_partials/navmenu.html')
-rw-r--r--layouts/_partials/navmenu.html48
1 files changed, 48 insertions, 0 deletions
diff --git a/layouts/_partials/navmenu.html b/layouts/_partials/navmenu.html
new file mode 100644
index 0000000..af0fc2e
--- /dev/null
+++ b/layouts/_partials/navmenu.html
@@ -0,0 +1,48 @@
+{{- /*
+Simplified version of the `hugo new template` menu.html default. Renders a menu for the given menu ID.
+
+@context {page} page: The current page.
+@context {string} menuID: The menu ID.
+
+@example: {{ partial "navmenu.html" (dict "menuID" "main" "page" .) }}
+*/}}
+
+{{- $currentPage := .page }}
+{{- $menuID := .menuID }}
+
+{{- with index site.Menus $menuID }}
+<nav role="navigation" aria-label="{{ lang.Translate "navmenu" | default "Site navigation" }}" class="header__navigation">
+ <ul class="header__navigation-list">
+ {{- range . }}
+ {{- $isCurrentPage := $currentPage.IsMenuCurrent .Menu . }}
+ {{- $isAncestorPage := $currentPage.HasMenuCurrent .Menu . }}
+ {{- $isActive := or $isCurrentPage $isAncestorPage }}
+ {{- $menuItemName := .Name }}
+
+ {{- $attrs := dict "href" .URL }}
+ {{- if $currentPage.IsMenuCurrent .Menu . }}
+ {{- $attrs = merge $attrs (dict "class" "active" "aria-current" "page") }}
+ {{- else if $currentPage.HasMenuCurrent .Menu .}}
+ {{- $attrs = merge $attrs (dict "class" "ancestor" "aria-current" "true") }}
+ {{- end }}
+
+ <!-- Translations -->
+ {{- with .Identifier }}
+ {{- with lang.Translate . }}
+ {{- $menuItemName = . }}
+ {{- end }}
+ {{- end }}
+
+ <li class="header__navigation--list-item">
+ <a
+ href="{{ .URL }}"
+ class="header__navigation-link{{ if $isActive }} header__navigation-link--active{{ end }}"
+ aria-current="{{ if $isCurrentPage }}page{{ else if $isAncestorPage }}true{{ end }}"
+ >
+ {{ $menuItemName }}
+ </a>
+ </li>
+ {{- end }}
+ </ul>
+</nav>
+{{- end -}}