1.0.1 • Published 7 years ago
seo-tag-inspector v1.0.1
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: 1. file 2. stream
The output can be: 1. console (default) 2. file 3. writable stream
Default Rules
Modify config in /src/config.json 1. Detect if any tag without alt attribute. 2. Detect if any tag without rel attribute. 3. Detect if there’re more than 15 \ tag in HTML 4. Detect if a HTML have more than one \ tag. 5. The tag
- Detect if header doesn’t have \ 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 tag
output:
The HTML has more than 2 <h2> tag
lessThan
Detect if a HTML have less than three specify tag.
inspector.tag('img').setRule({'lessThan': 3});
// defect if html has less than 3 <img> tag
output:
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 attribute
output:
There is 1 <img> tag without alt
withoutTag
Detect if a HTML doesn’t have specify tag.
inspector.tag('meta').setRule({'withoutTag': ['name=keywords']})
// defect if html with <meta> tag with name=keywords
output:
This HTML without <meta> tag with name=keywords
checkTag
Detect if a HTML tag existing or not.
inspector.tag('meta').setRule({'checkTag': ["name=robots"]})
// defect if html with <meta> tag with name=robots
output:
A <meta> tag with name=robots not exist.