Skip to content

Commit 55998fc

Browse files
committed
[Docs] Update API link crawler
1 parent f9b3122 commit 55998fc

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

bin/crawl-api-links.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ async function checkLinks() {
2121
});
2222
const page = await browser.newPage();
2323

24+
// skip image requests
25+
await page.setRequestInterception(true);
26+
page.on("request", (request) => {
27+
if (request.resourceType() === "image") request.abort();
28+
else request.continue();
29+
});
30+
2431
const sitemapUrl = "https://developers.cloudflare.com/sitemap.xml";
2532
await page.goto(sitemapUrl, { timeout: navigationTimeout });
2633

@@ -51,22 +58,17 @@ async function checkLinks() {
5158
}
5259

5360
if (
54-
pageLink.includes("developers.cloudflare.com/api/operations/") ||
55-
pageLink.startsWith("/api/operations/")
61+
pageLink.includes("developers.cloudflare.com/api/resources/") ||
62+
pageLink.startsWith("/api/resources/")
5663
) {
5764
console.log(`Evaluating link: ${pageLink}`);
58-
await page.goto(pageLink, {
65+
const response = await page.goto(pageLink, {
5966
waitUntil: "networkidle0",
6067
timeout: navigationTimeout,
6168
});
6269
visitedLinks.push(pageLink);
6370

64-
const statusCode = await page.evaluate(() => {
65-
return {
66-
url: window.location.href,
67-
};
68-
});
69-
if (statusCode.url === "https://developers.cloudflare.com/api/") {
71+
if (response.status() === 404) {
7072
brokenLinks.push(pageLink);
7173
}
7274
}

0 commit comments

Comments
 (0)