@fidian/metalsmith-link-checker
v0.8.0
Published
A Metalsmith plugin to check for broken links.
Downloads
112
Maintainers
Readme
@fidian/metalsmith-link-checker
This is forked from metalsmith-link-checker with some speed improvements and some local file link resolution bugfixes.
A Metalsmith plugin to check for local and remote broken links.
This plugin checks a number of different link types and protocols:
http:
andhttps:
remote links (with backoff and retry)- Local links (both relative and absolute)
facetime:
andfacetime-audio:
phone numbers and email addressesmailto:
email linkssms:
phone numberstel:
phone numbers
If there are any broken or invalid links found, all of them will be printed to console and the Metalsmith build will stop.
Installation
npm install --save metalsmith-link-checker
JavaScript Usage
This plugin will cause a build error if any links are broken:
const Metalsmith = require('metalsmith');
const linkChecker = require('metalsmith-link-checker');
Metalsmith(__dirname)
.use(linkChecker({
// options here
}))
.build((err) => {
if (err) {
throw err;
}
});
Options
html.pattern
(optional)
Type: string
Default: **/*.html
A micromatch glob pattern to find HTML files.
html.tags
(optional)
Type: object
Default:
{
"a": "href",
"img": ["src", "data-src"],
"link": "href",
"script": "src"
}
An object of what tags and attributes to look for links in.
ignore
(optional)
Type: string[]
Default: []
An array of regular expressions of links to be ignored.
timeout
(optional)
Type: number
Default: 10000
The network timeout when checking external links, in milliseconds.
attempts
(optional)
Type: number
Default: 3
The number of times to attempt checking external links.
userAgent
(optional)
Type: string
Default: the top result from top-user-agents
The user agent to use when making network requests.
parallelism
(optional)
Type: number
Default: 100
The maximum number of async operations at a time.