Git Product home page Git Product logo

grunt-deadlink's Introduction

grunt-deadlink

check dead links in files

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-deadlink --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-deadlink');

The "deadlink" task

Overview

In your project's Gruntfile, add a section named deadlink to the data object passed into grunt.initConfig(). For example, check out below code.

grunt.initConfig({
  deadlink: {
    options: {
      filter: function(content) { // `function` or `regular expressions` to take a link. default is markdown.
          var expressions = [
            /\[[^\]]*\]\((http[s]?:\/\/[^\) ]+)/g,  //[...](<url>)
            /\[[^\]]*\]\s*:\s*(http[s]?:\/\/.*)/g,  //[...]: <url>
          ];
          var result = [];
          _.forEach(expressions, function(expression) {
            var match = expression.exec(content);
            while(match != null) {
              result.push(match[1]);
              match = expression.exec(content);
            }
          });
          return result; // Return array of link. 
      }
    },
    your_target: {
      src: [ "doc/**/*.md", "!doc/layout/*.md" ]         // glob pattern. files path that include links to checking.
      filter: [...] // It has high priority then `options`.
    },
  },
})

Options

options.logToFile

  • Type : boolean
  • Default value : false

If this is true, Test report is printed to the file. Default file name to watch is 'deadlink.log'. It will locate in same directory with Gruntfile.js. If you change file path or name, look at options.logFilename

Note that to enable logging, grunt should be run in verbose mode.

options.logAll

  • Type : boolean
  • Default value : false

If this is true, non-broken link is logged. It can used with options.logToFile

options.logFilename

  • Type : String
  • Default value : 'deadlink.log'

If this is true, non-broken link is logged. It can used with options.logToFile

options.filter

  • Type : Function or Array of RegExp object
  • Default value : regular expression for markdown link form

regular expression to recognize a link. default is markdown.

If this is function, it get a content as argument and return array of link. So you should extract links in contnet within filter funciton.

If this is array of RegExp, first submatch string must be link to test. For example, markdown can match with /\[[^\]]*\]\((http[s]?:\/\/[^\) ]+)/g. To take all html link, regular expression may this form - /(http[s]?:\/\/[^ ]+)/g, not this - /http[s]?:\/\/[^ ]+/g

target.src

  • Required
  • Type : String or Array

Glob pattern to indicate files that include links for testing it is dead or not.

target.filter

  • Type : Function or Array of RegExp object
  • Default value : options.filter

Check out options.filter. It has high priority then options.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

grunt-deadlink's People

Contributors

lnyarl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.