-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
225 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { DOMParser } from "jsr:@b-fuze/deno-dom"; | ||
|
||
const visitedPages = new Set<string>(); | ||
|
||
const rootURL = new URL(Deno.env.get("DOCS_ROOT")!); | ||
const rootPage = await fetch(rootURL).then((res) => res.text()); | ||
|
||
visitedPages.add(rootURL); | ||
let hasInvalidHrefs = false; | ||
|
||
await traversePage(rootURL, rootPage); | ||
|
||
if (hasInvalidHrefs) { | ||
Deno.exit(1); | ||
} | ||
|
||
async function traversePage(url: URL, content: string) { | ||
const doc = new DOMParser().parseFromString(content, "text/html"); | ||
await Promise.allSettled([...doc.querySelectorAll("a").values()] | ||
.map((a) => { | ||
const href = a.getAttribute("href")?.trim(); | ||
if (!href) { | ||
hasInvalidHrefs = true; | ||
console.error(`Empty href on '${url.pathname}': ${a.outerHTML}`); | ||
return; | ||
} | ||
|
||
if (href.startsWith("http") || href.startsWith("mailto")) { | ||
return; | ||
} | ||
|
||
const aURL = new URL(href, url); | ||
if (aURL.pathname.startsWith("/api")) { | ||
return; | ||
} | ||
|
||
if (visitedPages.has(aURL.href)) { | ||
return; | ||
} | ||
|
||
visitedPages.add(aURL.href); | ||
|
||
return fetch(aURL).then((res) => { | ||
if (res.status === 200) { | ||
if (res.headers.get("content-type")?.includes("text/html")) { | ||
return res.text().then((text) => traversePage(aURL, text)); | ||
} | ||
} else { | ||
hasInvalidHrefs = true; | ||
console.error(`${res.status} on '${url.pathname}': ${href}`); | ||
} | ||
|
||
return res.body?.cancel(); | ||
}); | ||
})); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.