layouts/: Use absLangURL to determine active page in menu

On sites with multiple languages we need to use the absolute URL in
the test to determine if the current page should be marked "active"
in the menu bar. Perhaps a bug with Hugo that relative links end up
like "/bg/bg/about" instead of "/bg/about".
This commit is contained in:
Alan Orth 2017-04-04 12:03:07 +03:00
parent 09d089f214
commit 77671af35d
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
1 changed files with 5 additions and 5 deletions

View File

@ -35,16 +35,16 @@
<div class="container">
<nav class="nav blog-nav">
<a class="nav-link {{ if .IsHome }}active{{ end }}" href="{{ .Site.BaseURL | absLangURL }}">{{ i18n "home" }}</a>
{{ $currentRelURL := .URL | relLangURL }}
{{ $currentURL := .URL | absLangURL }}
{{ if .Site.Params.custom_navbar }}
{{ range .Site.Menus.navbar }}
{{ $menuRelURL := .URL | relLangURL }}
<a class="nav-link {{ if eq $menuRelURL $currentRelURL }}active{{ end }}" href="{{.URL | absURL }}">{{ .Name }}</a>
{{ $menuURL := .URL | absLangURL }}
<a class="nav-link {{ if eq $menuURL $currentURL }}active{{ end }}" href="{{.URL | absURL }}">{{ .Name }}</a>
{{ end }}
{{ else }}
{{ range where .Site.RegularPages "Type" "!=" "post" }}
{{ $permalinkRelURL := .Permalink | relLangURL }}
<a class="nav-link {{ if eq $permalinkRelURL $currentRelURL }}active{{ end }}" href="{{ .Permalink }}">{{ .Title }}</a>
{{ $permalinkURL := .Permalink | absLangURL }}
<a class="nav-link {{ if eq $permalinkURL $currentURL }}active{{ end }}" href="{{ .Permalink }}">{{ .Title }}</a>
{{ end }}
{{ end }}
</nav>