MCPcopy
hub / github.com/byoungd/up / checkLinksInFile

Function checkLinksInFile

scripts/check-content.mjs:74–100  ·  view source on GitHub ↗

逐文件提取链接,跳过围栏代码块,校验本地目标是否存在。

(file)

Source from the content-addressed store, hash-verified

72
73/** 逐文件提取链接,跳过围栏代码块,校验本地目标是否存在。 */
74function checkLinksInFile(file) {
75 const text = readFileSync(file, "utf8");
76 const lines = text.split("\n");
77 let inFence = false;
78 lines.forEach((line, i) => {
79 const fenceMatch = line.match(/^\s*(```|~~~)/);
80 if (fenceMatch) {
81 inFence = !inFence;
82 return;
83 }
84 if (inFence) return;
85
86 const targets = [];
87 let m;
88 MD_LINK_RE.lastIndex = 0;
89 while ((m = MD_LINK_RE.exec(line))) targets.push(m[1]);
90 HREF_RE.lastIndex = 0;
91 while ((m = HREF_RE.exec(line))) targets.push(m[1]);
92
93 for (const raw of targets) {
94 const resolved = resolveTarget(file, raw);
95 if (resolved && !existsSync(resolved)) {
96 addError(file, i + 1, `链接目标不存在: ${raw} -> ${relative(ROOT, resolved)}`);
97 }
98 }
99 });
100}
101
102/** 提取一个 SUMMARY 文件里引用的内容文件(.md),归一化为 repo 根相对路径。 */
103function summaryTargets(file, prefix) {

Callers 1

check-content.mjsFile · 0.85

Calls 2

resolveTargetFunction · 0.85
addErrorFunction · 0.85

Tested by

no test coverage detected