Skip to content

Commit 30a3f6a

Browse files
committed
Report broken links on compilation
1 parent 7bbed36 commit 30a3f6a

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

compile-markdown.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,23 @@ let mainHtml = await marked.parse(readFile(input), {
7676
return;
7777
}
7878

79-
// Relative link to markdown; remove extension.
79+
// Relative link to markdown.
8080
if (/(\.md$)|(\.md(?=#))/.test(token.href)) {
81+
// Remove extension.
8182
token.href = token.href.replace(/(\.md$)|(\.md(?=#))/, "");
83+
84+
// Validate existence.
85+
let file = `src/submodules/${repo}/${prefix}`;
86+
87+
file += path.dirname(target) + "/";
88+
file += token.href.replace(/#.*$/, "") + ".md";
89+
90+
if (!fs.existsSync(file)) {
91+
console.warn(
92+
`${input}: broken link to file '${file}'`
93+
);
94+
}
95+
8296
return;
8397
}
8498

0 commit comments

Comments
 (0)