Skip to content

Commit

Permalink
improved check_urls plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Nov 5, 2024
1 parent 5b9d953 commit 1848e06
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions plugins/check_urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parseSrcset, searchLinks } from "../core/utils/dom_links.ts";
import { gray, green, red } from "../deps/colors.ts";
import { join } from "../deps/path.ts";
import { concurrent } from "../core/utils/concurrent.ts";
import { log } from "../core/utils/log.ts";

import type Site from "../core/site.ts";

Expand Down Expand Up @@ -58,6 +59,11 @@ export default function (userOptions?: Options) {
const urls = new Map<string, Set<string>>(); // All URLs found
const redirects = new Set<string>(); // All URLs that redirect

// Ignore the ouput file to avoid infinite build loop
if (typeof options.output === "string") {
site.options.watcher.ignore.push(options.output);
}

function scan(url: string, pageUrl: URL): void {
if (ignore(url)) { // ignore empty, hash, search, etc
return;
Expand Down Expand Up @@ -253,6 +259,14 @@ function outputFile(
2,
);
Deno.writeTextFileSync(file, content);

if (notFound.size === 0) {
log.info("No broken links found!");
} else {
log.info(
`⛓️‍💥 ${notFound.size} broken links saved to <gray>${file}</gray>`,
);
}
}

function outputConsole(notFound: Map<string, Set<string>>) {
Expand Down

0 comments on commit 1848e06

Please sign in to comment.