summaryrefslogtreecommitdiff
path: root/layouts/_partials/menu.html
diff options
context:
space:
mode:
author2026-02-10 17:11:24 +0300
committer2026-02-10 20:08:10 +0300
commit2ecb959c5b9c2b0750212af0349fd6d4a5c25258 (patch)
tree16b3268b7dd825a13d4d8c0eb00007cc7f9a8ac1 /layouts/_partials/menu.html
downloadbase-2ecb959c5b9c2b0750212af0349fd6d4a5c25258.tar.gz
base-2ecb959c5b9c2b0750212af0349fd6d4a5c25258.tar.bz2
base-2ecb959c5b9c2b0750212af0349fd6d4a5c25258.tar.xz
base-2ecb959c5b9c2b0750212af0349fd6d4a5c25258.zip
Первый коммитHEADmaster
Diffstat (limited to 'layouts/_partials/menu.html')
-rw-r--r--layouts/_partials/menu.html50
1 files changed, 50 insertions, 0 deletions
diff --git a/layouts/_partials/menu.html b/layouts/_partials/menu.html
new file mode 100644
index 0000000..ebad53f
--- /dev/null
+++ b/layouts/_partials/menu.html
@@ -0,0 +1,50 @@
+{{- /*
+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>
+ <ul>
+ {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
+ </ul>
+</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 }}
+{{- $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 .Pre}}
+ {{.Pre}}
+ {{end}}
+ {{ $name }}
+ </a>
+ {{- with .Children }}
+ <ul>
+ {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }}
+ </ul>
+ {{- end }}
+</li>
+{{- end }}
+{{- end }} \ No newline at end of file