Skip to content

Commit

Permalink
fix: disable doc link checking on 301 status codes from amplify docs …
Browse files Browse the repository at this point in the history
…while we fix the errors (#4750)
  • Loading branch information
thaddmt authored Nov 15, 2023
1 parent 9effe1d commit 2a2735f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docs/scripts/link-checker-puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { checkLink, crawlAllLinks, isInternalLink } from './util';
import type { LinkInfo } from './util';
import {
DEFAULT_GOOD_STATUS_CODES,
DOCS_AMPLIFY_HOST,
PROMISE_POOL_CONCURRENCY,
} from './data/constants';

Expand All @@ -18,7 +19,8 @@ const testPaths = end ? sitePaths.slice(+start, +end) : sitePaths.slice(+start);
function reportResult(links: LinkInfo[]) {
const errorLinks = links.filter((link) => {
const isInternalRedirection =
link.statusCode === 308 && isInternalLink(link.href);
(link.statusCode === 308 && isInternalLink(link.href)) ||
(link.statusCode === 301 && link.href.startsWith(DOCS_AMPLIFY_HOST));
const goodStatusCodes = [0, ...DEFAULT_GOOD_STATUS_CODES];
return !goodStatusCodes.includes(link.statusCode) && !isInternalRedirection;
});
Expand Down
13 changes: 1 addition & 12 deletions docs/scripts/util/checkLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ async function returnStatus({
tagText,
}: LinkInfo): Promise<LinkInfo> {
if ([...DEFAULT_GOOD_STATUS_CODES, 301, 308].includes(statusCode)) {
/**
* If 301 and from 'https://docs.amplify.aws/', add a "/" and check again.
* Because 'https://docs.amplify.aws/' adds a "/" and return a 301 to all the links not ending with "/".
* e.g. https://docs.amplify.aws/lib/auth/getarted/q/platform/js returns 301 but we should catch it as 404.
*/
if (statusCode === 301 && href.startsWith(DOCS_AMPLIFY_HOST)) {
return await checkLink(
{ href: `${href}/`, tagName, tagText, pageIdx, pageUrl },
linkIdx
);
}
/**
* If 308, check if it's an internal redirection to add [platform] prefix. See docs/next.config.js redirects logic.
* If it's an internal redirection to add [platform] prefix, after adding the platform, it should be 200.
Expand Down Expand Up @@ -87,7 +76,7 @@ export async function checkLink(
const linkData = { href, linkIdx, pageIdx, pageUrl, tagName, tagText };
if (!href) {
console.log(
`⚠️[WARNING...] page #${pageIdx} link #${linkIdx} "${tagName}" tag "${tagText}" doesn't have a href.`
`⚠️[WARNING...] page #${pageIdx} link #${linkIdx} "${tagName}" tag "${tagText}" doesn't have a href on ${pageUrl}.`
);
res({ ...linkData, statusCode: 0 });
} else if (
Expand Down

0 comments on commit 2a2735f

Please sign in to comment.