Skip to content

Commit 754a16c

Browse files
authored
Update update_links.js
1 parent 10a2c5f commit 754a16c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/update_links.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
const fs = require("fs");
22
const path = require("path");
33

4-
// 获取项目根目录(GitHub Actions 中可用 GITHUB_WORKSPACE
4+
// 项目根目录(本地或 GitHub Actions 都可用
55
const projectRoot = process.env.GITHUB_WORKSPACE || path.resolve(__dirname, "../");
66
const scriptingDir = projectRoot;
77
const readmePath = path.join(projectRoot, "README.md");
88

99
let collectedLinks = [];
1010

11-
// 遍历目录,收集 .scripting 文件
11+
// 遍历目录(递归收集 .scripting 文件
1212
function walkDir(dir, callback) {
1313
fs.readdirSync(dir).forEach((file) => {
1414
const filepath = path.join(dir, file);
1515
const stat = fs.statSync(filepath);
1616
if (stat.isFile() && filepath.endsWith(".scripting")) {
1717
callback(filepath);
1818
} else if (stat.isDirectory()) {
19-
walkDir(filepath, callback); // 递归子目录
19+
walkDir(filepath, callback);
2020
}
2121
});
2222
}
2323

2424
// 生成 scripting.fun 链接
2525
function generateScriptLink(filename) {
2626
const baseUrl = "https://github.com/ScriptingApp/Community-Scripts/raw/refs/heads/main/";
27-
const relativePath = path.relative(scriptingDir, filename).replace(/\\/g, "/"); // 保留目录结构
27+
const relativePath = path.relative(scriptingDir, filename).replace(/\\/g, "/");
2828
const fullUrl = baseUrl + encodeURIComponent(relativePath);
2929
const name = path.basename(filename, ".scripting"); // 去掉后缀
3030
const link = `https://scripting.fun/import_scripts?urls=${encodeURIComponent(`[\"${fullUrl}\"]`)}`;
@@ -41,7 +41,7 @@ let readmeContent = fs.existsSync(readmePath) ? fs.readFileSync(readmePath, "utf
4141
const startTag = "<!-- SCRIPTS_LINKS_START -->";
4242
const endTag = "<!-- SCRIPTS_LINKS_END -->";
4343

44-
// Markdown 列表 + 时间戳保证内容每次都变
44+
// Markdown 列表 + 时间戳保证每次文件内容变化
4545
const linksMarkdown = collectedLinks.map(({ name, link }) => `- [${name}](${link})`).join("\n");
4646
const replacement = `${startTag}\n${linksMarkdown}\n<!-- updated at ${new Date().toISOString()} -->\n${endTag}`;
4747

@@ -52,6 +52,6 @@ if (readmeContent.includes(startTag)) {
5252
readmeContent += `\n\n${replacement}\n`;
5353
}
5454

55-
// 写入 README.md,GitHub Actions workflow 会提交
55+
// 写入 README.md,workflow 会自动提交
5656
fs.writeFileSync(readmePath, readmeContent, "utf-8");
5757
console.log("README.md updated with latest links.");

0 commit comments

Comments
 (0)