SEO detector
A Node.js package to detect HTML SEO defects
Install
npm install seo-detector
Example
const path = require('path');
const { Detector } = require('seo-detector');
const fooExistRule = {
validate: $ => {
const errors = [];
if (!$('foo').length) errors.push('This html does not contains <foo> tag!')
return errors;
}
}
const streamDetector = new Detector({
input: path.resolve(__dirname, 'example.html'),
rules: [ fooExistRule ]
});
streamDetector.writeConsole().then(() => process.exit())
It will out put following in console
custom rule error: <foo> not exist!
Pre-defined SEO rules
- Detect if any
<img />
tag without alt attribute - Detect if any
<a />
tag without rel attribute - In
<head>
tag- Detect if header doesn’t have
<title>
tag - Detect if header doesn’t have
<meta name=“descriptions” ... />
tag - Detect if header doesn’t have
<meta name=“keywords” ... />
tag
- Detect if header doesn’t have
- Detect if there’re 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.
Use Pre-defined rules
const { Detector, preDefinedRule: {
anchorShouldWithRel,
imgShouldWithAlt,
strongLimit,
head,
H1Limit1
} } = require('seo-detector');
const detector = new Detector({
input:'path/to/file.html',
rules:[head, H1Limit1, imgShouldWithAlt, strongLimit(15)]
})
detector.writeConsole().then(() => process.exit())
API Reference
new Detector({input, rules ,logger?})
Constructor - - input : string | stream
- rules : Array<{validate: cheerioStatic => string[]}>
- logger : console-like object
.writeConsole()
: Promise<void>
Output result to console
.getReadableStream()
: Promise<stream>
Return a readable stream
.writeFile(filePath:string)
: Promise<void>
Output result to specific filepath
Development
# Install dependencies
yarn install
# Test
yarn test
# See example
yarn example