From 53f171a3e90ae818711945635a213b47cf502f25 Mon Sep 17 00:00:00 2001 From: Joe Carstairs <65492573+Sycamost@users.noreply.github.com> Date: Sat, 26 Aug 2023 17:45:02 +0100 Subject: Adds link hreflangs for Google --- src/layouts/Layout.astro | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 2a4a542..24d0198 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,10 +1,12 @@ --- import Footer from '$components/Footer.astro'; import Navbar from '$components/Navbar/Navbar.astro'; +import locales, { defaultLocale } from '$i18n/locales'; import translate from '$i18n/translate'; import tFeed from '$i18n/translations/pages/rss.xml'; import site from '$i18n/translations/site'; import { getLocaleFromPathOrDefault } from '$lib/getLocaleFromPath'; +import type Locale from '$types/Locale'; interface Props { title: string; @@ -13,6 +15,12 @@ interface Props { const { title } = Astro.props; const locale = getLocaleFromPathOrDefault(Astro.url.pathname); const t = translate(locale); + +function qualifiedLocalisedPath(newLocale: Locale) { + const localePathSegment = new RegExp(`^/${locale}`); + const localisedPath = Astro.url.pathname.replace(localePathSegment, newLocale); + return Astro.site + localisedPath; +} --- @@ -31,6 +39,12 @@ const t = translate(locale); title={t(tFeed, { key: 'title' })} href={`/${locale}/rss.xml`} /> + { + locales.map((locale) => ( + + )) + } +