Skip to content

Commit d58e6b0

Browse files
committed
feat: add metadata
1 parent 05d62a3 commit d58e6b0

Some content is hidden

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

44 files changed

+459
-0
lines changed

metadata.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// 假设 JSON 数据已经保存在一个文件中
5+
const jsonData = require('./swift_docs_structure.json');
6+
7+
// 根目录路径
8+
const rootDir = './swift-6-beta.docc';
9+
10+
// GitHub 仓库的基础 URL
11+
const githubBaseUrl = 'https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc';
12+
13+
// 递归遍历目录
14+
function traverseDirectory(dir) {
15+
const files = fs.readdirSync(dir);
16+
17+
files.forEach(file => {
18+
const fullPath = path.join(dir, file);
19+
const stat = fs.statSync(fullPath);
20+
21+
if (stat.isDirectory()) {
22+
traverseDirectory(fullPath);
23+
} else if (path.extname(file) === '.md') {
24+
processMarkdownFile(fullPath);
25+
}
26+
});
27+
}
28+
29+
// 处理 Markdown 文件
30+
function processMarkdownFile(filePath) {
31+
const relativePath = path.relative(rootDir, filePath);
32+
const fileName = path.basename(filePath, '.md');
33+
34+
// 查找匹配的 URL
35+
let matchingUrl = null;
36+
for (const section in jsonData) {
37+
const match = jsonData[section].find(item => {
38+
const urlParts = item.url.split('/');
39+
const lastPart = urlParts[urlParts.length - 1].toLowerCase();
40+
return lastPart === fileName.toLowerCase() ||
41+
lastPart === fileName.toLowerCase().replace(/[^a-z0-9]/g, '');
42+
});
43+
if (match) {
44+
matchingUrl = match.url;
45+
break;
46+
}
47+
}
48+
49+
if (matchingUrl) {
50+
const content = fs.readFileSync(filePath, 'utf8');
51+
52+
// 检查文件是否已经包含了注释
53+
if (content.includes('要翻译的文件:') && content.includes('Swift 文档源文件地址:')) {
54+
console.log(`Already updated: ${filePath}`);
55+
return;
56+
}
57+
58+
const newContent = `<!--
59+
要翻译的文件:${githubBaseUrl}/${relativePath.replace(/\\/g, '/')}
60+
Swift 文档源文件地址:${matchingUrl}
61+
-->
62+
63+
${content}`;
64+
65+
fs.writeFileSync(filePath, newContent);
66+
console.log(`Updated: ${filePath}`);
67+
} else {
68+
console.log(`No matching URL found for: ${filePath}`);
69+
}
70+
}
71+
72+
// 开始处理
73+
traverseDirectory(rootDir);

swift-6-beta.docc/GuidedTour/AboutSwift.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/GuidedTour/AboutSwift.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/aboutswift
4+
-->
5+
16
# About Swift
27

38
Understand the high-level goals of the language.

swift-6-beta.docc/GuidedTour/Compatibility.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/GuidedTour/Compatibility.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/compatibility
4+
-->
5+
16
# Version Compatibility
27

38
Learn what functionality is available in older language modes.

swift-6-beta.docc/GuidedTour/GuidedTour.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/GuidedTour/GuidedTour.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour
4+
-->
5+
16
# A Swift Tour
27

38
Explore the features and syntax of Swift.

swift-6-beta.docc/LanguageGuide/AccessControl.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/LanguageGuide/AccessControl.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/accesscontrol
4+
-->
5+
16
# Access Control
27

38
Manage the visibility of code by declaration, file, and module.

swift-6-beta.docc/LanguageGuide/AdvancedOperators.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/LanguageGuide/AdvancedOperators.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/advancedoperators
4+
-->
5+
16
# Advanced Operators
27

38
Define custom operators, perform bitwise operations, and use builder syntax.

swift-6-beta.docc/LanguageGuide/AutomaticReferenceCounting.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/LanguageGuide/AutomaticReferenceCounting.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/automaticreferencecounting
4+
-->
5+
16
# Automatic Reference Counting
27

38
Model the lifetime of objects and their relationships.

swift-6-beta.docc/LanguageGuide/BasicOperators.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/LanguageGuide/BasicOperators.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/basicoperators
4+
-->
5+
16
# Basic Operators
27

38
Perform operations like assignment, arithmetic, and comparison.

swift-6-beta.docc/LanguageGuide/ClassesAndStructures.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/LanguageGuide/ClassesAndStructures.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/classesandstructures
4+
-->
5+
16
# Structures and Classes
27

38
Model custom types that encapsulate data.

swift-6-beta.docc/LanguageGuide/Closures.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
要翻译的文件:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese/blob/swift-6-beta-translation/swift-6-beta.docc/LanguageGuide/Closures.md
3+
Swift 文档源文件地址:https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures
4+
-->
5+
16
# Closures
27

38
Group code that executes together, without creating a named function.

0 commit comments

Comments
 (0)