Skip to content

Commit

Permalink
Merge branch 'production' into max/gw/log-updates-dns
Browse files Browse the repository at this point in the history
  • Loading branch information
maxvp authored Sep 16, 2024
2 parents d4bbe09 + 5cb88a1 commit 5180be7
Show file tree
Hide file tree
Showing 244 changed files with 18,981 additions and 17,670 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ 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"
RUN_LINK_CHECK: true

- name: Check - Validate redirects (infinite loops, sources with fragment)
run: npx tsm bin/validate-redirects.ts
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
on: [push, workflow_dispatch]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
publish:
runs-on: ubuntu-22.04
Expand Down
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
47 changes: 39 additions & 8 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import rehypeSlug from "rehype-slug";
import rehypeMermaid from "rehype-mermaid";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeExternalLinks from "rehype-external-links";
import starlightLinksValidator from "starlight-links-validator";
import { h } from "hastscript";
import { readdir } from "fs/promises";
import icon from "astro-icon";
import sitemap from "@astrojs/sitemap";

const runLinkCheck = process.env.RUN_LINK_CHECK || false;

async function autogenSections() {
const sections = (
await readdir("./src/content/docs/", {
Expand Down Expand Up @@ -150,14 +153,42 @@ export default defineConfig({
"./src/table.css",
"./src/tailwind.css",
],
plugins: [
starlightDocSearch({
appId: "8MU1G3QO9P",
apiKey: "4edb0a6cef3338ff4bcfbc6b3d2db56b",
indexName: "TEST - Re-dev docs",
}),
starlightImageZoom(),
],
plugins: runLinkCheck
? [
starlightLinksValidator({
errorOnInvalidHashes: false,
exclude: [
"/api/",
"/api/operations/**",
"/changelog/",
"/http/resources/**",
"{props.*}",
"/",
"**/glossary/?term=**",
"/products/?product-group=*",
"/products/",
"/rules/snippets/examples/?operation=*",
"/rules/transform/examples/?operation=*",
"/workers/examples/?languages=*",
"/workers/examples/?tags=*",
"/workers-ai/models/**",
],
}),
starlightDocSearch({
appId: "8MU1G3QO9P",
apiKey: "4edb0a6cef3338ff4bcfbc6b3d2db56b",
indexName: "TEST - Re-dev docs",
}),
starlightImageZoom(),
]
: [
starlightDocSearch({
appId: "8MU1G3QO9P",
apiKey: "4edb0a6cef3338ff4bcfbc6b3d2db56b",
indexName: "TEST - Re-dev docs",
}),
starlightImageZoom(),
],
}),
tailwind({
applyBaseStyles: false,
Expand Down
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 5180be7

Please sign in to comment.