diff options
Diffstat (limited to 'themes/danix-xyz-hacker/layouts/partials/header.html')
| -rw-r--r-- | themes/danix-xyz-hacker/layouts/partials/header.html | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/themes/danix-xyz-hacker/layouts/partials/header.html b/themes/danix-xyz-hacker/layouts/partials/header.html index 3afe968..3146775 100644 --- a/themes/danix-xyz-hacker/layouts/partials/header.html +++ b/themes/danix-xyz-hacker/layouts/partials/header.html @@ -19,13 +19,24 @@ <!-- Language switcher (desktop) --> <div class="hidden md:flex gap-2"> {{ $currentLang := .Page.Language }} + {{ $currentPath := .RelPermalink }} {{ range .Site.Languages }} {{ $langCode := .Lang }} {{ $langName := .LanguageName }} {{ $current := eq $langCode $currentLang }} - {{ $prefix := cond (eq $langCode "en") "" (printf "/%s" $langCode) }} + <!-- Build the translated URL by replacing language prefix --> + {{ $url := $currentPath }} + {{ if eq $langCode "en" }} + {{ if hasPrefix $currentPath "/it/" }} + {{ $url = strings.TrimPrefix "/it" $currentPath }} + {{ end }} + {{ else }} + {{ if not (hasPrefix $currentPath "/it/") }} + {{ $url = printf "/it%s" $currentPath }} + {{ end }} + {{ end }} <a - href="{{ $prefix }}/" + href="{{ $url }}" class="px-2 py-1 text-sm rounded transition-colors {{ if $current }}bg-accent text-white{{ else }}hover:bg-surface{{ end }}" > {{ $langName }} |
