From 41890965fa3e7618c54b6073e361211c6c376f39 Mon Sep 17 00:00:00 2001 From: itziarZG Date: Tue, 17 Feb 2026 11:40:25 +0100 Subject: [PATCH] feat: add navigation to header --- src/components/LanguagePicker.astro | 9 +- src/components/Nav.astro | 8 +- src/components/Navigation.astro | 59 +++++++----- src/components/index.astro | 4 +- src/i18n/menu/ca.ts | 19 +++- src/i18n/menu/en.ts | 19 +++- src/i18n/menu/es.ts | 19 +++- src/layouts/Layout.astro | 6 +- src/pages/[lang]/sponsors.astro | 136 +++++++++++++++------------- src/style/global.css | 6 +- 10 files changed, 179 insertions(+), 106 deletions(-) diff --git a/src/components/LanguagePicker.astro b/src/components/LanguagePicker.astro index 522a305..e7f11ae 100644 --- a/src/components/LanguagePicker.astro +++ b/src/components/LanguagePicker.astro @@ -30,7 +30,6 @@ const getPathForLang = (targetLang: string) => { return '/' + parts.join('/') } - --- { @@ -48,10 +47,10 @@ const getPathForLang = (targetLang: string) => { lang={lang} aria-current={lang === currentLang ? 'page' : undefined} class:list={[ - 'px-2 py-1 text-sm font-mono rounded transition-colors outline-none', + 'px-2 py-1 text-sm font-outfit rounded transition-colors outline-none', lang === currentLang - ? 'text-blue-400 font-bold' - : 'text-slate-400 hover:text-white focus-visible:text-blue-400', + ? 'text-pycon-red-100 font-bold underline' + : 'text-pycon-orange-500 hover:text-white focus-visible:text-pycon-red-500', ]} > {t.label[lang as keyof typeof t.label]} @@ -70,7 +69,7 @@ const getPathForLang = (targetLang: string) => { aria-current={lang === currentLang ? 'page' : undefined} aria-label={`${t['labelariadesc']} ${t.label[lang as keyof typeof t.label]}`} class:list={[ - 'px-3 py-2 text-sm font-mono rounded transition-colors outline-none', + 'px-3 py-2 text-sm font-outfit rounded transition-colors outline-none', lang === currentLang ? 'bg-blue-600 text-white font-bold' : 'bg-white/5 text-slate-300 hover:bg-white/10 focus-visible:bg-blue-600 focus-visible:text-white', diff --git a/src/components/Nav.astro b/src/components/Nav.astro index 5a75cbc..efeecc1 100644 --- a/src/components/Nav.astro +++ b/src/components/Nav.astro @@ -14,8 +14,14 @@ import Navigation from './Navigation.astro' * - Escape: Close dropdown/mobile menu and return focus to trigger * - Tab: Standard tab navigation with proper focus management */ + +interface Props { + lang?: string +} + +const { lang } = Astro.props ---
- +
diff --git a/src/components/Navigation.astro b/src/components/Navigation.astro index ede0485..479f8d1 100644 --- a/src/components/Navigation.astro +++ b/src/components/Navigation.astro @@ -9,16 +9,32 @@ interface MenuItem { href: string children?: MenuItem[] } - -// Get current language from URL -const lang = Astro.url.pathname.split('/')[1] || 'es' + +interface Props { + lang?: string +} + +const { lang: propLang } = Astro.props + +// Get current language from URL if prop not provided +const urlLang = Astro.url.pathname.split('/')[1] || 'es' +const rawLang = propLang || urlLang const validLangs = ['es', 'en', 'ca'] as const type Lang = (typeof validLangs)[number] -const currentLang: Lang = validLangs.includes(lang as Lang) ? (lang as Lang) : 'es' +const currentLang: Lang = validLangs.includes(rawLang as Lang) ? (rawLang as Lang) : 'es' // Helper to check if a URL is external const isExternal = (href: string) => href.startsWith('http://') || href.startsWith('https://') +// Helper to get localized URL with hash support +const getLocalizedUrl = (lang: string, href: string) => { + if (isExternal(href)) return href + + const [path, hash] = href.split('#') + const localizedPath = getRelativeLocaleUrl(lang, path) + return hash ? `${localizedPath}#${hash}` : localizedPath +} + /** * Navigation Component * @@ -45,9 +61,9 @@ const { items } = menuTexts[currentLang] - PyConES + PyConES
@@ -61,7 +77,7 @@ const { items } = menuTexts[currentLang] <>
- +