Commit e74b5fd
refactor(i18n): URL 段化让 docs 全量 SSG,砍 Vercel Fluid CPU 50%+ (#330)
* refactor: i18n URL 段化(/zh/...、/en/...)让 docs 全量 SSG,砍 Vercel Fluid CPU
主因:next-intl 原方案用 cookie + RSC 切语言(i18n/request.ts 调 cookies()),
让全站 RSC 树都被钉成 dynamic,318 篇 docs 每次访问现 SSR 一次,30 天 Vercel
Fluid Active CPU 月用量逼近 4h(Hobby 上限)。
改造:
1. next-intl 切到 URL routing
- i18n/routing.ts (defineRouting) localePrefix: always
- i18n/navigation.ts (createNavigation 出 Link/router/redirect)
- i18n/request.ts 从 requestLocale 读 locale,不再 await cookies()
2. 路由重排
- 17 个 user-facing page + admin 全部移到 app/[locale]/...
- app/api/* / app/sitemap.ts / app/robots.ts 保留在根
- app/layout.tsx 极简化(不读 cookies;只剩 html/body + 全局 metadata
+ theme inline script + structured data + analytics)
- app/[locale]/layout.tsx 调 setRequestLocale + 包所有 provider
(NextIntlClientProvider / ThemeProvider / AuthProvider / fumadocs
RootProvider)
3. fumadocs i18n
- lib/source.ts defineI18n: zh/en, dot parser, fallbackLanguage zh
- mdx 内容从 app/docs 拆到 content/docs(路由文件 / 内容分离,符合
fumadocs 推荐)
- normalize 8 对 conflict(无后缀=英文 + .zh.mdx=中文翻译 swap 成
无后缀=zh、.en.mdx=英文翻译,单一规则)
- app/[locale]/docs/[...slug]/page.tsx 用 source.getPage(slug, locale)
+ setRequestLocale + force-static
- SectionIndex 简化(删手写翻译版剪枝,靠 fumadocs i18n 的 pageTree
按 locale 隔离)
4. SEO + 切换
- LocaleToggle 改 next-intl router.replace + locale prefix
- sitemap.ts 输出双语 entry + alternates.languages(hreflang 自动)
- robots.ts disallow 用 wildcard 匹配两种语言
- canonical / hreflang 在 docs page generateMetadata 重新生成
5. proxy 合并 (Next.js 16 用 proxy.ts 不是 middleware.ts)
- 删掉旧 IP geo + Accept-Language + cookie 写入逻辑(next-intl
createMiddleware 原生支持)
- 老 leetcode 中文 slug 301 redirect 保留,先于 i18n middleware 跑
6. 路径统一
- DOCS_BASE / contributors normalize / api/chat fs.readFile / scripts
全部 app/docs → content/docs
预期:
- /[locale]/docs/[...slug] 从 ƒ Dynamic 变 ● SSG,build 时 322 静态页面
预渲染
- Vercel Fluid CPU docs 这块归零(占当前 50%)
- 首页 / events / feed 等仍 ƒ(fetchHomepageEvents 等 server fetch 阻挡,
下一轮单独 PR 处理)
验证:
- pnpm exec tsc --noEmit: 0 错误
- pnpm build: 通过
- .next/prerender-manifest.json: 322 routes prerendered
* docs(dev): 补 i18n URL 段化架构说明 + content/ 目录 README
dev_docs/i18n_url_routing.md(217 行):
- 为什么从 cookie 切到 URL 段(CPU 死结的来龙去脉)
- 文件分工:i18n/ + proxy.ts + app/[locale]/ + content/docs/
- SSG 开关:每个 page/layout 必须 setRequestLocale + docs 加 force-static
- 文档命名约定(dot parser 规则 + 加新文章 / 缺译 fallback)
- 切换语言流程 + SEO(hreflang / canonical / sitemap / robots)
- proxy 流程图 + 调试 5 类常见问题("为什么 page 还是 ƒ")
- 已知未做的下一轮工作清单(首页 SSG 等)
content/README.md:
- 说明 content/docs 是 fumadocs mdx 内容根(与 app/ 路由分离)
- 命名约定快速版(避免新人放 .zh.mdx 触发 build 冲突)
- 历史:2026-05 从 app/docs 拆出
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>1 parent d9f77b8 commit e74b5fd
489 files changed
Lines changed: 1046 additions & 859 deletions
File tree
- app
- [locale]
- admin
- community
- database
- events
- [id]/edit
- new
- users
- docs
- [...slug]
- editor
- events
- [id]
- feed
- components
- submit
- login
- rank
- settings
- u/[username]
- edit
- api/chat
- components
- docs
- docs
- content
- docs
- career
- events
- interview-prep
- leetcode
- community
- dev-tips
- CommonUsedMarkdown.assets
- Katex
- language
- life
- mental-health
- papers
- tools
- learn
- ai
- Introduction-of-Multi-agents-system
- MoE
- MOE-intro.assets
- Multi-agents-system-on-Code-Translation
- agents-todo
- cs294-194-196
- ai-math-basics
- calculus-optimization
- information-theory
- linear-algebra
- resources
- numerical-analysis
- probability-statistics
- resources
- compute-platforms
- foundation-models
- datasets
- deploy-infer
- evaluation
- finetune
- qkv-interview
- rag
- training
- generative-todo
- llm-basics
- courses
- cuda
- deep-learning
- d2l
- misc
- nlp
- embeddings
- qwen3-embedding
- pytorch
- index.assets
- transformer
- ai-by-hand
- methodology
- misc-tools
- model-datasets-platforms
- multimodal
- RQVAE
- index.assets
- VAE
- index.assets
- VQVAE
- index.assets
- courses
- llava
- index.assets
- mllm
- qwenvl
- video-mm-todo
- vit
- recommender-systems
- wangshusen_recommend_note
- images
- wangshusen_recommend_note_retrieval.assets
- reinforcement-learning
- cs
- cpp-backend
- easy-compile
- handwritten-pool-components
- data-structures
- array
- linked-list
- frontend
- frontend-learning
- projects
- dev_docs
- i18n
- lib
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
File renamed without changes.
File renamed without changes.
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
File renamed without changes.
0 commit comments