-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
content/issue 75 final content and site review (#127)
- Loading branch information
1 parent
3b0ec3e
commit 5415d00
Showing
48 changed files
with
433 additions
and
208 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,65 @@ | ||
import graph from "./public/graph.json" with { type: "json" }; | ||
import { parse } from "node-html-parser"; | ||
import fs from "fs/promises"; | ||
|
||
const report = {}; | ||
|
||
for (const page of graph) { | ||
const { outputHref, route } = page; | ||
const html = await fs.readFile(new URL(outputHref), "utf-8"); | ||
const root = parse(html); | ||
const links = root.querySelectorAll("a"); | ||
|
||
links.forEach((link) => { | ||
if (!route.startsWith("/blog/") && link.getAttribute("href").startsWith("/")) { | ||
const linkUrl = new URL(`https://www.greenwoodjs.dev${link.getAttribute("href")}`); | ||
const { pathname, hash } = linkUrl; | ||
const matchingRoute = graph.find((page) => page.route === pathname); | ||
|
||
if (!matchingRoute) { | ||
if (!report[route]) { | ||
report[route] = { | ||
violations: [], | ||
}; | ||
} | ||
|
||
report[route].violations.push({ | ||
link: pathname, | ||
}); | ||
} | ||
|
||
if (matchingRoute && hash !== "") { | ||
const { tableOfContents } = matchingRoute.data; | ||
const match = tableOfContents.find((toc) => toc.slug === hash.replace("#", "")); | ||
|
||
if (!match) { | ||
if (!report[route]) { | ||
report[route] = { | ||
violations: [], | ||
}; | ||
} | ||
|
||
report[route].violations.push({ | ||
hash, | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
if (Object.keys(report).length === 0) { | ||
console.log("✅ all links checked successfully and no broken links found"); | ||
} else { | ||
for (const r of Object.keys(report)) { | ||
console.log("---------------------------------"); | ||
console.log(`🚨 reporting violations for route ${r}...`); | ||
report[r].violations.forEach((violation, idx) => { | ||
if (violation.link) { | ||
console.error(`${idx + 1}) Could not find matching route for href => ${violation.link}`); | ||
} else if (violation.hash) { | ||
console.error(`${idx + 1}) Could not find matching heading for hash => ${violation.hash}`); | ||
} | ||
}); | ||
} | ||
} |
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.