Fix hreflang canonical + LangToggle: use centralized ES/EN slug map

- Add src/i18n/hreflang-map.ts with getHreflangUrl() for translated slugs
- Fix BaseLayout.astro hreflang tags (was hardcoding ES='/', 404 URLs)
- Fix LangToggle.astro to use hreflang map instead of naive path swap
- Fix htaccess.conf: remove !-f / !-d that blocked .html redirects
This commit is contained in:
Mauricio López Coria
2026-07-05 20:34:15 -03:00
parent ff3e57051f
commit b26959a041
4 changed files with 58 additions and 14 deletions
+44
View File
@@ -0,0 +1,44 @@
import type { Lang } from './ui';
const esToEnOverrides: Record<string, string | null> = {
'/nosotros/': '/en/about/',
'/contacto/': '/en/contact/',
'/planes/': '/en/plans/',
'/instructivos/': '/en/tutorials/',
'/legal/privacidad/': '/en/legal/privacy/',
'/legal/terminos/': '/en/legal/terms/',
'/preguntas/': null,
};
const enToEsMap: Record<string, string> = {};
for (const [esPath, enPath] of Object.entries(esToEnOverrides)) {
if (enPath) enToEsMap[enPath] = esPath;
}
const SITE_URL = 'https://hostingdelsur.net';
export function getHreflangUrl(
pathname: string,
currentLang: Lang,
targetLang: Lang
): string | null {
if (currentLang === targetLang) {
return `${SITE_URL}${pathname}`;
}
if (currentLang === 'es' && targetLang === 'en') {
const override = esToEnOverrides[pathname];
if (override === null) return null;
if (override) return `${SITE_URL}${override}`;
return `${SITE_URL}/en${pathname}`;
}
if (currentLang === 'en' && targetLang === 'es') {
const override = enToEsMap[pathname];
if (override) return `${SITE_URL}${override}`;
const esPath = pathname.replace(/^\/en/, '') || '/';
return `${SITE_URL}${esPath}`;
}
return null;
}