Skip to content

Commit

Permalink
1.5.0 (#3)
Browse files Browse the repository at this point in the history
* New: `--include-images` to check for broken images
  • Loading branch information
sergejmueller authored May 9, 2019
1 parent 5f7d6af commit 033e034
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# octopus / CHANGELOG


### 1.5.0 (2019-05-09)

* New: `--include-images` to check for broken images


### 1.4.0 (2019-01-14)

* Replace: Namespace `superreal` by `deptagency`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Option | Description | Default
`--ignore-query` | Ignore a query string | `false`
`--ignore-external` | Ignore all external links | `false`
`--ignore-nofollow` | Ignore `rel=nofollow` links | `false`
`--include-images` | Check `<img>` elements | `false`
`--slack-webhook` | Slack incoming webhook url | `none`
`--timeout` | Time to wait for response | `5000`
`--silent` | Run without printing progress line | `false`
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- [x] Ignore rel="nofollow" links
- [ ] Respect project config file
- [ ] Images check
- [x] Images check
21 changes: 18 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,26 @@ const request = async (requestUrl, referenceUrl, requestCallback) => {
const $ = cheerioLoad(body);

$('a[href]').not( ignoreProtocols.join(',') ).each( (i, elem) => {
const hrefUrl = new URL(elem.attribs.href, baseUrl).href;
if (elem.attribs.href) {
const hrefUrl = new URL(elem.attribs.href, baseUrl).href;

if ( ! pageLinks.includes(hrefUrl) ) {
pageLinks.push(hrefUrl);
if ( ! pageLinks.includes(hrefUrl) ) {
pageLinks.push(hrefUrl);
}
}
});

if ( config['include-images'] ) {
$('img[src]').each((i, elem) => {
if (elem.attribs.src) {
const srcUrl = new URL(elem.attribs.src, baseUrl).href;

if (!pageLinks.includes(srcUrl)) {
pageLinks.push(srcUrl);
}
}
});
}
}

// Execute callback
Expand Down Expand Up @@ -284,6 +298,7 @@ module.exports = (argv) => {
'silent': Boolean(argv['silent']),
'ignore-query': (Array.isArray(argv['ignore-query']) ? argv['ignore-query'] : Array(argv['ignore-query'])),
'ignore-external': Boolean(argv['ignore-external']),
'include-images': Boolean(argv['include-images']),
'slack-webhook': String(argv['slack-webhook']),
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deptagency/octopus",
"version": "1.4.0",
"version": "1.5.0",
"main": "index.js",
"license": "MIT",
"description": "Recursive and multi-threaded broken link checker",
Expand Down
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,22 @@ describe( 'Octopus Playground', () => {

} );

it( `octopus ${playgroundUrl} --silent --include-images`, done => {

exec( `octopus ${playgroundUrl} --silent --include-images` ).then( result => {

const data = result.stdout.trim();

data.must.include( 'https://www.deptagency.com/wp-content/uploads/fly.jpeg' );
data.must.include( 'APPEARS ON: https://static-pages.sr-lab.de/kunden/public/github/octopus/' );
data.must.include( 'STATUS MSG: NOT FOUND (404)' );

data.must.include( '8 links checked' );

done();

} )

} );

} );

0 comments on commit 033e034

Please sign in to comment.