Skip to content

Commit

Permalink
[Docs Site] Fixes all Astro TypeScript issues (cloudflare#16457)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Cherry authored Sep 13, 2024
1 parent 42347a1 commit 8ccb6d7
Show file tree
Hide file tree
Showing 62 changed files with 4,888 additions and 4,210 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ jobs:
${{ runner.os }}-node-
- run: npm ci
- run: npm run check

- run: npx astro build
## TODO: formatting checks

- run: npm run build
env:
NODE_OPTIONS: "--max-old-space-size=4192"

Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
144 changes: 72 additions & 72 deletions bin/crawl-api-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,85 @@ import core from "@actions/core";
const navigationTimeout = 120000; // Set the navigation timeout to 120 seconds (120,000 milliseconds)

function arrayToHTMLList(array) {
let html = "<ul>";
let html = "<ul>";

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

html += "</ul>";
html += "</ul>";

return html;
return html;
}

async function checkLinks() {
const browser = await puppeteer.launch({
headless: "new",
});
const page = await browser.newPage();

const sitemapUrl = "https://developers.cloudflare.com/sitemap.xml";
await page.goto(sitemapUrl, { timeout: navigationTimeout });

const sitemapLinks = await page.$$eval("url loc", (elements) =>
elements.map((el) => el.textContent)
);

const visitedLinks = [];
const brokenLinks = [];

for (const link of sitemapLinks) {
if (!link) {
continue; // Skip if the link is empty
}

await page.goto(link, {
waitUntil: "networkidle0",
timeout: navigationTimeout,
});

const pageLinks = await page.$$eval("a", (elements) =>
elements.map((el) => el.href)
);

for (const pageLink of pageLinks) {
if (!pageLink || visitedLinks.includes(pageLink)) {
continue; // Skip if the pageLink is empty or has already been visited
}

if (
pageLink.includes("developers.cloudflare.com/api/operations/") ||
pageLink.startsWith("/api/operations/")
) {
console.log(`Evaluating link: ${pageLink}`);
await page.goto(pageLink, {
waitUntil: "networkidle0",
timeout: navigationTimeout,
});
visitedLinks.push(pageLink);

const statusCode = await page.evaluate(() => {
return {
url: window.location.href,
};
});
if (statusCode.url === "https://developers.cloudflare.com/api/") {
brokenLinks.push(pageLink);
}
}
}
}

await browser.close();
console.log("Broken links:");
console.log(brokenLinks);
if (brokenLinks.length > 0) {
core.setOutput("brokenLinks", arrayToHTMLList(brokenLinks));
}
process.exit(0);
const browser = await puppeteer.launch({
headless: "new",
});
const page = await browser.newPage();

const sitemapUrl = "https://developers.cloudflare.com/sitemap.xml";
await page.goto(sitemapUrl, { timeout: navigationTimeout });

const sitemapLinks = await page.$$eval("url loc", (elements) =>
elements.map((el) => el.textContent),
);

const visitedLinks = [];
const brokenLinks = [];

for (const link of sitemapLinks) {
if (!link) {
continue; // Skip if the link is empty
}

await page.goto(link, {
waitUntil: "networkidle0",
timeout: navigationTimeout,
});

const pageLinks = await page.$$eval("a", (elements) =>
elements.map((el) => el.href),
);

for (const pageLink of pageLinks) {
if (!pageLink || visitedLinks.includes(pageLink)) {
continue; // Skip if the pageLink is empty or has already been visited
}

if (
pageLink.includes("developers.cloudflare.com/api/operations/") ||
pageLink.startsWith("/api/operations/")
) {
console.log(`Evaluating link: ${pageLink}`);
await page.goto(pageLink, {
waitUntil: "networkidle0",
timeout: navigationTimeout,
});
visitedLinks.push(pageLink);

const statusCode = await page.evaluate(() => {
return {
url: window.location.href,
};
});
if (statusCode.url === "https://developers.cloudflare.com/api/") {
brokenLinks.push(pageLink);
}
}
}
}

await browser.close();
console.log("Broken links:");
console.log(brokenLinks);
if (brokenLinks.length > 0) {
core.setOutput("brokenLinks", arrayToHTMLList(brokenLinks));
}
process.exit(0);
}

checkLinks().catch((error) => {
console.error(error);
process.exit(1);
console.error(error);
process.exit(1);
});
Loading

0 comments on commit 8ccb6d7

Please sign in to comment.