Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -168,6 +169,7 @@ describe('brokenLinks', () => {
linkToJavadoc1,
linkToHtmlFile2,
linkToJavadoc3,
linkToJavadoc4,
linkToEmptyFolder1,
],
'/page2': [
Expand Down
47 changes: 27 additions & 20 deletions packages/docusaurus/src/server/brokenLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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???
Expand Down Expand Up @@ -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 ')}`;
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down