forked from nus-cs2103-AY2223S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from RichDom2185/week13/add-link-checker
Add link checker
- Loading branch information
Showing
6 changed files
with
804 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Check all links on website are valid | ||
|
||
on: [push, pull_request, workflow_dispatch] | ||
|
||
jobs: | ||
check-links: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Set up repository | ||
uses: actions/checkout@main | ||
- name: Set up PATH | ||
run: echo "$HOME/.gem/ruby/2.7.0/bin" >> $GITHUB_PATH | ||
- name: Set up server dependencies | ||
working-directory: ${{ github.workspace }}/docs | ||
run: gem install --user-install bundler && bundle install | ||
- name: Set up checker dependencies | ||
working-directory: ${{ github.workspace }}/cli-test/linkchecker | ||
run: npm install | ||
- name: Set up server and check all links are valid | ||
working-directory: ${{ github.workspace }}/cli-test/linkchecker | ||
run: python serve-and-check.py |
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 @@ | ||
node_modules |
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,49 @@ | ||
// Adapted from https://github.com/w3c/node-linkchecker | ||
import { check } from "node-linkchecker"; | ||
const options = { | ||
schemes: ["http:"], // Do not check external links to prevent rate-limiting | ||
userAgent: | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36", | ||
fragments: true, | ||
}; | ||
|
||
const HOST = process.env.HOST ?? "http://localhost:4000"; | ||
const PATHS_TO_CHECK = [ | ||
// Basic | ||
"/", | ||
"/UserGuide.html", | ||
"/DeveloperGuide.html", | ||
// Other Pages | ||
"/AboutUs.html", | ||
"/Configuration.html", | ||
"/DevOps.html", | ||
"/Documentation.html", | ||
"/Logging.html", | ||
"/SettingUp.html", | ||
"/Testing.html", | ||
// PPP | ||
"/team/bryanljx.html", | ||
"/team/eugenetanwl3881.html", | ||
"/team/ferusel.html", | ||
"/team/richdom2185.html", | ||
"/team/yixiann.html", | ||
]; | ||
|
||
const links = new Set(); | ||
const fragments = new Set(); | ||
for (const path of PATHS_TO_CHECK) { | ||
console.log("Checking URL: " + HOST + path); | ||
const { brokenLinks, brokenFragments } = await check(HOST + path, options); | ||
brokenLinks.forEach(({ link }) => links.add(link)); | ||
brokenFragments.forEach(({ link }) => fragments.add(link)); | ||
} | ||
if (links.size > 0) { | ||
process.stderr.write("Broken Links: "); | ||
console.error(links); | ||
process.exitCode = 1; | ||
} | ||
if (fragments.size > 0) { | ||
process.stderr.write("Broken Fragments: "); | ||
console.error(fragments); | ||
process.exitCode = 1; | ||
} |
Oops, something went wrong.