diff options
| author | Eltrac <hi@guhub.cn> | 2026-01-27 10:53:16 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2026-01-27 10:53:16 +0800 |
| commit | 60f9a4dd78fd78ebe7a66386e394cbf74184dadc (patch) | |
| tree | c9942b03b42a0f441fec2c16bd15baf679af3747 | |
| parent | 2751717aa2373b5efa9d4f3ff23203eafe295767 (diff) | |
feat: make nav configurable
| -rw-r--r-- | hugo.toml | 5 | ||||
| -rw-r--r-- | layouts/_partials/header.html | 2 | ||||
| -rw-r--r-- | layouts/_partials/menu.html | 54 |
3 files changed, 11 insertions, 50 deletions
@@ -3,3 +3,8 @@ languageCode = 'zh-cn' title = 'Jar' mainSections = ['notes'] + +[params] + [[params.nav]] + name = '瓶口' + link = '/' diff --git a/layouts/_partials/header.html b/layouts/_partials/header.html index f88077f..b3d9f1d 100644 --- a/layouts/_partials/header.html +++ b/layouts/_partials/header.html @@ -1,5 +1,5 @@ <div class="text-center font-mono"> <img src="/favicon.png" class="dark:invert" style="width: 200px"> <h1 class="text-base">{{ site.Title }}.png</h1> - {{ partial "menu.html" (dict "menuID" "main" "page" .) }} + {{ partial "menu.html" . }} </div> diff --git a/layouts/_partials/menu.html b/layouts/_partials/menu.html index ab36f0c..7e9fccd 100644 --- a/layouts/_partials/menu.html +++ b/layouts/_partials/menu.html @@ -1,51 +1,7 @@ -{{- /* -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> +<nav> <ul class="list-none m-0 p-0"> - {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }} + {{ range .Site.Params.nav }} + <li><a href="{{ .link }}">{{ .name }}</a></li> + {{ end }} </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 class="list-none"> - <a - {{- range $k, $v := $attrs }} - {{- with $v }} - {{- printf " %s=%q" $k $v | safeHTMLAttr }} - {{- end }} - {{- end -}} - >{{ $name }}</a> - {{- with .Children }} - <ul> - {{- partial "inline/menu/walk.html" (dict "page" $page "menuEntries" .) }} - </ul> - {{- end }} - </li> - {{- end }} -{{- end }} +</nav> |
