From dfe3cc3b9850866202f0cfb20c9b9029c975a322 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 15 Apr 2026 17:33:26 +0200 Subject: Fix language switcher to preserve current page path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update language switcher to translate current page path instead of redirecting to root - When switching languages, preserve the page you're on (e.g., /articles/ → /it/articles/) - Works for both desktop header and mobile hamburger menu - Uses Hugo's string functions to manipulate URL paths Co-Authored-By: Claude Haiku 4.5 --- .../danix-xyz-hacker/layouts/partials/hamburger-menu.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html') diff --git a/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html b/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html index c22981b..ee80d20 100644 --- a/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html +++ b/themes/danix-xyz-hacker/layouts/partials/hamburger-menu.html @@ -38,14 +38,25 @@
{{ i18n "language" }}
{{ $currentLang := .Page.Language }} + {{ $currentPath := .RelPermalink }} {{ range .Site.Languages }} {{ $langCode := .Lang }} {{ $langName := .LanguageName }} {{ $current := eq $langCode $currentLang }} - {{ $prefix := cond (eq $langCode "en") "" (printf "/%s" $langCode) }} + + {{ $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 }} {{ $langName }} -- cgit v1.2.3