header: improve menu location indicator

- fix non-highlight on subdirs
- menu url need not have leading or trailing slashes
- fix non-highlight with multilingual config
This commit is contained in:
Aditya Telange 2020-12-01 13:58:16 +05:30
parent dc743ae5e2
commit 7a0e742def
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77

View File

@ -109,12 +109,11 @@
{{- $currentPage := . }}
<ul class="menu" id="menu" onscroll="menu_on_scroll()">
{{- range .Site.Menus.main }}
{{- $menu_item_url := .URL | relLangURL }}
{{- $page_url:= $currentPage.RelPermalink | relLangURL }}
{{- $menu_item_url := (cond (strings.HasSuffix .URL "/") .URL (printf "%s/" .URL) ) | absLangURL }}
{{- $page_url:= $currentPage.Permalink | absLangURL }}
<li>
<a href="{{ .URL | absLangURL }}">
<span {{- if eq $menu_item_url $page_url }}
{{- /* the menu item links to the current page (with relLangURL) */}} class="active" {{- end }}>
<a href="{{ $menu_item_url }}">
<span {{- if eq $menu_item_url $page_url }} class="active" {{- end }}>
{{ .Name }}
</span>
</a>