Make menus:

1. Not repeat the current page language
2. point to the same page in the other languages rather than to the web site's root
This commit is contained in:
Rui Miguel Silva Seabra 2022-12-02 02:02:40 +00:00
parent 007d7f3df6
commit 45ed0606ad
2 changed files with 25 additions and 4 deletions

View File

@ -1,9 +1,20 @@
{{ $currentpage := .Page }}
<ul class="menu menu--desktop menu--language-selector">
<li class="menu__trigger">{{ .Language.LanguageName }}&nbsp;</li>
<li>
<ul class="menu__dropdown">
{{ range $.Site.Home.AllTranslations }}
<li><a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a></li>
{{ if ne .Lang $currentpage.Language.Lang }}
{{ if eq .Lang $.Site.Params.DefaultContentLanguage }}
<li><a href="{{ strings.Substr $currentpage.RelPermalink 3 }}">{{ .Language.LanguageName }}</a></li>
{{ else }}
{{ if eq $currentpage.Language.Lang $.Site.Params.DefaultContentLanguage }}
<li><a href="/{{ .Lang }}{{ $currentpage.RelPermalink }}">{{ .Language.LanguageName }}</a></li>
{{ else }}
<li><a href="/{{ .Lang }}{{ substr $currentpage.RelPermalink 3 }}">{{ .Language.LanguageName }}</a></li>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</ul>
</li>

View File

@ -1,3 +1,4 @@
{{ $currentpage := .Page }}
<ul class="menu menu--mobile">
<li class="menu__trigger">Menu&nbsp;</li>
<li>
@ -10,10 +11,19 @@
{{ if and $.Site.Params.showLanguageSelector (len $.Site.Home.AllTranslations) }}
<hr />
{{ range $.Site.Home.AllTranslations }}
<li>
<a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a>
</li>
{{ if ne .Lang $currentpage.Language.Lang }}
{{ if eq .Lang $.Site.Params.DefaultContentLanguage }}
<li><a href="{{ strings.Substr $currentpage.RelPermalink 3 }}">{{ .Language.LanguageName }}</a></li>
{{ else }}
{{ if eq $currentpage.Language.Lang $.Site.Params.DefaultContentLanguage }}
<li><a href="/{{ .Lang }}{{ $currentpage.RelPermalink }}">{{ .Language.LanguageName }}</a></li>
{{ else }}
<li><a href="/{{ .Lang }}{{ substr $currentpage.RelPermalink 3 }}">{{ .Language.LanguageName }}</a></li>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</ul>
</li>