1.0.2 • Published 7 years ago

html-scan v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

html-scan

Scrutinizer Code Quality Build Status Coverage Status Build Status

A simple html scan, Pre-defined some simple rules to detect SEO. Easy to define more rule

Features

Scan a HTML file and show all of the SEO defected

Pre-defined rules

  1. Detect if there are any <img /> tags without alt attribute
  2. Detect if there are any <a /> tags without rel attribute
  3. In <head> tag

    • Detect if there is any header that doesn’t have <title></title> tag
    • Detect if there is any header that doesn’t have <meta name="descriptions" ... /> tag
    • Detect if there is any header that doesn’t have <meta name="keywords" ... /> tag
  4. Detect if there are more than 15 <strong> tag in HTML (15 is a value should be configurable by user)

  5. Detect if a HTML have more than one <h1> tag.

Support Input

  • HTML file
  • Node Readable Stream

Support Output

  • File
  • Node Writable Stream
  • Console

Installation

  • Using yarn yarn add --dev html-scan

  • Using npm npm install --save-dev html-scan

Usage

Input

  1. Can be a string: path to input file
const scan = require('html-scan')

scan('test/sample.html', output, options)
  1. Can be a node Readable
const Readable = require('stream').Readable

const scan = require('html-scan')

const readStream = new Readable()
readStream._read = () => {} // To prevent cash when not implement _read
readStream.push('input data')
scan(readStream, output, options)

Output

  1. Can be a null value, result will be print to console.log()
const scan = require('html-scan')

scan(input, null, options)
  1. Can be a string: path to output file
const scan = require('html-scan')

scan(input, 'test/output.txt', options)
  1. Can be a node Writeable
const fs = require('fs')

const scan = require('html-scan')

const writeStream = fs.createWriteStream('test/output.txt')
scan(input, writeStream, options)

Options

To override the default config

{
    rules: {
        h1: { threadhold: 1 },
        strong: { threadhold: 15 }
    },
    order: ['a', 'h1', 'head', 'img', 'strong'],
    path: 'rules'
}
  • rules (object): Extra parameter which will send to the rule. The object key must exactly the same with rule name
  • order (array): An array that define the order of rule will going to run. If any rule that not list in here, it will Not run
  • path (string): path to defined rules

Add more rule

Simply add an module to rules directory

module.exports = ($, options) => {
  ...
  if (...) {
      return 'Message here...'
  } else {
      return null
  }
}
  • $ is a Cheerio object
  • options is extra paramenter for the rule in config

Contributing

  • Pass all tests yarn test