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

update link checker to wait for each call to complete before making t… #6993

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions tasks/link-checker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const puppeteer = require('puppeteer');
const axios = require('axios');
const puppeteer = require('puppeteer'); // eslint-disable-line
const axios = require('axios'); // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ESLint mad about the require here?


const SITEMAP_URL = 'https://docs.amplify.aws/sitemap.xml';
const DOMAIN = 'https://docs.amplify.aws';
Expand Down Expand Up @@ -62,7 +62,6 @@ const retrieveLinks = async (siteMapUrls, visitedLinks, localDomain) => {
let response = await page.goto(url, { waitUntil: 'domcontentloaded' });
await new Promise((r) => setTimeout(r, 100)); // localhost hangs on wait for idle so use a short timeout instead
if (response && response.status() && response.status() === 200) {
console.log(`successfully visited ${url} to retrieve links`);
visitedLinks[url] = true;

const urlList = await page.evaluate(async (url) => {
Expand All @@ -82,6 +81,10 @@ const retrieveLinks = async (siteMapUrls, visitedLinks, localDomain) => {
return urls;
}, url);

console.log(
`successfully visited ${url} to retrieve links ${urlList.length} links found`
);
reesscot marked this conversation as resolved.
Show resolved Hide resolved

urlList.forEach((link) => {
if (
!CRAWLER_EXCEPTIONS.includes(link.url) &&
Expand Down Expand Up @@ -128,11 +131,9 @@ const linkChecker = async (localDomain) => {
localDomain
);

let allPromises = [];

for (let i = 0; i < urlsToVisit.length; i++) {
const link = urlsToVisit[i];
let href = link.url;
let href = link.url.split('#')[0];
if (href.startsWith(GITHUB_CREATE_ISSUE_LINK)) {
// remove query parameters from github new issue links
href = href.split('?')[0];
Expand Down Expand Up @@ -163,11 +164,9 @@ const linkChecker = async (localDomain) => {
}
});

allPromises.push(request);
await request;
}

await Promise.all(allPromises);

console.log(statusCodes);
console.log(brokenLinks);

Expand Down
Loading