cc-haha/site/index.html
程序员阿江(Relakkes) 07a06227ca feat(site): pick the docs language from the browser on first visit
The site already ships both languages, but / always served Chinese, so
English readers had to find the switcher themselves. A Chinese browser now
stays on /, everything else lands on /en.

The decision runs as an inline script in index.html, next to the existing
theme anti-flash block: deferring it to React would show English readers a
full screen of Chinese first. It only fires on the root path — /en, /start
and /en/start are deliberate destinations, and redirecting those would kick
readers off any cross-language link they follow. A manual switch is stored
in localStorage and wins over the browser language, otherwise switching
would be undone on the next visit to the home page.

resolveRootRedirect carries the same rules as a testable pure function.
check-docs asserts the inline copy and the module agree on the storage key,
the Chinese tag pattern and the root-only guard, so the two cannot drift.
2026-07-29 09:23:19 +08:00

69 lines
3.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#201d17" media="(prefers-color-scheme: dark)">
<meta name="description" content="Claude Code Haha — Claude Code 的本地优先桌面客户端。会话、改动、Agent、定时任务都摆在明处接哪个模型你说了算。">
<link rel="icon" href="/images/app-icon.png" type="image/png">
<link rel="preload" href="/fonts/inter-latin.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/fonts/noto-serif-sc-latin.woff2" as="font" type="font/woff2" crossorigin>
<meta property="og:type" content="website">
<meta property="og:site_name" content="Claude Code Haha">
<meta property="og:title" content="Claude Code Haha — Claude Code 的本地优先桌面客户端">
<meta property="og:description" content="会话、改动、Agent、定时任务都摆在明处。接哪个模型你说了算改哪一行你点头才算。">
<meta property="og:image" content="https://cchaha.ai/images/banner.png">
<meta name="twitter:card" content="summary_large_image">
<title>Claude Code Haha — Claude Code 的本地优先桌面客户端</title>
<script>
// 首帧就把语言定下来:中文浏览器留在中文站,其余跳英文站。等 React 起来再跳的话,
// 英文用户会先看到一整屏中文。只认根路径,带语言前缀的地址是用户的明确意图。
// 判定规则与 src/lib/locale.js 是同一套check-docs.mjs 盯着两处不漂移。
(function () {
try {
if (window.location.pathname.replace(/\/+$/, '') !== '') return
var stored = localStorage.getItem('cch-locale')
var locale = stored === 'en' || stored === 'zh'
? stored
: ((navigator.languages || [navigator.language || '']).some(function (tag) {
return /^zh(?:-|$)/i.test(String(tag).trim())
}) ? 'zh' : 'en')
if (locale === 'en') {
window.location.replace('/en' + window.location.search + window.location.hash)
}
} catch (error) {
// 读不到偏好就维持中文站,别让语言分流把首页整个拦死。
}
})()
</script>
<script>
// 首帧就把主题定下来,避免深色偏好的用户先闪一下白屏。
(function () {
try {
var stored = localStorage.getItem('cch-theme')
var theme = stored === 'dark' || stored === 'light'
? stored
: (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
document.documentElement.dataset.theme = theme
} catch (error) {
document.documentElement.dataset.theme = 'light'
}
})()
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-D42DM82263"></script>
<script>
window.dataLayer = window.dataLayer || []
function gtag(){dataLayer.push(arguments)}
gtag('js', new Date())
gtag('config', 'G-D42DM82263')
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>