Skip to content

Commit

Permalink
broken links: we should ignore folders when looking for existing file…
Browse files Browse the repository at this point in the history
…s in the build folder
  • Loading branch information
slorber committed Jul 23, 2020
1 parent 336c3e5 commit c84f3f0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/docusaurus/src/server/brokenLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,17 @@ async function filterExistingFileLinks({
allCollectedLinks: Record<string, string[]>;
}): Promise<Record<string, string[]>> {
// not easy to make this async :'(
function linkFileDoesNotExist(link: string): boolean {
function linkFileExists(link: string): boolean {
const filePath = `${outDir}/${removePrefix(link, baseUrl)}`;
const exists = fs.existsSync(filePath);
return !exists;
try {
return fs.statSync(filePath).isFile(); // only consider files
} catch (e) {
return false;
}
}

return mapValues(allCollectedLinks, (links) => {
return links.filter(linkFileDoesNotExist);
return links.filter((link) => !linkFileExists(link));
});
}

Expand Down

0 comments on commit c84f3f0

Please sign in to comment.