Skip to content

Commit

Permalink
Update link checker to have clearer details and instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabek committed Feb 17, 2024
1 parent afc59bc commit 78afee6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions scripts/linkchecker/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const links = require("./links.json");
const repositoryOwner = "owncast";
const repositoryName = "owncast";
const localLinkMessage = `\nHowever, this is a link internal to the site. So make sure you understand how the site is organized using [Hugo](https://gohugo.io/content-management/organization/), our [static site generator](https://jamstack.org/glossary/ssg/).\n`;

async function searchForIssue(issueTitle) {
// console.log("Searching for issue with title:", issueTitle);
Expand All @@ -19,20 +20,30 @@ async function searchForIssue(issueTitle) {
return null;
}

function cleanInternalLink(link) {
return link.replace(/file:\/\/\/.*\/owncast\.github\.io/, "Internal link: ");
}

function isInternalLink(link) {
return link.startsWith("file:///");
}

async function run() {
for (const key in links.fail_map) {
if (links.fail_map.hasOwnProperty(key)) {
const failedUrls = links.fail_map[key];
for (const failedUrl of failedUrls) {
const link = failedUrl.url;
const isInternal = isInternalLink(link);
const displayLink = cleanInternalLink(link);
const displaySource = key.replace("../../", "");
const issueTitle = `Documentation broken link: ${link}`;
const issueTitle = `Documentation broken link: ${displayLink}`;
const sourceLink = `https://github.com/owncast/owncast.github.io/tree/master/${displaySource}`;
const sourceLinkEditor = `https://github.dev/owncast/owncast.github.io/tree/master/${displaySource}`;

let issueCheck;
try {
issueCheck = await searchForIssue(link);
issueCheck = await searchForIssue(displayLink);
await sleep(2000);
if (issueCheck) {
console.log("Issue already exists");
Expand All @@ -42,8 +53,8 @@ async function run() {
let issueBody = `
# Broken link found in Owncast documentation
Please fix or remove the broken link ${link} from [${displaySource}](${sourceLink}).
First, **please verify that this link or asset is actually broken** by testing the correct page that is in production at https://owncast.online. Then you can fix or remove the broken link ${displayLink} from [${displaySource}](${sourceLink}).
${isInternal ? localLinkMessage : ""}
You can find the Owncast documentation site repository at https://github.com/owncast/owncast.github.io, and that is where you would make any fixes to broken links, or documentation in general. Thank you for helping improve our documentation!
[Open documentation repository in editor](${sourceLinkEditor})
Expand Down

0 comments on commit 78afee6

Please sign in to comment.