From 2c17174c8caf74f13c9db5a511bfc53bedccefd6 Mon Sep 17 00:00:00 2001 From: Somrat <58769763+tfsomrat@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:29:09 +0600 Subject: [PATCH] update language switcher, ref: #162 --- .../components/language-switcher.html | 53 +++++++++++-------- package.json | 2 +- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/layouts/partials/components/language-switcher.html b/layouts/partials/components/language-switcher.html index bbee9dd..b8cf68f 100644 --- a/layouts/partials/components/language-switcher.html +++ b/layouts/partials/components/language-switcher.html @@ -1,28 +1,35 @@ +{{ if hugo.IsMultilingual }} {{ $class := .Class }} {{ $context := .Context }} {{ $pageLang := $context.Lang }} -{{ $base:= urls.Parse site.Home.Permalink }} -{{ $siteLanguages := site.Home.AllTranslations }} -{{ $pageLink := replace (replace $context.RelPermalink (add $pageLang "/") "") $base.Path "/" }} - -{{ if $context.IsTranslated }} - +{{ $pageTranslations := newScratch }} +{{/* First, fill all translations of the Home page (failsafe) */}} +{{ range site.Home.AllTranslations }} + {{ $pageTranslations.Set .Language.Lang .Permalink }} {{ end }} +{{/* Second, if a translation exists for the current page for the target language, replace failsafe */}} +{{ range $context.AllTranslations }} + {{ $pageTranslations.Set .Language.Lang .Permalink }} +{{ end }} + + +{{ end }} \ No newline at end of file diff --git a/package.json b/package.json index 0508728..1b46e63 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hugoplate", "description": "hugo tailwindcss boilerplate", - "version": "1.18.0", + "version": "1.18.1", "license": "MIT", "author": "zeon.studio", "scripts": {