-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content/issue 75 final content and site review #127
Merged
thescientist13
merged 12 commits into
main
from
content/issue-75-final-content-and-site-review
Nov 7, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f75d022
link checker script
thescientist13 6f612ec
install html parser dep
thescientist13 fd94481
docs content final walk through
thescientist13 fe92395
final guides content walk through
thescientist13 880b0e4
fix up collections example
thescientist13 de4d5a2
thin out inline style blocks
thescientist13 ff12666
improve table of contents contrast on mobile
thescientist13 e2bda97
make edit on github button smaller on mobile
thescientist13 1622cf1
lit ssr plugin repo link
thescientist13 bfa76e6
clarify DOM emulation optional chaining opt-outs
thescientist13 67c711c
fix linting
thescientist13 5cccdef
hide edit on github button on lower breakpoints
thescientist13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit pick.. the
URL()
class can take 2 arguments, which would avoid the string concat.https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, I always forget about that lol. Next time! (Or happy to accept a PR for it 👍)