Gathering detailed insights and metrics for @tankunsheng/linkinator
Gathering detailed insights and metrics for @tankunsheng/linkinator
Gathering detailed insights and metrics for @tankunsheng/linkinator
Gathering detailed insights and metrics for @tankunsheng/linkinator
🐿 Scurry around your site and find all those broken links.
npm install @tankunsheng/linkinator
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (86.58%)
JavaScript (13.42%)
Total Downloads
762
Last Day
3
Last Week
4
Last Month
16
Last Year
220
MIT License
192 Commits
5 Branches
6 Contributors
Updated on Sep 28, 2021
Minified
Minified + Gzipped
Latest Version
0.0.0
Package Id
@tankunsheng/linkinator@0.0.0
Unpacked Size
96.45 kB
Size
26.43 kB
File Count
27
NPM Version
7.16.0
Node Version
12.13.0
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
300%
4
Compared to previous week
Last Month
-52.9%
16
Compared to previous month
Last Year
10%
220
Compared to previous year
11
A super simple site crawler and broken link checker.
Behold my latest inator! The linkinator
provides an API and CLI for crawling websites and validating links. It's got a ton of sweet features:
<a href>
1npm install linkinator
Not into the whole node.js or npm thing? You can also download a standalone binary that bundles node, linkinator, and anything else you need. See releases.
You can use this as a library, or as a CLI. Let's see the CLI!
1$ linkinator LOCATIONS [ --arguments ] 2 3 Positional arguments 4 5 LOCATIONS 6 Required. Either the URLs or the paths on disk to check for broken links. 7 Supports multiple paths, and globs. 8 9 Flags 10 11 --concurrency 12 The number of connections to make simultaneously. Defaults to 100. 13 14 --config 15 Path to the config file to use. Looks for `linkinator.config.json` by default. 16 17 --directory-listing 18 Include an automatic directory index file when linking to a directory. 19 Defaults to 'false'. 20 21 --format, -f 22 Return the data in CSV or JSON format. 23 24 --help 25 Show this command. 26 27 --include, -i 28 List of urls in regexy form to include. The opposite of --skip. 29 30 --markdown 31 Automatically parse and scan markdown if scanning from a location on disk. 32 33 --recurse, -r 34 Recursively follow links on the same root domain. 35 36 --retry, 37 Automatically retry requests that return HTTP 429 responses and include 38 a 'retry-after' header. Defaults to false. 39 40 --server-root 41 When scanning a locally directory, customize the location on disk 42 where the server is started. Defaults to the path passed in [LOCATION]. 43 44 --skip, -s 45 List of urls in regexy form to not include in the check. 46 47 --timeout 48 Request timeout in ms. Defaults to 0 (no timeout). 49 50 --url-rewrite-search 51 Pattern to search for in urls. Must be used with --url-rewrite-replace. 52 53 --url-rewrite-replace 54 Expression used to replace search content. Must be used with --url-rewrite-search. 55 56 --verbosity 57 Override the default verbosity for this command. Available options are 58 'debug', 'info', 'warning', 'error', and 'none'. Defaults to 'warning'.
You can run a shallow scan of a website for busted links:
1npx linkinator http://jbeckwith.com
That was fun. What about local files? The linkinator will stand up a static web server for yinz:
1npx linkinator ./docs
But that only gets the top level of links. Lets go deeper and do a full recursive scan!
1npx linkinator ./docs --recurse
Aw, snap. I didn't want that to check those links. Let's skip em:
1npx linkinator ./docs --skip www.googleapis.com
The --skip
parameter will accept any regex! You can do more complex matching, or even tell it to only scan links with a given domain:
1linkinator http://jbeckwith.com --skip '^(?!http://jbeckwith.com)'
Maybe you're going to pipe the output to another program. Use the --format
option to get JSON or CSV!
1linkinator ./docs --format CSV
Let's make sure the README.md
in our repo doesn't have any busted links:
1linkinator ./README.md --markdown
You know what, we better check all of the markdown files!
1linkinator "**/*.md" --markdown
You can pass options directly to the linkinator
CLI, or you can define a config file. By default, linkinator
will look for a linkinator.config.json
file in the current working directory.
All options are optional. It should look like this:
1{ 2 "format": "json", 3 "recurse": true, 4 "silent": true, 5 "concurrency": 100, 6 "timeout": 0, 7 "markdown": true, 8 "directoryListing": true, 9 "skip": "www.googleapis.com" 10}
To load config settings outside the CWD, you can pass the --config
flag to the linkinator
CLI:
1linkinator --config /some/path/your-config.json
You can use linkinator
as a GitHub Action as well, using JustinBeckwith/linkinator-action:
1on: 2 push: 3 branches: 4 - main 5 pull_request: 6name: ci 7jobs: 8 linkinator: 9 runs-on: ubuntu-latest 10 steps: 11 - uses: actions/checkout@v2 12 - uses: JustinBeckwith/linkinator-action@v1 13 with: 14 paths: README.md
To see all options or to learn more, visit JustinBeckwith/linkinator-action.
Asynchronous method that runs a site wide scan. Options come in the form of an object that includes:
path
(string|string[]) - A fully qualified path to the url to be scanned, or the path(s) to the directory on disk that contains files to be scanned. required.concurrency
(number) - The number of connections to make simultaneously. Defaults to 100.port
(number) - When the path
is provided as a local path on disk, the port
on which to start the temporary web server. Defaults to a random high range order port.recurse
(boolean) - By default, all scans are shallow. Only the top level links on the requested page will be scanned. By setting recurse
to true
, the crawler will follow all links on the page, and continue scanning links on the same domain for as long as it can go. Results are cached, so no worries about loops.retry
(boolean|RetryConfig) - Automatically retry requests that respond with an HTTP 429, and include a retry-after
header. The RetryConfig
option is a placeholder for fine-grained controls to be implemented at a later time, and is only included here to signal forward-compatibility.serverRoot
(string) - When scanning a locally directory, customize the location on disk
where the server is started. Defaults to the path passed in path
.timeout
(number) - By default, requests made by linkinator do not time out (or follow the settings of the OS). This option (in milliseconds) will fail requests after the configured amount of time.markdown
(boolean) - Automatically parse and scan markdown if scanning from a location on disk.linksToSkip
(array | function) - An array of regular expression strings that should be skipped, OR an async function that's called for each link with the link URL as its only argument. Return a Promise that resolves to true
to skip the link or false
to check it.directoryListing
(boolean) - Automatically serve a static file listing page when serving a directory. Defaults to false
.urlRewriteExpressions
(array) - Collection of objects that contain a search pattern, and replacement.Constructor method that can be used to create a new LinkChecker
instance. This is particularly useful if you want to receive events as the crawler crawls. Exposes the following events:
pagestart
(string) - Provides the url that the crawler has just started to scan.link
(object) - Provides an object with
url
(string) - The url that was scannedstate
(string) - The result of the scan. Potential values include BROKEN
, OK
, or SKIPPED
.status
(number) - The HTTP status code of the request.1const link = require('linkinator'); 2 3async function simple() { 4 const results = await link.check({ 5 path: 'http://example.com' 6 }); 7 8 // To see if all the links passed, you can check `passed` 9 console.log(`Passed: ${results.passed}`); 10 11 // Show the list of scanned links and their results 12 console.log(results); 13 14 // Example output: 15 // { 16 // passed: true, 17 // links: [ 18 // { 19 // url: 'http://example.com', 20 // status: 200, 21 // state: 'OK' 22 // }, 23 // { 24 // url: 'http://www.iana.org/domains/example', 25 // status: 200, 26 // state: 'OK' 27 // } 28 // ] 29 // } 30} 31simple();
In most cases you're going to want to respond to events, as running the check command can kinda take a long time.
1const link = require('linkinator'); 2 3async function complex() { 4 // create a new `LinkChecker` that we'll use to run the scan. 5 const checker = new link.LinkChecker(); 6 7 // Respond to the beginning of a new page being scanned 8 checker.on('pagestart', url => { 9 console.log(`Scanning ${url}`); 10 }); 11 12 // After a page is scanned, check out the results! 13 checker.on('link', result => { 14 15 // check the specific url that was scanned 16 console.log(` ${result.url}`); 17 18 // How did the scan go? Potential states are `BROKEN`, `OK`, and `SKIPPED` 19 console.log(` ${result.state}`); 20 21 // What was the status code of the response? 22 console.log(` ${result.status}`); 23 24 // What page linked here? 25 console.log(` ${result.parent}`); 26 }); 27 28 // Go ahead and start the scan! As events occur, we will see them above. 29 const result = await checker.check({ 30 path: 'http://example.com', 31 // port: 8673, 32 // recurse: true, 33 // linksToSkip: [ 34 // 'https://jbeckwith.com/some/link', 35 // 'http://example.com' 36 // ] 37 }); 38 39 // Check to see if the scan passed! 40 console.log(result.passed ? 'PASSED :D' : 'FAILED :('); 41 42 // How many links did we scan? 43 console.log(`Scanned total of ${result.links.length} links!`); 44 45 // The final result will contain the list of checked links, and the pass/fail 46 const brokeLinksCount = result.links.filter(x => x.state === 'BROKEN'); 47 console.log(`Detected ${brokeLinksCount.length} broken links.`); 48} 49 50complex();
This library supports proxies via the HTTP_PROXY
and HTTPS_PROXY
environment variables. This guide provides a nice overview of how to format and set these variables.
You may have noticed in the example, when using a glob the pattern is encapsulated in quotes:
1linkinator "**/*.md" --markdown
Without the quotes, some shells will attempt to expand the glob paths on their own. Various shells (bash, zsh) have different, somewhat unpredictable behaviors when left to their own devices. Using the quotes ensures consistent, predictable behavior by letting the library expand the pattern.
Oftentimes when a link fails, it's an easy to spot typo, or a clear 404. Other times ... you may need more details on exactly what went wrong. To see a full call stack for the HTTP request failure, use --verbosity DEBUG
:
1linkinator https://jbeckwith.com --verbosity DEBUG
The --verbosity
flag offers preset options for controlling the output, but you may want more control. Using jq
and --format JSON
- you can do just that!
1linkinator https://jbeckwith.com --verbosity DEBUG --format JSON | jq '.links | .[] | select(.state | contains("BROKEN"))'
No vulnerabilities found.
No security vulnerabilities found.