Skip to content

Commit

Permalink
fix(validate/links): use 'link-checker' temporarily (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Sid Vishnoi <[email protected]>
  • Loading branch information
marcoscaceres and sidvishnoi authored Jun 9, 2021
1 parent 453bce4 commit 06be7f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ The Action will try to make use of metadata/config from previously published ver

Whether or not to check for broken hyperlinks.

**Warning:** This feature is experimental.

**Possible values:** true, false

**Default:** false
Expand Down
30 changes: 20 additions & 10 deletions src/validate-links.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import { env, exit, install, sh, yesOrNo } from "./utils.js";
import { PUPPETEER_ENV } from "./constants.js";

import { BuildResult } from "./build.js";
type Input = Pick<BuildResult, "dest" | "file">;

const URL_IGNORE = [
// Doesn't like robots
"https://ev.buaa.edu.cn/",
// The to-be published /TR URL.
// Ideally should include shortname, but may be good enough.
`/TR/.+${new Date().toISOString().slice(0, 10).replace(/-/g, "")}/$`,
];

if (module === require.main) {
if (yesOrNo(env("INPUTS_VALIDATE_LINKS")) === false) {
exit("Skipped", 0);
}
exit("Link validator is currently disabled due to some bugs.", 0);

const input: Input = JSON.parse(env("OUTPUTS_BUILD"));
main(input).catch(err => exit(err.message || "Failed", err.code));
}

export default async function main({ dest, file }: Input) {
await install(`href-checker`, PUPPETEER_ENV);
await sh(`href-checker ${file} --no-same-site`, {
output: "stream",
cwd: dest,
env: PUPPETEER_ENV,
});
export default async function main({ dest: dir }: Input) {
await install("link-checker");
const opts = getLinkCheckerOptions(URL_IGNORE);
// Note: link-checker checks a directory, not a file.
await sh(`link-checker ${opts} ${dir}`, "stream");
}

function getLinkCheckerOptions(ignoreList: string[]) {
return ignoreList
.map(url => `--url-ignore="${url}"`)
.concat(["--http-timeout=50000", "--http-redirects=3", "--http-always-get"])
.join(" ");
}

0 comments on commit 06be7f7

Please sign in to comment.