Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a link checker for gulp?

Tags:

node.js

gulp

Is there a 404 link checker for gulp? I'm looking for something like grunt's grunt-link-checker for those unfamiliar it provides a list of internal and external links that 404.

like image 258
David Silva Smith Avatar asked Jun 28 '14 04:06

David Silva Smith


1 Answers

A gulpfile is just javascript. So you could easily make a task for this:

var gulp = require('gulp');
var gutil = require('gulp-util');
var Crawler = require('simplecrawler');

gulp.task('checklinks', function(cb) {
  Crawler.crawl('http://example.com/')
    .on('fetch404', function(queueItem, response) {
      gutil.log('Resource not found linked from ' +
                      queueItem.referrer + ' to', queueItem.url);
      gutil.log('Status code: ' + response.statusCode);
    })
    .on('complete', function(queueItem) {
      cb();
    });
});

grunt-link-checker uses https://github.com/cgiffard/node-simplecrawler. We can just use its API directly in the gulpfile.

like image 120
Austin Pray Avatar answered Oct 10 '22 10:10

Austin Pray