Skip to content

Commit f4cd13b

Browse files
authored
Fix: translator - gulpfile.js (#1479)
1 parent f8f4371 commit f4cd13b

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

src/content/posts/whats-new-in-flutter-3-24.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Flutter GPU 扩展了 Flutter 的直接渲染能力,实现高级图形和 3D
127127

128128
要深入了解 Flutter GPU 并了解如何在项目中利用它,请查看详细的 [Flutter GPU 博客文章](https://medium.com/flutter/getting-started-with-flutter-gpu-f33d497b7c11)。无论你是创建游戏还是复杂图形,Flutter 的新 GPU 功能都使其成为你的产品的强大选择。
129129

130-
## Web
130+
## Web
131131

132132
### 多视图嵌入
133133

@@ -160,7 +160,7 @@ Flutter Web 应用现在可以利用多视图嵌入,允许开发者同时将
160160

161161
资源: [插件指南](https://pub.flutter-io.cn/packages/interactive_media_ads)[示例应用](https://pub.flutter-io.cn/packages/interactive_media_ads/example)[Git 仓库](https://github.com/flutter/packages/tree/main/packages/interactive_media_ads)
162162

163-
## iOS
163+
## iOS
164164

165165
### Swift Package Manager 初步支持
166166

tool/translator/gulpfile.js

+27-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ const replace = require('gulp-replace');
44
// 为了翻译工具能正确匹配,
55
// 需要为一些结构格式做出调整。
66

7+
// 适用路径
8+
const gulpSrc = [
9+
'../../_site/**/*.html',
10+
'../../_site/!(about|community|disclaimer|posts|tutorials)/**/!(*_cn).html',
11+
'!../../_site/{about,disclaimer,posts}/**/*.html',
12+
'!../../_site/community/tutorials/**/*.html',
13+
'../../_site/community/china/index.html',
14+
'../../_site/*/index.html',
15+
'../../_site/index.html',
16+
];
17+
718
// 去掉中文标点与中文间的空格
819
gulp.task('remove-space', () => {
920
return gulp.src(['../../_site/**/*.html'])
@@ -14,23 +25,23 @@ gulp.task('remove-space', () => {
1425
// 匹配替换目录相关格式
1526
gulp.task('mark-side-toc', () => {
1627
// 宽显示屏右侧目录 正则匹配
17-
const wideRegexp = /<li class="toc-entry nav-item toc-h(\d)">\s*<a class="nav-link" href="#(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/a>\s*<\/li>\s*<li class="toc-entry nav-item toc-h(\d)">\s*<a class="nav-link" href="#(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/a>/g;
28+
const wideRegexp = /<li class="toc-entry nav-item toc-h(\d)">\s*<a class="nav-link" href="#(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/a>\s*<\/li>\s*<li class="toc-entry nav-item toc-h\1">\s*<a class="nav-link" href="#(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/a>/g;
1829
// 移动端显示屏顶部目录 正则匹配
19-
const mobileRegexp = /<li class="toc-entry toc-h(\d)">\s*<a href="#(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/a>\s*<\/li>\s*<li class="toc-entry toc-h(\d)">\s*<a href="#(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/a>/g;
30+
const mobileRegexp = /<li class="toc-entry toc-h(\d)">\s*<a href="#(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/a>\s*<\/li>\s*<li class="toc-entry toc-h\1">\s*<a href="#(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/a>/g;
2031

21-
return gulp.src(['../../_site/**/*.html'])
32+
return gulp.src(gulpSrc)
2233
// 宽显示屏右侧目录
2334
.pipe(
24-
replace(wideRegexp, (match, p1, p2, p3, p4, p5, p6) => {
35+
replace(wideRegexp, (match, p1, p2, p3, p4, p5) => {
2536
// 注意:不能以 </li> 结尾,避免分级标题混乱
26-
return `<li class="toc-entry nav-item toc-h${p1}"><a class="nav-link" href="#${p2}"><t>${p3}</t><t>${p6}</t></a>`;
37+
return `<li class="toc-entry nav-item toc-h${p1}"><a class="nav-link" href="#${p2}"><t>${p3}</t><t>${p5}</t></a>`;
2738
})
2839
)
2940
// 移动端显示屏顶部目录
3041
.pipe(
31-
replace(mobileRegexp, (match, p1, p2, p3, p4, p5, p6) => {
42+
replace(mobileRegexp, (match, p1, p2, p3, p4, p5) => {
3243
// 注意:不能以 </li> 结尾,避免分级标题混乱
33-
return `<li class="toc-entry toc-h${p1}"><a href="#${p2}"><t>${p3}</t><t>${p6}</t></a>`;
44+
return `<li class="toc-entry toc-h${p1}"><a href="#${p2}"><t>${p3}</t><t>${p5}</t></a>`;
3445
})
3546
)
3647
.pipe(gulp.dest('../../_site'));
@@ -39,29 +50,29 @@ gulp.task('mark-side-toc', () => {
3950
// 匹配替换正文分级标题相关格式
4051
gulp.task('mark-side-level-title', () => {
4152
// 正文分级标题 正则匹配
42-
const titleRegexp = /<div class="header-wrapper">\s*<h(\d) id="(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/h(\d)>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>\s*<div class="header-wrapper">\s*<h(\d) id="(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/h(\d)>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>/g;
53+
const titleRegexp = /<div class="header-wrapper">\s*<h(\d) id="(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/h\1>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>\s*<div class="header-wrapper">\s*<h\1 id="(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/h\1>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>/g;
4354
// 正文分级标题(no_toc) 正则匹配
44-
const titleNoTocRegexp = /<div class="header-wrapper">\s*<h(\d) class="no_toc" id="(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/h(\d)>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>\s*<div class="header-wrapper">\s*<h(\d) class="no_toc" id="(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/h(\d)>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>/g;
55+
const titleNoTocRegexp = /<div class="header-wrapper">\s*<h(\d) class="no_toc" id="(.*?)">(?!.*[\u4e00-\u9fa5])(.*?)<\/h\1>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>\s*<div class="header-wrapper">\s*<h\1 class="no_toc" id="(.*?)">(?=.*[\u4e00-\u9fa5])(.*?)<\/h\1>\s*<a class="heading-link" href="#(.*?)" aria-label="(.*?)">#<\/a>\s*<\/div>/g;
4556

46-
return gulp.src(['../../_site/**/*.html'])
57+
return gulp.src(gulpSrc)
4758
// 正文分级标题
4859
.pipe(
49-
replace(titleRegexp, (match, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) => {
60+
replace(titleRegexp, (match, p1, p2, p3, p4, p5, p6, p7, p8, p9) => {
5061
return `
5162
<div class="header-wrapper">
52-
<h${p1} id="${p2}">${p3}</h${p1}><h${p1} id="${p2}">${p9}</h${p1}>
53-
<a class="heading-link" href="#${p5}" aria-label="${p6}">#</a>
63+
<h${p1} id="${p2}">${p3}</h${p1}><h${p1} id="${p2}">${p7}</h${p1}>
64+
<a class="heading-link" href="#${p4}" aria-label="${p5}">#</a>
5465
</div>
5566
`;
5667
})
5768
)
5869
// 正文分级标题(no_toc)
5970
.pipe(
60-
replace(titleNoTocRegexp, (match, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12) => {
71+
replace(titleNoTocRegexp, (match, p1, p2, p3, p4, p5, p6, p7, p8, p9) => {
6172
return `
6273
<div class="header-wrapper">
63-
<h${p1} class="no_toc" id="${p2}">${p3}</h${p1}><h${p1} class="no_toc" id="${p2}">${p9}</h${p1}>
64-
<a class="heading-link" href="#${p5}" aria-label="${p6}">#</a>
74+
<h${p1} class="no_toc" id="${p2}">${p3}</h${p1}><h${p1} class="no_toc" id="${p2}">${p7}</h${p1}>
75+
<a class="heading-link" href="#${p4}" aria-label="${p5}">#</a>
6576
</div>
6677
`;
6778
})

0 commit comments

Comments
 (0)