Files
hugo-book/layouts/_partials/docs/menu-hugo.html
2025-09-21 22:29:59 +02:00

43 lines
1.1 KiB
HTML

<!--
This is template for hugo menus, accepts Page and Menu as context
https://gohugo.io/variables/menus/
-->
{{- if .Menu -}}
{{- template "book-menu-hugo" . -}}
{{- end -}}
{{ define "book-menu-hugo" }}
<ul>
{{- range .Menu -}}
{{- $class := slice -}}
{{- with .Params.class -}}
{{- $class = $class | append . -}}
{{- end -}}
{{- if $.Page.IsMenuCurrent .Menu . -}}
{{- $class = $class | append "active" -}}
{{- end -}}
<li>
{{- $isRemote := (urls.Parse .URL).IsAbs -}}
<a href="{{ .URL }}"
{{- with $class }}class="{{ delimit . " " }}"{{ end -}}
{{- with .Title }}title="{{ . }}"{{ end -}}
{{- if $isRemote }}target="_blank" rel="noopener"{{ end -}}>
{{- .Pre -}}
{{ template "book-menu-title" . }}
{{- .Post -}}
</a>
{{- with .Children }}
{{ template "book-menu-hugo" (dict "Page" $.Page "Menu" .) }}
{{- end }}
</li>
{{- end -}}
</ul>
{{ end }}
{{ define "book-menu-title" }}
{{ if .Name }}
{{ .Name }}
{{ else if .Page }}
{{ partial "docs/title" .Page }}
{{ end }}
{{ end }}