mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-14 01:27:35 +02:00
feat: warning message when md links are broken (#1116)
feat: show a warning message when md links are broken
This commit is contained in:
parent
1e8361392c
commit
711c15d3e3
1 changed files with 12 additions and 0 deletions
|
@ -49,6 +49,7 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
|
||||||
let content = oldContent;
|
let content = oldContent;
|
||||||
const mdLinks = [];
|
const mdLinks = [];
|
||||||
const mdReferences = [];
|
const mdReferences = [];
|
||||||
|
const mdBrokenLinks = [];
|
||||||
|
|
||||||
// find any inline-style links to markdown files
|
// find any inline-style links to markdown files
|
||||||
const linkRegex = /(?:\]\()(?:\.\/)?([^'")\]\s>]+\.md)/g;
|
const linkRegex = /(?:\]\()(?:\.\/)?([^'")\]\s>]+\.md)/g;
|
||||||
|
@ -81,6 +82,8 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
|
||||||
new RegExp(`\\]\\((\\./)?${mdLink}`, 'g'),
|
new RegExp(`\\]\\((\\./)?${mdLink}`, 'g'),
|
||||||
`](${htmlLink}`,
|
`](${htmlLink}`,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
mdBrokenLinks.push(mdLink);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -100,8 +103,17 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
|
||||||
new RegExp(`\\]:(?:\\s)?(\\./|\\.\\./)?${refLink}`, 'g'),
|
new RegExp(`\\]:(?:\\s)?(\\./|\\.\\./)?${refLink}`, 'g'),
|
||||||
`]: ${htmlLink}`,
|
`]: ${htmlLink}`,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
mdBrokenLinks.push(refLink);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (mdBrokenLinks.length) {
|
||||||
|
console.log(
|
||||||
|
`[WARN] unresolved links in file '${metadata.source}' >`,
|
||||||
|
mdBrokenLinks,
|
||||||
|
);
|
||||||
|
}
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue