Skip to content

Commit 93c1648

Browse files
committed
feat(scripts): contributors 脚本跳过翻译版文档
翻译版文件 frontmatter 有 translatedFrom 字段,这类文件由 AI 产出、不应污染 contributor 统计。 在 parseDocFrontmatter 新增 isTranslation 字段,主循环里 检测到翻译版则打印跳过日志并 continue,不拉 commit 历史、 不写入 doc_contributors 表。 影响:generate-leaderboard.mjs 无需改动(它从 DB 聚合, 源头已过滤),DB schema 不变。
1 parent 4e511ae commit 93c1648

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

scripts/backfill-contributors.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,19 @@ async function listDocFiles() {
165165
.sort((a, b) => a.relative.localeCompare(b.relative));
166166
}
167167

168-
// 解析 frontmatter,取 docId / title
168+
// 解析 frontmatter,取 docId / title / isTranslation
169169
function parseDocFrontmatter(content) {
170170
const parsed = matter(content);
171171
const data = parsed.data || {};
172172
const docId = typeof data.docId === "string" ? data.docId.trim() : "";
173173
const title = typeof data.title === "string" ? data.title.trim() : "";
174+
// 有 translatedFrom 字段即为翻译版,不计入贡献者统计
175+
const isTranslation =
176+
typeof data.translatedFrom === "string" && data.translatedFrom.length > 0;
174177
return {
175178
docId: docId || null,
176179
title: title || null,
180+
isTranslation,
177181
frontmatter: data,
178182
};
179183
}
@@ -485,6 +489,11 @@ async function main() {
485489
log(` ⚠️ 跳过 ${repoRelative}:缺少 docId`);
486490
continue;
487491
}
492+
// 翻译版(frontmatter 有 translatedFrom)不统计贡献者
493+
if (meta.isTranslation) {
494+
log(` ⏭ 跳过翻译版:${repoRelative}`);
495+
continue;
496+
}
488497
const set = currentDocIdPaths.get(meta.docId) ?? new Set();
489498
set.add(repoRelative);
490499
currentDocIdPaths.set(meta.docId, set);

0 commit comments

Comments
 (0)