Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
fix(website): improve sharing previews and detect browser language (#9)
澄潭c1e1462a88c5
diff --git a/apps/website/.gitignore b/apps/website/.gitignoreindex d23c637c..30de806f 100644--- a/apps/website/.gitignore+++ b/apps/website/.gitignore@@ -5,3 +5,4 @@ public/api/public/decision-assets/public/install/public/install.sh+public/brand/app-icon.pngdiff --git a/apps/website/public/scripts/language.js b/apps/website/public/scripts/language.jsnew file mode 100644index 00000000..24265086--- /dev/null+++ b/apps/website/public/scripts/language.js@@ -0,0 +1,30 @@+(() => {+ const key = 'hiroute-language';+ const url = new URL(location.href);+ const explicit = url.searchParams.get('lang');+ let preference;+ try { preference = localStorage.getItem(key); } catch {}+ if (explicit === 'zh' || explicit === 'en') {+ preference = explicit;+ try { localStorage.setItem(key, explicit); } catch {}+ }+ if (url.pathname === '/') {+ const browserLanguage = navigator.languages?.[0] || navigator.language || 'en';+ const language = preference === 'zh' || preference === 'en'+ ? preference : /^zh(?:-|$)/i.test(browserLanguage) ? 'zh' : 'en';+ if (language === 'en') {+ url.pathname = '/en/';+ location.replace(url.href);+ }+ }+ document.addEventListener('click', event => {+ const link = event.target.closest?.('a[data-language]');+ if (!link) return;+ const language = link.lang === 'en' ? 'en' : 'zh';+ try { localStorage.setItem(key, language); } catch {}+ const target = new URL(link.href);+ target.searchParams.set('lang', language);+ target.hash = location.hash;+ link.href = target.href;+ }, true);+})();diff --git a/apps/website/scripts/prepare-content.mjs b/apps/website/scripts/prepare-content.mjsindex e66bc39a..c5cc4a43 100644--- a/apps/website/scripts/prepare-content.mjs+++ b/apps/website/scripts/prepare-content.mjs@@ -18,6 +18,8 @@ await fs.rm(installDirectory, { recursive: true, force: true });await fs.mkdir(apiDirectory, { recursive: true });await fs.mkdir(assetsDirectory, { recursive: true });await fs.mkdir(installDirectory, { recursive: true });+// Reuse the Desktop logo for raster-only link preview services.+await fs.copyFile(path.join(repository, 'apps/desktop/src-tauri/icons/icon.png'), path.join(publicDirectory, 'brand/app-icon.png'));await fs.copyFile(path.join(source, 'api/decision.openapi.json'), path.join(apiDirectory, 'decision.openapi.json'));for (const entry of await fs.readdir(path.join(source, 'assets'), { withFileTypes: true })) {if (entry.isFile() && /\.(png|svg)$/.test(entry.name)) {diff --git a/apps/website/scripts/validate-build.mjs b/apps/website/scripts/validate-build.mjsindex b85ea9b9..4b591a45 100644--- a/apps/website/scripts/validate-build.mjs+++ b/apps/website/scripts/validate-build.mjs@@ -54,7 +54,8 @@ const untranslatedChinesePageCopy = ['DOWNLOAD',];for (const file of htmlFiles.filter(file => !path.relative(dist, file).startsWith(`en${path.sep}`))) {- const html = fs.readFileSync(file, 'utf8');+ // Sharing metadata may intentionally use English; visible page copy stays localized.+ const html = fs.readFileSync(file, 'utf8').replace(/<head\b[^>]*>[\s\S]*?<\/head>/i, '');const leaked = untranslatedChinesePageCopy.find(value => html.includes(value));if (leaked) throw new Error(`English copy leaked into Chinese page ${file}: ${leaked}`);}diff --git a/apps/website/src/components/HomePage.astro b/apps/website/src/components/HomePage.astroindex 4c9a5402..ca64dc20 100644--- a/apps/website/src/components/HomePage.astro+++ b/apps/website/src/components/HomePage.astro@@ -14,7 +14,7 @@ const releaseKinds = [preferredArtifact && t('macOS 桌面应用', 'macOS Deskto---<SiteLayout language={language}title={t('HiRoute · 长程 Agent 智能路由引擎', 'HiRoute · Intelligent routing for long-horizon agents')}- description={t('按任务选择 Agent,按阶段选择模型。通过官方 Jev 决策扩展,结合执行表现和任务复杂度,做出缓存友好的路由决策。', 'Match agents to tasks and models to stages. Use the official Jev extension to make cache-friendly decisions from task complexity and observed performance.')}+ description="Intelligent routing for long-horizon agents. Match models to each stage with Jev, balancing quality and cost."path={path} alternatePath={alternatePath} fullWidth><section class="hero wrap"><div>diff --git a/apps/website/src/layouts/SiteLayout.astro b/apps/website/src/layouts/SiteLayout.astroindex 83543419..689f5f84 100644--- a/apps/website/src/layouts/SiteLayout.astro+++ b/apps/website/src/layouts/SiteLayout.astro@@ -22,6 +22,7 @@ const nav = english ? [<html lang={english ? 'en' : 'zh-CN'}><head><meta charset="utf-8">+ <script is:inline src="/scripts/language.js"></script><meta name="viewport" content="width=device-width,initial-scale=1"><title>{title}</title><meta name="description" content={description}>@@ -31,15 +32,21 @@ const nav = english ? [<link rel="alternate" hreflang="zh-CN" href={english ? alternate : canonical}><link rel="alternate" hreflang="en" href={english ? canonical : alternate}><link rel="alternate" hreflang="x-default" href={new URL('/', Astro.site)}>- <link rel="icon" type="image/svg+xml" href="/brand/mark-switch.svg">+ <link rel="icon" type="image/png" sizes="1024x1024" href="/brand/app-icon.png">+ <link rel="apple-touch-icon" href="/brand/app-icon.png"><meta property="og:type" content="website"><meta property="og:title" content={title}><meta property="og:description" content={description}><meta property="og:url" content={canonical}>- <meta property="og:image" content={new URL('/brand/og.svg', Astro.site)}>- <meta property="og:image:width" content="1200">- <meta property="og:image:height" content="630">- <meta name="twitter:card" content="summary_large_image">+ <meta property="og:site_name" content="HiRoute">+ <meta property="og:image" content={new URL('/brand/app-icon.png', Astro.site)}>+ <meta property="og:image:type" content="image/png">+ <meta property="og:image:width" content="1024">+ <meta property="og:image:height" content="1024">+ <meta property="og:image:alt" content="HiRoute logo">+ <meta name="twitter:card" content="summary">+ <meta name="twitter:image" content={new URL('/brand/app-icon.png', Astro.site)}>+ <meta name="twitter:description" content={description}></head><body><header class="header wrap site-header">diff --git a/apps/website/tests/language.test.mjs b/apps/website/tests/language.test.mjsnew file mode 100644index 00000000..1a7cef3e--- /dev/null+++ b/apps/website/tests/language.test.mjs@@ -0,0 +1,51 @@+import assert from 'node:assert/strict';+import fs from 'node:fs';+import vm from 'node:vm';+import test from 'node:test';++const source = fs.readFileSync(new URL('../public/scripts/language.js', import.meta.url), 'utf8');+function visit(path, languages, stored, blocked = false) {+ let redirected;+ let click;+ const storage = new Map(stored ? [['hiroute-language', stored]] : []);+ vm.runInNewContext(source, {+ URL,+ location: { href: 'https://hiroute.ai' + path, hash: new URL('https://hiroute.ai' + path).hash,+ replace: value => { redirected = value; } },+ navigator: { languages, language: languages[0] },+ localStorage: {+ getItem: key => { if (blocked) throw Error('blocked'); return storage.get(key); },+ setItem: (key, value) => { if (blocked) throw Error('blocked'); storage.set(key, value); },+ },+ document: { addEventListener: (_, handler) => { click = handler; } },+ });+ return { redirected, storage, click };+}++test('root follows the preferred browser language, retaining query and fragment', () => {+ assert.equal(visit('/?campaign=test#how', ['en-US', 'zh-CN']).redirected,+ 'https://hiroute.ai/en/?campaign=test#how');+ for (const language of ['zh-CN', 'zh-TW', 'zh-HK', 'zh']) {+ assert.equal(visit('/', [language]).redirected, undefined);+ }+ assert.equal(visit('/', ['fr-FR']).redirected, 'https://hiroute.ai/en/');+});++test('explicit and saved language choices win, while direct routes remain stable', () => {+ assert.equal(visit('/', ['en'], 'zh').redirected, undefined);+ assert.equal(visit('/', ['zh'], 'en').redirected, 'https://hiroute.ai/en/');+ assert.equal(visit('/?lang=zh', ['en'], 'en', true).redirected, undefined);+ for (const path of ['/en/', '/docs/cli/', '/en/docs/cli/']) {+ assert.equal(visit(path, ['en'], 'zh').redirected, undefined);+ }+});++test('manual language switch preserves the section and works when storage is unavailable', () => {+ for (const blocked of [false, true]) {+ const page = visit('/en/#how', ['en'], undefined, blocked);+ const link = { href: 'https://hiroute.ai/', lang: 'zh-CN' };+ page.click({ target: { closest: () => link } });+ assert.equal(link.href, 'https://hiroute.ai/?lang=zh#how');+ if (!blocked) assert.equal(page.storage.get('hiroute-language'), 'zh');+ }+});