diff --git a/src/components/Header.astro b/src/components/Header.astro index b0253ad..5d028d9 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -2,26 +2,30 @@ import { localeOf, localePath } from '../lib/locale'; import { t } from '../i18n/ui'; -// 顶部导航:≤4 项纪律(防 higan 十项复发);当前页 aria-current +// 顶部导航:单行纪律 + 双语整轨(zh 无前缀 ↔ /en/,locale 构建期按页自推断—— +// 曾只把 locale 喂给词条/语言钮而 href 裸奔 zh 路径,en 页点导航全部跌回中文轨) const path = Astro.url.pathname; +const curLocale = localeOf(path); +const prefix = curLocale === 'en' ? '/en' : ''; const isCurrent = (href: string) => path === href || path === href.replace(/\/$/, '') || path.startsWith(href); -// 语言切换:同路径跨前缀跳转(zh 无前缀 ↔ /en/),预构建双语毫秒级 -const curLocale = localeOf(path); +// 顺序:开源 · 文章 · 图库 · 瞬间 · 关于(瞬间新进,开源前置) const nav = [ - { href: '/archives/', label: t('nav_posts', curLocale) }, - { href: '/gallery/', label: t('nav_gallery', curLocale) }, - { href: '/about/', label: t('nav_about', curLocale) }, - { href: '/opensource/', label: t('nav_opensource', curLocale) }, + { href: `${prefix}/opensource/`, label: t('nav_opensource', curLocale) }, + { href: `${prefix}/archives/`, label: t('nav_posts', curLocale) }, + { href: `${prefix}/gallery/`, label: t('nav_gallery', curLocale) }, + { href: `${prefix}/moments/`, label: t('nav_moments', curLocale) }, + { href: `${prefix}/about/`, label: t('nav_about', curLocale) }, ]; +const homeHref = curLocale === 'en' ? '/en/' : '/'; const switchHref = localePath(path, curLocale === 'zh' ? 'en' : 'zh'); const switchLabel = curLocale === 'zh' ? 'EN' : '中'; ---