saladday1 commited on
Commit
ebe5562
·
verified ·
1 Parent(s): 784350a

code: sync from git

Browse files
code/.claude/skills/eco-release/SKILL.md CHANGED
@@ -24,7 +24,7 @@ description: MiniMax 官方在 Hugging Face 上发了新模型(新版本如 M3
24
  | `label_diff.py <家族> <旧标签>` | 改规则前后每个发布的计数,以及每个变动的仓库 |
25
  | `sample.py <家族> <lineage> [N] [--uncounted]` | 随机抽样出链接,人工核对 |
26
  | `preview.sh [--live-data]` | 用本地或线上数据构建页面,在 Mac 上开 18767 端口 |
27
- | `shots.mjs`(在 Mac 上运行) | 桌面和手机截图,报告报错、404、溢出,以及顶部视频是否在播;第三个参数 `lang=en` / `lang=zh` 选语言(不写就跟 Mac 的系统语言,是中文) |
28
  | `site_media.mjs`(在 Mac 上运行) | 列出 minimax.io 页面上的全部视频素材地址 |
29
  | `run_job.py [--wait]` | 按定时任务的配置立刻跑一次,当天刷新线上数据 |
30
  | `check_live.py [发布key…]` | 线上页面现在有哪些发布、各自的数字 |
@@ -106,7 +106,7 @@ python3 .claude/skills/eco-release/scripts/sample.py <key> <新lineage> 25
106
  python3 .claude/skills/eco-release/scripts/sample.py <key> <新lineage> 15 --uncounted
107
  # 页面数据:一定要全部家族一起跑(org 那一步要读每个家族的 dashboard/family/<key>.json)
108
  env -u ALL_PROXY -u all_proxy python3 scripts/daily.py --skip-snapshot
109
- bash .claude/skills/eco-release/scripts/preview.sh && ssh parsar-mac 'cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs new "home:/,rel:/<模态>/<发布key>" lang=en && /opt/homebrew/bin/node shots.mjs newzh "home:/,rel:/<模态>/<发布key>" lang=zh'
110
  ```
111
 
112
  `deploy.md` 第 2 节的七条门槛全部满足才往下走:
 
24
  | `label_diff.py <家族> <旧标签>` | 改规则前后每个发布的计数,以及每个变动的仓库 |
25
  | `sample.py <家族> <lineage> [N] [--uncounted]` | 随机抽样出链接,人工核对 |
26
  | `preview.sh [--live-data]` | 用本地或线上数据构建页面,在 Mac 上开 18767 端口 |
27
+ | `shots.mjs`(在 Mac 上运行) | 桌面和手机截图,报告报错、404、溢出,以及顶部视频是否在播;第三个参数 `ch` 截中文版(地址带 `#/ch` 后缀),不写是英文 |
28
  | `site_media.mjs`(在 Mac 上运行) | 列出 minimax.io 页面上的全部视频素材地址 |
29
  | `run_job.py [--wait]` | 按定时任务的配置立刻跑一次,当天刷新线上数据 |
30
  | `check_live.py [发布key…]` | 线上页面现在有哪些发布、各自的数字 |
 
106
  python3 .claude/skills/eco-release/scripts/sample.py <key> <新lineage> 15 --uncounted
107
  # 页面数据:一定要全部家族一起跑(org 那一步要读每个家族的 dashboard/family/<key>.json)
108
  env -u ALL_PROXY -u all_proxy python3 scripts/daily.py --skip-snapshot
109
+ bash .claude/skills/eco-release/scripts/preview.sh && ssh parsar-mac 'cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs new "home:/,rel:/<模态>/<发布key>" && /opt/homebrew/bin/node shots.mjs newzh "home:/,rel:/<模态>/<发布key>" ch'
110
  ```
111
 
112
  `deploy.md` 第 2 节的七条门槛全部满足才往下走:
code/.claude/skills/eco-release/reference/page.md CHANGED
@@ -131,8 +131,8 @@
131
  ```bash
132
  python3 scripts/daily.py --skip-snapshot # 不加 --push;全部家族一起跑,生成 data/dashboard/site.json 和各模态页
133
  bash .claude/skills/eco-release/scripts/preview.sh # 用本地数据构建,在 Mac 上开 18767 端口
134
- ssh parsar-mac 'cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs new "home:/,rel:/<模态>/<发布key>" lang=en'
135
- ssh parsar-mac 'cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs newzh "home:/,rel:/<模态>/<发布key>" lang=zh'
136
  scp 'parsar-mac:mm-shots/out/new*' /tmp/shots/ # 拉回来看,中英两版都看
137
  ```
138
 
@@ -151,8 +151,8 @@ scp 'parsar-mac:mm-shots/out/new*' /tmp/shots/ # 拉回来看,中英两版
151
  ## 5. 中英两版(`web/src/lib/i18n.ts`)
152
 
153
  - **文案只写在 `i18n.ts`**:`en` 和 `zh` 两张表,组件里用 `T.xxx`。`zh` 的类型取自 `en`,少一个键 `npx tsc -b` 就报错。不要在组件里写死英文。
154
- - **语言怎么定**:URL 的 `?lang=zh|en` 优先,其次是访客上次的选择(localStorage),最后看浏览器的第一语言。顶栏地球图标切换;切换时整页按新语言重画(App 按语言 key),所以组件只在渲染时读 `T`,不要把文案存进模块级常量。
155
  - **随语言变的格式**:`format.ts` 的 `num` 在中文下用万、亿(1.75亿、4347万),`md`、`mdy`、`my`、`mon` 出中文日期(11月3日、2026年11月)。新代码用这些函数,不要自己拼月份或 K/M。
156
  - **不翻译的**:模型名、仓库名、开发者名、H3 Family 和 M Plan 这类产品名;下载的 PNG 文件名保持英文(`slug` 会把中文全删掉)。
157
  - **字体**:中文走系统字体,顺序同 minimaxi.com(PingFang SC、MiSans、微软雅黑……),写在 `index.css` 的 `--font-cjk`。不要引 MiSans 网络字体:一个字重约 5 MB,导出 PNG 时还会被内联。
158
- - **验收**:中文预览截图用 `shots.mjs <tag> "<pages>" lang=zh`;`grep -rn 开源 web/src web/dist` 必须没有结果。
 
131
  ```bash
132
  python3 scripts/daily.py --skip-snapshot # 不加 --push;全部家族一起跑,生成 data/dashboard/site.json 和各模态页
133
  bash .claude/skills/eco-release/scripts/preview.sh # 用本地数据构建,在 Mac 上开 18767 端口
134
+ ssh parsar-mac 'cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs new "home:/,rel:/<模态>/<发布key>"'
135
+ ssh parsar-mac 'cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs newzh "home:/,rel:/<模态>/<发布key>" ch'
136
  scp 'parsar-mac:mm-shots/out/new*' /tmp/shots/ # 拉回来看,中英两版都看
137
  ```
138
 
 
151
  ## 5. 中英两版(`web/src/lib/i18n.ts`)
152
 
153
  - **文案只写在 `i18n.ts`**:`en` 和 `zh` 两张表,组件里用 `T.xxx`。`zh` 的类型取自 `en`,少一个键 `npx tsc -b` 就报错。不要在组件里写死英文。
154
+ - **语言怎么定**:只看地址里的后缀,即 hash 的第一段。`#/ch`、`#/ch/video` 是中文,`#/en/...` 或不带后缀是英文(2026-11-26 用户定的:默认英文,en 和 ch 两个后缀)。不看浏览器语言,也不记上次的选择。huggingface.co 只把 `?` 参数和 `#` 传给 Space,`/ch` 这种路径会 404,所以后缀放在 hash 里。旧的 `?lang=zh` 链接打开时会被改写成 `#/ch/...`。站内链接一律用 `route.ts` 的 `href()`,它会带上当前语言;不要手写 `#/...`。顶栏地球图标切换,切换就是改后缀;整页按新语言重画(App 按语言 key),所以组件只在渲染时读 `T`,不要把文案存进模块级常量。
155
  - **随语言变的格式**:`format.ts` 的 `num` 在中文下用万、亿(1.75亿、4347万),`md`、`mdy`、`my`、`mon` 出中文日期(11月3日、2026年11月)。新代码用这些函数,不要自己拼月份或 K/M。
156
  - **不翻译的**:模型名、仓库名、开发者名、H3 Family 和 M Plan 这类产品名;下载的 PNG 文件名保持英文(`slug` 会把中文全删掉)。
157
  - **字体**:中文走系统字体,顺序同 minimaxi.com(PingFang SC、MiSans、微软雅黑……),写在 `index.css` 的 `--font-cjk`。不要引 MiSans 网络字体:一个字重约 5 MB,导出 PNG 时还会被内联。
158
+ - **验收**:中文预览截图用 `shots.mjs <tag> "<pages>" ch`;`grep -rn 开源 web/src web/dist` 必须没有结果。
code/.claude/skills/eco-release/scripts/shots.mjs CHANGED
@@ -1,13 +1,13 @@
1
  // Screenshots of the preview at desktop and phone width, first screen and full page, with any
2
  // page error, failed request, horizontal overflow or stalled hero video reported. Runs on the
3
  // Mac (playwright-core in ~/mm-shots + Google Chrome):
4
- // cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs <tag> "home:/,m3pro:/language/m3-pro" [lang=zh]
5
- // (the optional third argument is a query string: lang=zh shoots the Chinese page)
6
  // Writes ~/mm-shots/out/<tag>_<d|m>_<name>[_fold].png; scp them back to look at them.
7
  import { mkdirSync } from "node:fs"
8
  import { chromium } from "playwright-core"
9
  const b = await chromium.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" })
10
- const U = `http://localhost:18767/index.html${process.argv[4] ? "?" + process.argv[4] : ""}#`
11
  const tag = process.argv[2] || "shot"
12
  const pages = (process.argv[3] || "home:/").split(",").map((x) => x.split(":"))
13
  const errs = []
 
1
  // Screenshots of the preview at desktop and phone width, first screen and full page, with any
2
  // page error, failed request, horizontal overflow or stalled hero video reported. Runs on the
3
  // Mac (playwright-core in ~/mm-shots + Google Chrome):
4
+ // cd ~/mm-shots && /opt/homebrew/bin/node shots.mjs <tag> "home:/,m3pro:/language/m3-pro" [ch|en]
5
+ // (the optional third argument is the language suffix: ch shoots the Chinese page, #/ch/...)
6
  // Writes ~/mm-shots/out/<tag>_<d|m>_<name>[_fold].png; scp them back to look at them.
7
  import { mkdirSync } from "node:fs"
8
  import { chromium } from "playwright-core"
9
  const b = await chromium.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" })
10
+ const U = `http://localhost:18767/index.html#${process.argv[4] ? "/" + process.argv[4] : ""}`
11
  const tag = process.argv[2] || "shot"
12
  const pages = (process.argv[3] || "home:/").split(",").map((x) => x.split(":"))
13
  const errs = []
code/web/src/lib/i18n.ts CHANGED
@@ -2,11 +2,13 @@ import { useSyncExternalStore } from "react"
2
  import type { Rel } from "@/lib/types"
3
 
4
  /**
5
- * English and Chinese copy. The language comes from `?lang=zh|en`, then the visitor's last
6
- * choice, then the browser's first language; switching re-renders the whole page (App keys it on
7
- * the language), so components read `T` while they render and nothing caches copy at import.
8
- * Every key must exist in both languages: `zh` is typed from `en`, so a missing one fails the build.
9
- * In Chinese, as in English, MiniMax's weights are never called open source: 公开 / 开放权重.
 
 
10
  */
11
  export type Lang = "en" | "zh"
12
 
@@ -187,43 +189,53 @@ const zh: typeof en = {
187
  cat: { language: "语言", video: "视频", image: "图片", music: "音乐", audio: "语音" },
188
  }
189
 
190
- const KEY = "mm-eco-lang"
191
- const valid = (s: string | null | undefined): s is Lang => s === "en" || s === "zh"
192
-
193
- function detect(): Lang {
194
- const q = new URLSearchParams(location.search).get("lang")
195
- if (valid(q)) return q
196
- try {
197
- const s = localStorage.getItem(KEY)
198
- if (valid(s)) return s
199
- } catch { /* storage blocked: fall through to the browser's language */ }
200
- return /^zh\b/i.test(navigator.languages?.[0] ?? navigator.language ?? "") ? "zh" : "en"
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
202
 
203
- let lang: Lang = detect()
204
- /** The copy in the current language; reassigned by setLang. */
205
  export let T = lang === "zh" ? zh : en
206
  const listeners = new Set<() => void>()
207
  const mark = () => (document.documentElement.lang = lang === "zh" ? "zh-CN" : "en")
208
  mark()
209
 
210
- export const getLang = () => lang
211
-
212
- export function setLang(l: Lang) {
213
  if (l === lang) return
214
  lang = l
215
  T = l === "zh" ? zh : en
216
  mark()
217
- try {
218
- localStorage.setItem(KEY, l)
219
- } catch { /* the choice lasts this visit only */ }
220
- // a shared ?lang= link would otherwise win over the choice on the next load
221
- const u = new URL(location.href)
222
- if (u.searchParams.has("lang")) {
223
- u.searchParams.set("lang", l)
224
- history.replaceState(history.state, "", u)
225
- }
226
  listeners.forEach((f) => f())
 
 
 
 
 
 
 
227
  }
228
 
229
  export function useLang(): Lang {
 
2
  import type { Rel } from "@/lib/types"
3
 
4
  /**
5
+ * English and Chinese copy. The language is a suffix on the page's address, the first part of the
6
+ * hash: `#/ch`, `#/ch/video`, `#/en/video`; none means English. (huggingface.co passes only the
7
+ * query and the hash on to the Space, so a path such as /ch cannot work.) An older `?lang=zh` link
8
+ * is moved into the hash on load. Switching rewrites the hash and re-renders the whole page (App
9
+ * keys it on the language), so components read `T` while they render and nothing caches copy at
10
+ * import. Every key must exist in both languages: `zh` is typed from `en`, so a missing one fails
11
+ * the build. In Chinese, as in English, MiniMax's weights are never called open source: 公开 / 开放权重.
12
  */
13
  export type Lang = "en" | "zh"
14
 
 
189
  cat: { language: "语言", video: "视频", image: "图片", music: "音乐", audio: "语音" },
190
  }
191
 
192
+ /** What the address may say: "ch" (or "zh") for Chinese, "en" for English. */
193
+ const URL_LANG: Record<string, Lang> = { en: "en", ch: "zh", zh: "zh" }
194
+
195
+ /** The hash split into its language suffix, if it has one, and the route after it (still encoded). */
196
+ export function splitHash(hash = location.hash): { lang: Lang | null; rest: string[] } {
197
+ const parts = hash.replace(/^#\/?/, "").split("/").filter(Boolean)
198
+ const l = URL_LANG[parts[0]?.toLowerCase() ?? ""]
199
+ return l ? { lang: l, rest: parts.slice(1) } : { lang: null, rest: parts }
200
+ }
201
+
202
+ /** The hash for a route in a language: English has no suffix, Chinese leads with "ch". */
203
+ export const hashFor = (l: Lang, rest: string[]) => "#/" + [...(l === "zh" ? ["ch"] : []), ...rest].join("/")
204
+
205
+ // An older ?lang=zh link: move the language into the hash, where it lives now.
206
+ {
207
+ const u = new URL(location.href)
208
+ const q = URL_LANG[u.searchParams.get("lang")?.toLowerCase() ?? ""]
209
+ if (u.searchParams.has("lang")) {
210
+ const { lang: h, rest } = splitHash()
211
+ u.searchParams.delete("lang")
212
+ u.hash = hashFor(h ?? q ?? "en", rest)
213
+ history.replaceState(history.state, "", u)
214
+ }
215
  }
216
 
217
+ let lang: Lang = splitHash().lang ?? "en"
218
+ /** The copy in the current language; follows the hash. */
219
  export let T = lang === "zh" ? zh : en
220
  const listeners = new Set<() => void>()
221
  const mark = () => (document.documentElement.lang = lang === "zh" ? "zh-CN" : "en")
222
  mark()
223
 
224
+ // Registered before the router's own listener, so the copy has switched by the time it renders.
225
+ addEventListener("hashchange", () => {
226
+ const l = splitHash().lang ?? "en"
227
  if (l === lang) return
228
  lang = l
229
  T = l === "zh" ? zh : en
230
  mark()
 
 
 
 
 
 
 
 
 
231
  listeners.forEach((f) => f())
232
+ })
233
+
234
+ export const getLang = () => lang
235
+
236
+ /** Switch language by rewriting the hash suffix; the page stays where it is in the routes. */
237
+ export function setLang(l: Lang) {
238
+ if (l !== lang) location.hash = hashFor(l, splitHash().rest)
239
  }
240
 
241
  export function useLang(): Lang {
code/web/src/lib/route.ts CHANGED
@@ -1,13 +1,15 @@
1
  import { useEffect, useState } from "react"
 
2
 
3
  /** Hash routes, because a static Space serves only index.html at the root:
4
  * #/ the landing page
5
  * #/language a category, its first release selected
6
- * #/language/m2.7 */
 
7
  export type Route = { cat: string | null; rel: string | null }
8
 
9
  const parse = (): Route => {
10
- const [cat, rel] = location.hash.replace(/^#\/?/, "").split("/").map((s) => decodeURIComponent(s))
11
  return { cat: cat || null, rel: rel || null }
12
  }
13
 
@@ -24,5 +26,6 @@ export function useRoute(): Route {
24
  return r
25
  }
26
 
 
27
  export const href = (cat?: string | null, rel?: string | null) =>
28
- !cat ? "#/" : rel ? `#/${cat}/${encodeURIComponent(rel)}` : `#/${cat}`
 
1
  import { useEffect, useState } from "react"
2
+ import { getLang, hashFor, splitHash } from "@/lib/i18n"
3
 
4
  /** Hash routes, because a static Space serves only index.html at the root:
5
  * #/ the landing page
6
  * #/language a category, its first release selected
7
+ * #/language/m2.7
8
+ * each with an optional language suffix first: #/ch, #/ch/language/m2.7, #/en/... (lib/i18n). */
9
  export type Route = { cat: string | null; rel: string | null }
10
 
11
  const parse = (): Route => {
12
+ const [cat, rel] = splitHash().rest.map((s) => decodeURIComponent(s))
13
  return { cat: cat || null, rel: rel || null }
14
  }
15
 
 
26
  return r
27
  }
28
 
29
+ /** A link within the page, in the language on screen. */
30
  export const href = (cat?: string | null, rel?: string | null) =>
31
+ hashFor(getLang(), !cat ? [] : rel ? [cat, encodeURIComponent(rel)] : [cat])