Skip to content

feat(mirror-redirect): 收敛主站与 x 站的镜像通道判定为 createMirrorRedirect - #2

Open
cc-hearts wants to merge 2 commits into
mainfrom
feat/mirror-redirect
Open

feat(mirror-redirect): 收敛主站与 x 站的镜像通道判定为 createMirrorRedirect#2
cc-hearts wants to merge 2 commits into
mainfrom
feat/mirror-redirect

Conversation

@cc-hearts

Copy link
Copy Markdown
Member

🤔 本次变更属于 ...

  • 🆕 新功能
  • 🐞 Bug 修复
  • 📝 站点 / 文档改进
  • 📽️ Demo 改进
  • 💄 组件样式改进
  • 🤖 TypeScript 类型定义改进
  • 📦 包体积优化
  • ⚡️ 性能优化
  • ⭐️ 功能增强
  • 🌐 国际化
  • 🛠 重构
  • 🎨 代码风格优化
  • ✅ 测试用例
  • 🔀 分支合并
  • ⏩ 工作流
  • ⌨️ 无障碍改进
  • ❓ 其他(请说明)

🔗 相关 Issue

无(由 docs-plugins 仓库内讨论直接提出)。

💡 背景与方案

antdv-next 主站(docs/src/utils/geo-redirect.ts,约 324 行)与 x 站(packages/docs/src/utils/geo-redirect.ts,约 149 行)各自维护一份"国内访问 → .cn 镜像站"的判定逻辑,后续加固只发生在主站一侧(本地信号打分、GeoIP 回退、可达性探测、偏好记忆、调试 / 豁免开关等),两份实现逐渐分叉。

本 PR 将判定逻辑收敛为按站点配置实例化的单一实现,两站差异只由配置表达:

import { createMirrorRedirect } from '@antdv-next/docs-plugins'

// antdv-next 主站形态
const mirror = createMirrorRedirect({
  mainHosts: ['antdv-next.com', 'www.antdv-next.com'],
  mirrorOrigin: 'https://www.antdv-next.cn',
  probeUrl: 'https://www.antdv-next.cn/antdv-next.png',
  debugValue: 'antdv-next',
})

// x 站形态:换域名、路由一致用 pathname: 'same'、沿用自身 GeoIP 回退链
  • 新增导出:createMirrorRedirectMirrorRedirectOptions / MirrorRedirect / MirrorRedirectDecision / MirrorRedirectPreference / HostnameMatcher / GeoIpApi
  • 选项默认值与主站加固版一致:本地信号打分(语言 / 时区 / -cn 路径,港/澳/台否决)、rejected 30 天 TTL、GeoIP 回退链、提示 / 跳转前 probeUrl 可达性探测(可选)、?cn-redirect=off 单次豁免、localStorage.DEBUG 调试开关、兼容旧版纯字符串偏好
  • 路径映射支持 'cn-suffix'//index-cn,同主站 toCnPathname 语义)、'same'(同 x 站)与自定义函数
  • mirror.isMirrorHost(hostname):判断主机是否属于镜像站部署(如仅在 .cn 镜像站展示 ICP 备案),默认由 mirrorOrigin 推导匹配规则
  • README 补充「国内镜像通道」章节

站点侧接入时删除各自 utils/geo-redirect.ts,改为配置实例化并保留各自弹窗 / 文案(两个站点弹窗方式不同:Modal.useModaluseAppContext),行为差异收敛为配置差异。

📝 变更日志

语言 变更日志
🇺🇸 英文 Add createMirrorRedirect: a single configurable implementation for detecting mainland-China visitors and switching them to the .cn mirror site — local signal scoring, GeoIP fallback chain, cn-site reachability probe, preference memory with TTL, debug and opt-out switches — plus isMirrorHost for mirror-host matching.
🇨🇳 中文 新增 createMirrorRedirect:将"国内访问 → .cn 镜像站"的判定与跳转收敛为按站点配置实例化的单一实现(语言 / 时区 / 路径本地信号打分、GeoIP 回退链、镜像站可达性探测、偏好记忆与 TTL、调试与豁免开关),并新增 isMirrorHost 用于镜像站部署判断(如 ICP 备案展示)。

…rorRedirect

antdv-next site and x site each maintained their own geo-redirect logic and
diverged after only one side was hardened. Add a configurable single
implementation: local signal scoring, GeoIP fallback chain, cn-site
reachability probe, preference memory with TTL, debug/opt-out switches,
plus isMirrorHost for mirror-host matching (ICP footer).
@cc-hearts
cc-hearts force-pushed the feat/mirror-redirect branch from 4726e2a to 11e0c6b Compare September 7, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant