Check Your Hexo Static Site for 404 Errors

So the idea is that we will hexo gen generate the site, run http-server, then run blc broken-link-checker.

Install

npm install --save-dev http-server broken-link-checker npm-run-all

NPM scripts

In the scripts section of package.json

"scripts": {
  "prd-gulp": "NODE_ENV=production gulp prd",
  "prd-hexo": "NODE_ENV=production hexo gen",
  "prd": "run-s setup-* && run-s prd-*",
  "test-server": "http-server public -p 4000 -a 127.0.0.1 -s -c-1 & echo $! > .test-server-id",
  "test-blc": "sleep 1 && blc --exclude-external -r -requests 32 http://127.0.0.1:4000 && kill `cat .test-server-id` && rm .test-server-id",
  "test": "npm run prd && run-p test-*"
}

Conclusion

If all files check for 200 status it succeeds. If any 404 the script tells you which one and fails. That will allow it to be built into a flow where success is required to continue.

Home Experience Archives Github Repos