1.0.2 • Published 7 years ago
html-scan v1.0.2
html-scan
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
- Detect if there are any
<img />
tags withoutalt
attribute - Detect if there are any
<a />
tags withoutrel
attribute 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
- Detect if there is any header that doesn’t have
Detect if there are more than 15
<strong>
tag in HTML (15 is a value should be configurable by user)- 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
Usage
Input
- Can be a string: path to input file
const scan = require('html-scan')
scan('test/sample.html', output, options)
- 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
- Can be a null value, result will be print to console.log()
const scan = require('html-scan')
scan(input, null, options)
- Can be a string: path to output file
const scan = require('html-scan')
scan(input, 'test/output.txt', options)
- 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