2
0

feat(i18n): Layout derives locale/currentPath, threads t to Nav+Footer

This commit is contained in:
2026-05-18 22:16:37 +08:00
parent cdab68ee2a
commit 82ca08ec67

View File

@@ -1,6 +1,7 @@
---
import Nav from '../components/Nav.astro';
import Footer from '../components/Footer.astro';
import { getTranslations } from '../i18n/utils';
interface Props {
title?: string;
@@ -16,12 +17,18 @@ const {
noindex = false,
} = Astro.props;
const locale = Astro.currentLocale ?? 'en';
const rawPath = Astro.url.pathname;
const currentPath =
locale === 'zh-cn' ? rawPath.replace(/^\/zh-cn/, '') || '/' : rawPath;
const t = getTranslations(locale);
const siteUrl = Astro.site?.href || '';
const canonicalUrl = `${siteUrl.replace(/\/$/, '')}${canonicalPath}`;
---
<!doctype html>
<html lang="en">
<html lang={locale === 'zh-cn' ? 'zh-CN' : 'en'}>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -59,9 +66,9 @@ const canonicalUrl = `${siteUrl.replace(/\/$/, '')}${canonicalPath}`;
/>
</head>
<body>
<Nav />
<Nav locale={locale} currentPath={currentPath} t={t.nav} />
<slot />
<Footer />
<Footer t={t.footer} />
</body>
</html>