Files
hugo-book/layouts/_partials/docs/menu-hugo.html
Levente Polyak 4018d4b51d Menu: Allow to explicitly override if a menu url is remote or not (#809)
* Menu: Allow to explicitly override if a menu url is remote or not

This can be very useful if a hugo website f.e. on GitHub pages is
constructed from different individual spec repos but still represent
one coherent site.

* Rename param to bookNewTab

---------

Co-authored-by: Alex Shpak <alex-shpak@users.noreply.github.com>
2026-05-10 23:33:57 +02:00

46 lines
1.2 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 := default (urls.Parse .URL).IsAbs .Params.bookNewTab -}}
<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" }}
{{- with .Params.BookIcon -}}
<img src="{{ partial "docs/icon" . }}" class="book-icon" alt="{{ partial "docs/text/i18n" . }}" />
{{- end -}}
{{- if .Name -}}
{{- .Name -}}
{{- else if .Page -}}
{{- partial "docs/title" .Page -}}
{{- end -}}
{{ end }}