Skip to content

Instantly share code, notes, and snippets.

@tg44
Created June 5, 2021 07:25
Show Gist options
  • Save tg44/c43f9e3af5a508192d9d9fb7edd294f8 to your computer and use it in GitHub Desktop.
Save tg44/c43f9e3af5a508192d9d9fb7edd294f8 to your computer and use it in GitHub Desktop.
Vuepress broken link checker
const path = require( 'path' );
const express = require( 'express' );
const app = express();
const blc = () => {
let err = 0
const blc = require('broken-link-checker')
const siteChecker = new blc.SiteChecker({}, {
robots: function(robots, customData){},
html: function(tree, robots, response, pageUrl, customData){},
junk: function(result, customData){},
link: (result, customData) => {
if(result.broken) {
err++
console.info(`Broken link in ${result.base.original} to ${result.url.original} with ${result.brokenReason}`)
//console.info("l: " + JSON.stringify(result))
}
},
page: (error, pageUrl, customData) => {},
site: function(error, siteUrl, customData){},
end: () => {
console.info( `BLC finished with ${err} roken links`);
process.exit(err)
}
});
siteChecker.enqueue("http://localhost:8080/", {});
}
app.use('/',
express.static( path.resolve( __dirname, './docs/.vuepress/dist/' ) )
);app.listen(8080, 'localhost', ( err ) => {
if ( err ) {
console.error( err )
process.exit(1)
} else {
console.info( 'Listening at http://localhost:8080' );
blc()
}
});
{
...
"scripts": {
"docs:dev": "vuepress dev --debug docs",
"docs:build": "vuepress build docs",
"docs:check": "node linkchecker.js",
"clean": "rm -rf node_modules",
"reinstall": "npm run clean && npm install",
"docs:clean": "rm -rf docs/.vuepress/dist/ && rm -rf node_modules/@vuepress/core/node_modules/.cache"
},
...
"devDependencies": {
"broken-link-checker": "^0.7.8",
"express": "^4.17.1",
"path": "^0.12.7",
"vuepress": "^1.8.2"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment