Skip to content

Commit

Permalink
External link checks
Browse files Browse the repository at this point in the history
  • Loading branch information
PuruVJ committed Sep 20, 2024
1 parent f59f23c commit 0a71800
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ async function checkLinks() {
const slugErrors = errors.get(slug)!;
const lines = raw.split('\n');

const linksToCheck = new Set<string>();

await transform(raw, {
link({ href }) {
if (href.startsWith('#')) {
Expand Down Expand Up @@ -217,11 +219,27 @@ async function checkLinks() {
}
}
}
} else if (/^https?:\/\//.test(href)) {
// If the link is an external URL, then add it to the link queue
linksToCheck.add(href);
}

return '';
},
});

// Check links to external URLs
for (const link of linksToCheck) {
console.log(kleur.dim().bold(`Checking ${slug}:${link}`));
const response = await fetch(link);
if (!response.ok) {
slugErrors.add({
message: `External: Link to ${link} is broken`,
file: path,
line: lines.findIndex(line => line.includes(link)) + 1,
});
}
}
}
}

Expand Down

0 comments on commit 0a71800

Please sign in to comment.