fix(core): remove hash/query when filtering existing files for broken link check (#6812)

* fix(core): remove hash/query when filtering existing files for broken link check

* fix tests
This commit is contained in:
Joshua Chen 2022-03-02 12:46:38 +08:00 committed by GitHub
parent ea8590f80b
commit 954e4d42fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 20 deletions

View File

@ -153,6 +153,7 @@ describe('brokenLinks', () => {
const linkToJavadoc1 = '/javadoc';
const linkToJavadoc2 = '/javadoc/';
const linkToJavadoc3 = '/javadoc/index.html';
const linkToJavadoc4 = '/javadoc/index.html#foo';
const linkToZipFile = '/files/file.zip';
const linkToHtmlFile1 = '/files/hey.html';
@ -168,6 +169,7 @@ describe('brokenLinks', () => {
linkToJavadoc1,
linkToHtmlFile2,
linkToJavadoc3,
linkToJavadoc4,
linkToEmptyFolder1,
],
'/page2': [

View File

@ -21,6 +21,7 @@ import {
import {getAllFinalRoutes} from './utils';
import path from 'path';
import combinePromises from 'combine-promises';
import logger from '@docusaurus/logger';
function toReactRouterRoutes(routes: RouteConfig[]): RRRouteConfig[] {
// @ts-expect-error: types incompatible???
@ -111,9 +112,11 @@ export function getBrokenLinksErrorMessage(
pagePath: string,
brokenLinks: BrokenLink[],
): string {
return `\n- On source page path = ${pagePath}:\n -> linking to ${brokenLinks
.map(brokenLinkMessage)
.join('\n -> linking to ')}`;
return `
- On source page path = ${pagePath}:
-> linking to ${brokenLinks
.map(brokenLinkMessage)
.join('\n -> linking to ')}`;
}
/**
@ -141,22 +144,27 @@ export function getBrokenLinksErrorMessage(
return '';
}
return `\n\nIt looks like some of the broken links we found appear in many pages of your site.\nMaybe those broken links appear on all pages through your site layout?\nWe recommend that you check your theme configuration for such links (particularly, theme navbar and footer).\nFrequent broken links are linking to:\n- ${frequentLinks.join(
`\n- `,
)}\n`;
return logger.interpolate`
It looks like some of the broken links we found appear in many pages of your site.
Maybe those broken links appear on all pages through your site layout?
We recommend that you check your theme configuration for such links (particularly, theme navbar and footer).
Frequent broken links are linking to:${frequentLinks}
`;
}
return (
`Docusaurus found broken links!\n\nPlease check the pages of your site in the list below, and make sure you don't reference any path that does not exist.\nNote: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.${getLayoutBrokenLinksHelpMessage()}` +
`\n\nExhaustive list of all broken links found:\n${Object.entries(
allBrokenLinks,
)
.map(([pagePath, brokenLinks]) =>
pageBrokenLinksMessage(pagePath, brokenLinks),
)
.join('\n')}
`
);
return `Docusaurus found broken links!
Please check the pages of your site in the list below, and make sure you don't reference any path that does not exist.
Note: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.${getLayoutBrokenLinksHelpMessage()}
Exhaustive list of all broken links found:
${Object.entries(allBrokenLinks)
.map(([pagePath, brokenLinks]) =>
pageBrokenLinksMessage(pagePath, brokenLinks),
)
.join('\n')}
`;
}
async function isExistingFile(filePath: string) {
@ -180,9 +188,8 @@ export async function filterExistingFileLinks({
}): Promise<Record<string, string[]>> {
async function linkFileExists(link: string) {
// /baseUrl/javadoc/ -> /outDir/javadoc
const baseFilePath = removeSuffix(
`${outDir}/${removePrefix(link, baseUrl)}`,
'/',
const baseFilePath = onlyPathname(
removeSuffix(`${outDir}/${removePrefix(link, baseUrl)}`, '/'),
);
// -> /outDir/javadoc