seo-tag-inspector
v1.0.1
Published
A simple npm package to check HTML SEO defect.
Readme
seo-tag-inspector
A simple npm package to check HTML SEO defect.
Getting Started
Basic usage
const SeoTagInspector = require('seo-tag-inspector')
const inspector = new SeoTagInspector()
inspector.input('example/example.html')
inspector.output(console)
inspector.run()and run node test.js will show the output on console like this:
The HTML has more than 1 <h1> tag
There is 1 <a> tag without rel
There are 2 <img> tags without alt
In <head> Tag. This HTML without <title> tag
In <head> Tag. This HTML without <meta> tag with name=keywords
The HTML has more than 1 <h2> tag
A <meta> tag with name=robots not exist.Input/Output
You can also set the input and output type. The input can be:
- file
- stream
The output can be:
- console (default)
- file
- writable stream
Default Rules
Modify config in /src/config.json
- Detect if any tag without alt attribute.
- Detect if any tag without rel attribute.
- Detect if there’re more than 15 <strong> tag in HTML
- Detect if a HTML have more than one <H1> tag.
- The tag
- Detect if header doesn’t have <title> tag
- Detect if header doesn’t have <meta name=“description” ... /> tag
- Detect if header doesn’t have <meta name=“keywords” ... /> tag
Set custom rules
inspector.tag('h2').setRule({'moreThan': 1})
inspector.tag('meta').setRule({'checkTag': ["name=robots"]})moreThan
Detect if a HTML have more than two specify tag.
inspector.tag('h2').setRule({'moreThan': 2});
// defect if html has more than 2 h2 tagoutput:
The HTML has more than 2 <h2> taglessThan
Detect if a HTML have less than three specify tag.
inspector.tag('img').setRule({'lessThan': 3});
// defect if html has less than 3 <img> tagoutput:
The HTML has less than '3' <img> tag.withoutAttr
Detect if a HTML tag without attribute.
inspector.tag('img').setRule({'withoutAttr': ['alt']})
// defect if html tag without attributeoutput:
There is 1 <img> tag without altwithoutTag
Detect if a HTML doesn’t have specify tag.
inspector.tag('meta').setRule({'withoutTag': ['name=keywords']})
// defect if html with <meta> tag with name=keywordsoutput:
This HTML without <meta> tag with name=keywordscheckTag
Detect if a HTML tag existing or not.
inspector.tag('meta').setRule({'checkTag': ["name=robots"]})
// defect if html with <meta> tag with name=robotsoutput:
A <meta> tag with name=robots not exist.