A simple html scan, Pre-defined some simple rules to detect SEO. Easy to define more rule
Scan a HTML file and show all of the SEO defected
-
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.
- HTML file
- Node Readable Stream
- File
- Node Writable Stream
- Console
- 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)
- 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)
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
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
- Pass all tests
yarn test