feat: warning message when md links are broken (#1116)

feat: show a warning message when md links are broken
This commit is contained in:
Gianluca Donato 2018-11-23 15:43:12 +01:00 committed by Endilie Yacop Sucipto
parent 1e8361392c
commit 711c15d3e3

View file

@ -49,6 +49,7 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
let content = oldContent;
const mdLinks = [];
const mdReferences = [];
const mdBrokenLinks = [];
// find any inline-style links to markdown files
const linkRegex = /(?:\]\()(?:\.\/)?([^'")\]\s>]+\.md)/g;
@ -81,6 +82,8 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
new RegExp(`\\]\\((\\./)?${mdLink}`, 'g'),
`](${htmlLink}`,
);
} else {
mdBrokenLinks.push(mdLink);
}
});
@ -100,8 +103,17 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
new RegExp(`\\]:(?:\\s)?(\\./|\\.\\./)?${refLink}`, 'g'),
`]: ${htmlLink}`,
);
} else {
mdBrokenLinks.push(refLink);
}
});
if (mdBrokenLinks.length) {
console.log(
`[WARN] unresolved links in file '${metadata.source}' >`,
mdBrokenLinks,
);
}
return content;
}