summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-26 17:45:02 +0100
committerJoe Carstairs <65492573+Sycamost@users.noreply.github.com>2023-08-26 17:45:02 +0100
commit53f171a3e90ae818711945635a213b47cf502f25 (patch)
tree76db96432d05657022c541bd0e74e86e80e255d0 /src
parent628b8daad0b319b092b72bfe262b445fe7c8b197 (diff)
Adds link hreflangs for Google
Diffstat (limited to 'src')
-rw-r--r--src/layouts/Layout.astro14
1 files changed, 14 insertions, 0 deletions
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;
+}
---
<!DOCTYPE html>
@@ -31,6 +39,12 @@ const t = translate(locale);
title={t(tFeed, { key: 'title' })}
href={`/${locale}/rss.xml`}
/>
+ {
+ locales.map((locale) => (
+ <link rel="alternate" href={qualifiedLocalisedPath(locale)} hreflang={locale} />
+ ))
+ }
+ <link rel="alternate" href={qualifiedLocalisedPath(defaultLocale)} hreflang="x-default" />
<meta name="generator" content={Astro.generator} />
<title>{title} | {t(site, { key: 'title' })}</title>
</head>