Skip to content

Commit 46d905e

Browse files
authored
site: normalize locale-aware links in Chinese docs (#59277)
1 parent c7f4441 commit 46d905e

97 files changed

Lines changed: 320 additions & 289 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.dumi/theme/plugins/raw-md.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,34 @@ function replacePrettierIgnore(md: string) {
135135
return md.replace(/<!--\s*prettier-ignore\s*-->\s*\n?/g, '');
136136
}
137137

138+
/**
139+
* 为中文原始 Markdown 中的站内链接补充语言后缀。
140+
* 网页中的链接由 LocaleLink 处理,原始 Markdown 则需要在构建时显式指定中文路由。
141+
*/
142+
function replaceLocaleLinks(md: string, context: ContentFilterContext) {
143+
if (detectDocLocale(context.file) !== 'zh-CN') {
144+
return md;
145+
}
146+
147+
return md.replace(/(?<!!)(\[[^\]\n]+\]\(\s*)(\/[^)\s]*)/g, (link, prefix, url) => {
148+
const suffixIndex = url.search(/[?#]/);
149+
const pathname = suffixIndex === -1 ? url : url.slice(0, suffixIndex);
150+
const suffix = suffixIndex === -1 ? '' : url.slice(suffixIndex);
151+
const trailingSlash = pathname.endsWith('/');
152+
const basePath = trailingSlash ? pathname.slice(0, -1) : pathname;
153+
154+
if (!basePath) {
155+
return `${prefix}/index-cn${suffix}`;
156+
}
157+
158+
if (basePath.endsWith('-cn')) {
159+
return link;
160+
}
161+
162+
return `${prefix}${basePath}-cn${trailingSlash ? '/' : ''}${suffix}`;
163+
});
164+
}
165+
138166
/**
139167
* 替换 markdown 中的 "Semantic DOM" 部分的 code 标签为指向生成的 semantic.md 文件的链接
140168
*
@@ -570,6 +598,9 @@ function emitRawMd(api: IApi) {
570598
content = replaceCodeSrcToMarkdown(content, file, PLUGIN_OPTIONS.codeAppend);
571599
}
572600

601+
// 5. 为中文原始 Markdown 中的站内链接补充语言后缀
602+
content = replaceLocaleLinks(content, filterContext);
603+
573604
const outMd = path.join(outRoot, `${relPath}.md`);
574605
fs.mkdirSync(path.dirname(outMd), { recursive: true });
575606
fs.writeFileSync(outMd, content, 'utf-8');

‎components/affix/index.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ group:
3434

3535
通用属性参考:[通用属性](/docs/react/common-props)
3636

37-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
37+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
3838
| --- | --- | --- | --- | --- | --- |
3939
| offsetBottom | 距离窗口底部达到指定偏移量后触发 | number | - | | × |
4040
| offsetTop | 距离窗口顶部达到指定偏移量后触发 | number | 0 | | × |

‎components/alert/index.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ group:
4040

4141
通用属性参考:[通用属性](/docs/react/common-props)
4242

43-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
43+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
4444
| --- | --- | --- | --- | --- | --- |
4545
| action | 自定义操作项 | ReactNode | - | | × |
4646
| ~~afterClose~~ | 关闭动画结束后触发的回调函数,请使用 `closable.afterClose` 替换 | () => void | - | | × |

‎components/anchor/index.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ group:
4141

4242
### Anchor Props
4343

44-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
44+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
4545
| --- | --- | --- | --- | --- | --- |
4646
| affix | 固定模式 | boolean \| Omit<AffixProps, 'offsetTop' \| 'target' \| 'children'> | true | object: 5.19.0 | × |
4747
| bounds | 锚点区域边界 | number | 5 | | × |

‎components/app/index.zh-CN.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ export default () => {
129129
130130
### App
131131

132-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
132+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
133133
| --- | --- | --- | --- | --- | --- |
134134
| component | 设置渲染元素,为 `false` 则不创建 DOM 节点 | ComponentType \| false | div | 5.11.0 | × |
135-
| message | App 内 Message 的全局配置 | [MessageConfig](/components/message-cn/#messageconfig) | - | 5.3.0 | × |
136-
| notification | App 内 Notification 的全局配置 | [NotificationConfig](/components/notification-cn/#notificationconfig) | - | 5.3.0 | × |
135+
| message | App 内 Message 的全局配置 | [MessageConfig](/components/message/#messageconfig) | - | 5.3.0 | × |
136+
| notification | App 内 Notification 的全局配置 | [NotificationConfig](/components/notification/#notificationconfig) | - | 5.3.0 | × |
137137

138138
## 主题变量(Design Token){#design-token}
139139

‎components/avatar/index.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ group:
3636

3737
### Avatar
3838

39-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
39+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
4040
| --- | --- | --- | --- | --- | --- |
4141
| alt | 图像无法显示时的替代文本 | string | - | | × |
4242
| gap | 字符类型距离左右两侧边界单位像素 | number | 4 | 4.3.0 | × |

‎components/badge/index.zh-CN.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ group: 数据展示
4141

4242
### Badge
4343

44-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
44+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
4545
| --- | --- | --- | --- | --- | --- |
4646
| color | 自定义小圆点的颜色 | string | - | | × |
4747
| count | 展示的数字,大于 overflowCount 时显示为 `${overflowCount}+`,为 0 时隐藏 | ReactNode | - | | × |
@@ -58,7 +58,7 @@ group: 数据展示
5858

5959
### Badge.Ribbon
6060

61-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
61+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
6262
| --- | --- | --- | --- | --- | --- |
6363
| classNames | 用于自定义组件内部各语义化结构的 class,支持对象或函数 | Record<[SemanticDOM](#semantic-dom), string> \| (info: { props })=> Record<[SemanticDOM](#semantic-dom), string> | - | | 6.0.0 |
6464
| color | 自定义缎带的颜色 | string | - | | × |

‎components/border-beam/index.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tag: 6.4.0
3737

3838
### BorderBeam
3939

40-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
40+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
4141
| --- | --- | --- | --- | --- | --- |
4242
| children | 装饰内容 | `ReactNode` | - | 6.4.0 | × |
4343
| color | 流光颜色配置,支持单色字符串或渐变停靠点数组。`percent` 使用 `0 ~ 100` 的输入区间,组件会在内部为尾部透明过渡预留空间 | `string \| { color: string; percent: number }[]` | - | 6.4.0 | × |

‎components/breadcrumb/index.zh-CN.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ demo:
3535

3636
### Breadcrumb
3737

38-
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
38+
| 参数 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
3939
| --- | --- | --- | --- | --- | --- |
4040
| classNames | 用于自定义组件内部各语义化结构的 class,支持对象或函数 | Record<[SemanticDOM](#semantic-dom), string> \| (info: { props })=> Record<[SemanticDOM](#semantic-dom), string> | - | 6.0.0 | 6.0.0 |
4141
| dropdownIcon | 自定义下拉图标 | ReactNode | `<DownOutlined />` | 6.2.0 | 6.2.0 |
@@ -54,10 +54,10 @@ demo:
5454
| 参数 | 说明 | 类型 | 默认值 | 版本 |
5555
| --- | --- | --- | --- | --- |
5656
| className | 自定义类名 | string | - | |
57-
| dropdownProps | 弹出下拉菜单的自定义配置 | [Dropdown](/components/dropdown-cn) | - | |
57+
| dropdownProps | 弹出下拉菜单的自定义配置 | [Dropdown](/components/dropdown) | - | |
5858
| href | 链接的目的地,不能和 `path` 共用 | string | - | |
5959
| path | 拼接路径,每一层都会拼接前一个 `path` 信息。不能和 `href` 共用 | string | - | |
60-
| menu | 菜单配置项 | [MenuProps](/components/menu-cn/#api) | - | 4.24.0 |
60+
| menu | 菜单配置项 | [MenuProps](/components/menu/#api) | - | 4.24.0 |
6161
| onClick | 单击事件 | (e:MouseEvent) => void | - | |
6262
| title | 名称 | ReactNode | - | 5.3.0 |
6363

‎components/button/index.zh-CN.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ group:
6666

6767
按钮的属性说明如下:
6868

69-
| 属性 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider-cn#component-config) |
69+
| 属性 | 说明 | 类型 | 默认值 | 版本 | [全局配置](/components/config-provider#component-config) |
7070
| --- | --- | --- | --- | --- | --- |
7171
| autoInsertSpace | 我们默认提供两个汉字之间的空格,可以设置 `autoInsertSpace` 为 `false` 关闭 | boolean | `true` | 5.17.0 | 5.17.0 |
7272
| block | 将按钮宽度调整为其父宽度的选项 | boolean | false | | × |
@@ -125,7 +125,7 @@ group:
125125

126126
### 如何关闭点击波纹效果? {#faq-close-wave-effect}
127127

128-
如果你不需要这个特性,可以设置 [ConfigProvider](/components/config-provider-cn#api) 的 `wave` 的 `disabled` 为 `true`。
128+
如果你不需要这个特性,可以设置 [ConfigProvider](/components/config-provider#api) 的 `wave` 的 `disabled` 为 `true`。
129129

130130
```jsx
131131
<ConfigProvider wave={{ disabled: true }}>

0 commit comments

Comments
 (0)