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
1 changed files with 4 additions and 5 deletions

View File

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