fix(seo): correct hreflang alternates by stripping locale prefix; set x-default to default locale page

This commit is contained in:
Ruidy 2025-09-06 18:44:43 -04:00
parent 72483c4ec5
commit 492b549d8b
5 changed files with 1146 additions and 2268 deletions

View file

@ -1,5 +1,6 @@
// @ts-check
import { defineConfig } from "astro/config";
import sitemap from "@astrojs/sitemap";
import tailwindcss from "@tailwindcss/vite";
@ -14,6 +15,7 @@ export default defineConfig({
redirectToDefaultLocale: true,
},
},
integrations: [sitemap()],
vite: {
plugins: [tailwindcss()],
},

View file

@ -10,6 +10,7 @@
"format": "prettier -wl ."
},
"dependencies": {
"@astrojs/sitemap": "^3.1.0",
"@tailwindcss/vite": "^4.1.13",
"astro": "^5.13.5",
"lucide-astro": "^0.542.0",

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,6 @@
User-agent: *
Allow: /
# Both standard and index sitemaps (plugin may generate an index)
Sitemap: https://villafleuriegp.com/sitemap.xml
Sitemap: https://villafleuriegp.com/sitemap-index.xml

View file

@ -3,9 +3,14 @@ import '../styles/global.css';
import { ctaLabelFor } from '../i18n/routes';
import { getRelativeLocaleUrl } from 'astro:i18n';
const { title = 'VillaFleurie', lang = 'fr', description = 'Séjours confortables au Gosier pour couples et petites familles' } = Astro.props;
// Locale alternates for the current path
const altFr = getRelativeLocaleUrl('fr', Astro.url.pathname);
const altEn = getRelativeLocaleUrl('en', Astro.url.pathname);
// Locale alternates: strip current locale prefix before generating sibling paths
const pathSuffix = (() => {
const p = Astro.url.pathname;
const stripped = p.replace(/^\/(fr|en)/, "");
return stripped === "" ? "/" : stripped;
})();
const altFr = getRelativeLocaleUrl('fr', pathSuffix);
const altEn = getRelativeLocaleUrl('en', pathSuffix);
// Canonical URL
const canonicalUrl = new URL(Astro.url.pathname, Astro.site ?? 'https://villafleuriegp.com').toString();
const nav = lang === 'en'
@ -35,7 +40,7 @@ const homeHref = getRelativeLocaleUrl(lang, '/');
<link rel="icon" href="/assets/images/logo.png" />
<link rel="alternate" hreflang="fr" href={altFr} />
<link rel="alternate" hreflang="en" href={altEn} />
<link rel="alternate" hreflang="x-default" href="/fr/" />
<link rel="alternate" hreflang="x-default" href={altFr} />
<!-- Open Graph -->
<meta property="og:type" content="website" />
<meta property="og:site_name" content="VillaFleurie" />