diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index d85390f..bcf9b3c 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -5,10 +5,17 @@ interface Props { description: string; image?: string; lang?: string; + alternateUrl?: string; // URL of the same page in the other language } -const { title, description, image = '/og-image.png', lang = 'en' } = Astro.props; +const { title, description, image = '/og-image.png', lang = 'en', alternateUrl } = Astro.props; const canonicalURL = new URL(Astro.url.pathname, Astro.site); + +// Compute hreflang URLs +// lang='en' → this page is English, alternate is Spanish (alternateUrl) +// lang='es' → this page is Spanish, alternate is English (alternateUrl) +const enURL = lang === 'en' ? canonicalURL.href : (alternateUrl ?? new URL('/', Astro.site).href); +const esURL = lang === 'es' ? canonicalURL.href : (alternateUrl ?? new URL('/es/', Astro.site).href); --- @@ -20,6 +27,11 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site); + + + + + {title} diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index 44258e3..8e11d5c 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -3,21 +3,23 @@ import BaseHead from '@/components/BaseHead.astro'; import Header from '@/components/Header.astro'; import Footer from '@/components/Footer.astro'; +import type { Lang } from '@/lib/i18n'; import '@/index.css'; interface Props { title: string; description: string; - lang?: string; + lang?: Lang; + alternateUrl?: string; // URL of the equivalent page in the other language } -const { title, description, lang = 'en' } = Astro.props; +const { title, description, lang = 'en', alternateUrl } = Astro.props; --- - +
diff --git a/src/pages/about.astro b/src/pages/about.astro index 4f4d8cf..10e26be 100644 --- a/src/pages/about.astro +++ b/src/pages/about.astro @@ -28,6 +28,7 @@ const experienceStrings = { title={`${t('about.line1')} ${t('about.line2')} — Jesus Ordosgoitty`} description={t('about.description')} lang={lang} + alternateUrl="https://jodaz.xyz/es/about" > diff --git a/src/pages/es/about.astro b/src/pages/es/about.astro index 48f58f8..f906784 100644 --- a/src/pages/es/about.astro +++ b/src/pages/es/about.astro @@ -28,6 +28,7 @@ const experienceStrings = { title={`${t('about.line1')} ${t('about.line2')} — Jesús Ordosgoitty`} description={t('about.description')} lang={lang} + alternateUrl="https://jodaz.xyz/about" > diff --git a/src/pages/es/index.astro b/src/pages/es/index.astro index 4137d80..e9fc722 100644 --- a/src/pages/es/index.astro +++ b/src/pages/es/index.astro @@ -43,6 +43,7 @@ const contactStrings = { title="Jesús Ordosgoitty — Transforma Tu Presencia Digital" description={t('hero.description')} lang={lang} + alternateUrl="https://jodaz.xyz/" > diff --git a/src/pages/index.astro b/src/pages/index.astro index 193bf82..53f9af6 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -43,6 +43,7 @@ const contactStrings = { title="Jesus Ordosgoitty — Transform Your Digital Presence" description={t('hero.description')} lang={lang} + alternateUrl="https://jodaz.xyz/es/" >