Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
---

<!-- Global Metadata -->
Expand All @@ -20,6 +27,11 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
<!-- Canonical URL -->
<link rel="canonical" href={canonicalURL} />

<!-- hreflang – tells Google these pages are language alternates, not duplicates -->
<link rel="alternate" hreflang="en" href={enURL} />
<link rel="alternate" hreflang="es" href={esURL} />
<link rel="alternate" hreflang="x-default" href={enURL} />

<!-- Primary Meta Tags -->
<title>{title}</title>
<meta name="title" content={title} />
Expand Down
8 changes: 5 additions & 3 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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;
---

<!doctype html>
<html lang={lang}>
<head>
<BaseHead title={title} description={description} lang={lang} />
<BaseHead title={title} description={description} lang={lang} alternateUrl={alternateUrl} />
</head>
<body class="min-h-screen bg-background flex flex-col">
<Header lang={lang} />
Expand Down
1 change: 1 addition & 0 deletions src/pages/about.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<AboutView strings={aboutStrings} client:load />
<ExperienceView strings={experienceStrings} client:visible />
Expand Down
1 change: 1 addition & 0 deletions src/pages/es/about.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<AboutView strings={aboutStrings} client:load />
<ExperienceView strings={experienceStrings} client:visible />
Expand Down
1 change: 1 addition & 0 deletions src/pages/es/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const contactStrings = {
title="Jesús Ordosgoitty — Transforma Tu Presencia Digital"
description={t('hero.description')}
lang={lang}
alternateUrl="https://jodaz.xyz/"
>
<HeroIsland {...heroProps} client:load />
<ServicesSection lang={lang} />
Expand Down
1 change: 1 addition & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const contactStrings = {
title="Jesus Ordosgoitty — Transform Your Digital Presence"
description={t('hero.description')}
lang={lang}
alternateUrl="https://jodaz.xyz/es/"
>
<HeroIsland {...heroProps} client:load />
<ServicesSection lang={lang} />
Expand Down
Loading