Skip to content

Commit 8ccb6d7

Browse files
authored
[Docs Site] Fixes all Astro TypeScript issues (#16457)
* fix: many many typescript issues chore: bump dependencies * fix: assign-pr script when no codeowners found * fix: ExternalResources TS * fix: check all functions * chore: minor dep bumps * chore: fixups * chore: merge fixups
1 parent 42347a1 commit 8ccb6d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+4888
-4210
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ jobs:
3535
${{ runner.os }}-node-
3636
3737
- run: npm ci
38+
- run: npm run check
3839

39-
- run: npx astro build
40+
## TODO: formatting checks
41+
42+
- run: npm run build
4043
env:
4144
NODE_OPTIONS: "--max-old-space-size=4192"
4245

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

bin/crawl-api-links.js

+72-72
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,85 @@ import core from "@actions/core";
44
const navigationTimeout = 120000; // Set the navigation timeout to 120 seconds (120,000 milliseconds)
55

66
function arrayToHTMLList(array) {
7-
let html = "<ul>";
7+
let html = "<ul>";
88

9-
for (let i = 0; i < array.length; i++) {
10-
html += "<li>" + array[i] + "</li>";
11-
}
9+
for (let i = 0; i < array.length; i++) {
10+
html += "<li>" + array[i] + "</li>";
11+
}
1212

13-
html += "</ul>";
13+
html += "</ul>";
1414

15-
return html;
15+
return html;
1616
}
1717

1818
async function checkLinks() {
19-
const browser = await puppeteer.launch({
20-
headless: "new",
21-
});
22-
const page = await browser.newPage();
23-
24-
const sitemapUrl = "https://developers.cloudflare.com/sitemap.xml";
25-
await page.goto(sitemapUrl, { timeout: navigationTimeout });
26-
27-
const sitemapLinks = await page.$$eval("url loc", (elements) =>
28-
elements.map((el) => el.textContent)
29-
);
30-
31-
const visitedLinks = [];
32-
const brokenLinks = [];
33-
34-
for (const link of sitemapLinks) {
35-
if (!link) {
36-
continue; // Skip if the link is empty
37-
}
38-
39-
await page.goto(link, {
40-
waitUntil: "networkidle0",
41-
timeout: navigationTimeout,
42-
});
43-
44-
const pageLinks = await page.$$eval("a", (elements) =>
45-
elements.map((el) => el.href)
46-
);
47-
48-
for (const pageLink of pageLinks) {
49-
if (!pageLink || visitedLinks.includes(pageLink)) {
50-
continue; // Skip if the pageLink is empty or has already been visited
51-
}
52-
53-
if (
54-
pageLink.includes("developers.cloudflare.com/api/operations/") ||
55-
pageLink.startsWith("/api/operations/")
56-
) {
57-
console.log(`Evaluating link: ${pageLink}`);
58-
await page.goto(pageLink, {
59-
waitUntil: "networkidle0",
60-
timeout: navigationTimeout,
61-
});
62-
visitedLinks.push(pageLink);
63-
64-
const statusCode = await page.evaluate(() => {
65-
return {
66-
url: window.location.href,
67-
};
68-
});
69-
if (statusCode.url === "https://developers.cloudflare.com/api/") {
70-
brokenLinks.push(pageLink);
71-
}
72-
}
73-
}
74-
}
75-
76-
await browser.close();
77-
console.log("Broken links:");
78-
console.log(brokenLinks);
79-
if (brokenLinks.length > 0) {
80-
core.setOutput("brokenLinks", arrayToHTMLList(brokenLinks));
81-
}
82-
process.exit(0);
19+
const browser = await puppeteer.launch({
20+
headless: "new",
21+
});
22+
const page = await browser.newPage();
23+
24+
const sitemapUrl = "https://developers.cloudflare.com/sitemap.xml";
25+
await page.goto(sitemapUrl, { timeout: navigationTimeout });
26+
27+
const sitemapLinks = await page.$$eval("url loc", (elements) =>
28+
elements.map((el) => el.textContent),
29+
);
30+
31+
const visitedLinks = [];
32+
const brokenLinks = [];
33+
34+
for (const link of sitemapLinks) {
35+
if (!link) {
36+
continue; // Skip if the link is empty
37+
}
38+
39+
await page.goto(link, {
40+
waitUntil: "networkidle0",
41+
timeout: navigationTimeout,
42+
});
43+
44+
const pageLinks = await page.$$eval("a", (elements) =>
45+
elements.map((el) => el.href),
46+
);
47+
48+
for (const pageLink of pageLinks) {
49+
if (!pageLink || visitedLinks.includes(pageLink)) {
50+
continue; // Skip if the pageLink is empty or has already been visited
51+
}
52+
53+
if (
54+
pageLink.includes("developers.cloudflare.com/api/operations/") ||
55+
pageLink.startsWith("/api/operations/")
56+
) {
57+
console.log(`Evaluating link: ${pageLink}`);
58+
await page.goto(pageLink, {
59+
waitUntil: "networkidle0",
60+
timeout: navigationTimeout,
61+
});
62+
visitedLinks.push(pageLink);
63+
64+
const statusCode = await page.evaluate(() => {
65+
return {
66+
url: window.location.href,
67+
};
68+
});
69+
if (statusCode.url === "https://developers.cloudflare.com/api/") {
70+
brokenLinks.push(pageLink);
71+
}
72+
}
73+
}
74+
}
75+
76+
await browser.close();
77+
console.log("Broken links:");
78+
console.log(brokenLinks);
79+
if (brokenLinks.length > 0) {
80+
core.setOutput("brokenLinks", arrayToHTMLList(brokenLinks));
81+
}
82+
process.exit(0);
8383
}
8484

8585
checkLinks().catch((error) => {
86-
console.error(error);
87-
process.exit(1);
86+
console.error(error);
87+
process.exit(1);
8888
});

0 commit comments

Comments
 (0)