Skip to content

Commit

Permalink
feat: warning message when md links are broken (#1116)
Browse files Browse the repository at this point in the history
feat: show a warning message when md links are broken
  • Loading branch information
gianlucadonato authored and endiliey committed Nov 23, 2018
1 parent 1e83613 commit 711c15d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions v1/lib/server/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,8 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
new RegExp(`\\]\\((\\./)?${mdLink}`, 'g'),
`](${htmlLink}`,
);
} else {
mdBrokenLinks.push(mdLink);
}
});

Expand All @@ -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;
}

Expand Down

0 comments on commit 711c15d

Please sign in to comment.