From cb3e759f75f643c006faf82eb9c2f88064da91e5 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:38:28 -0600 Subject: [PATCH] feat: remove redundant /en --- packages/website/src/layouts/BaseLayout.astro | 14 ++++++++++++-- packages/website/src/pages/[...locale]/index.astro | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/website/src/layouts/BaseLayout.astro b/packages/website/src/layouts/BaseLayout.astro index 061f903d2..8228acb92 100644 --- a/packages/website/src/layouts/BaseLayout.astro +++ b/packages/website/src/layouts/BaseLayout.astro @@ -46,9 +46,19 @@ const isRoot = pathname === '/'; window.location.pathname.startsWith(`/${locale}`), ); const bestLocale = getBestLocale(); + const currentPathLocale = SUPPORTED_LOCALES.find((locale) => + window.location.pathname.startsWith(`/${locale}`), + ); - if (!isI18nPath && bestLocale !== undefined) { - window.location.pathname = `/${bestLocale}${window.location.pathname}`; + console.log(bestLocale); + + if (bestLocale !== currentPathLocale) { + window.location.pathname = isI18nPath + ? window.location.pathname.replace( + `/${currentPathLocale}`, + bestLocale === undefined ? '' : `/${bestLocale}`, + ) + : `/${bestLocale}${window.location.pathname}`; } diff --git a/packages/website/src/pages/[...locale]/index.astro b/packages/website/src/pages/[...locale]/index.astro index 783fd9480..3fbcb940b 100644 --- a/packages/website/src/pages/[...locale]/index.astro +++ b/packages/website/src/pages/[...locale]/index.astro @@ -33,7 +33,9 @@ const strings = getStrings(Astro.params.locale); export const getStaticPaths = (() => { return [ - ...SUPPORTED_LOCALES.map((locale) => ({ params: { locale } })), + ...SUPPORTED_LOCALES.filter((locale) => locale !== DEFAULT_LOCALE).map( + (locale) => ({ params: { locale } }), + ), { params: { locale: undefined } }, ]; }) satisfies GetStaticPaths;