@@ -3,7 +3,11 @@ import Header from "./Header.astro";
33import Footer from " ./Footer.astro" ;
44import GridBackground from " ../ui/GridBackground.astro" ;
55import " ../../styles/global.css" ;
6- import { type Locale , defaultLocale , t } from " ../../lib/i18n" ;
6+ // ZH-specific styles are imported unconditionally — every rule inside is
7+ // scoped under `html[lang="zh"]`, so EN pages never apply any of it, and
8+ // the CJK woff2 files only load when glyphs actually require them.
9+ import " ../../styles/zh.css" ;
10+ import { type Locale , defaultLocale , t , toggleLocalePath } from " ../../lib/i18n" ;
711
812interface Props {
913 title? : string ;
@@ -25,6 +29,10 @@ const siteTitle = t(lang, "site.title");
2529const pageTitle = title ? ` ${title } — ${siteTitle } ` : siteTitle ;
2630const pageDescription = description ?? t (lang , " site.description" );
2731const canonicalUrl = new URL (Astro .url .pathname , Astro .site );
32+
33+ // Compute absolute URLs for each locale variant of this page
34+ const enUrl = new URL (toggleLocalePath (Astro .url .pathname , " en" ), Astro .site ).href ;
35+ const zhUrl = new URL (toggleLocalePath (Astro .url .pathname , " zh" ), Astro .site ).href ;
2836---
2937
3038<!doctype html >
@@ -41,6 +49,11 @@ const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
4149 <!-- Canonical -->
4250 <link rel =" canonical" href ={ canonicalUrl .href } />
4351
52+ <!-- Alternate language variants (for SEO) -->
53+ <link rel =" alternate" hreflang =" en" href ={ enUrl } />
54+ <link rel =" alternate" hreflang =" zh" href ={ zhUrl } />
55+ <link rel =" alternate" hreflang =" x-default" href ={ enUrl } />
56+
4457 <!-- Open Graph -->
4558 <meta property =" og:type" content =" website" />
4659 <meta property =" og:title" content ={ pageTitle } />
0 commit comments