-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(validate/links): use 'link-checker' temporarily (#78)
Co-authored-by: Sid Vishnoi <[email protected]>
- Loading branch information
1 parent
453bce4
commit 06be7f7
Showing
2 changed files
with
22 additions
and
10 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 |
---|---|---|
@@ -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(" "); | ||
} |