1.2.0 • Published 7 years ago
seo-validate-tool v1.2.0
seo-validate-tool
A Node.js package for scan HTML contents and show SEO defects
Installation
npm install seo-validate-tool
Input And Output
The validator supports 2 types of input objects and 3 types output objects
Input Type
- FileInput
StreamInput
Output Type
- FileOutput
- StreamOutput
- ConsoleOutput
Usage & Demo
Please refer to examples in examples folder, and check run_examples.sh, example1.js, and example1.js for the details.
Example
const {
RuleBase,
RuleTagWithoutAttribute,
RuleBasetagWithoutTag,
RuleBasetagWithoutTagAttributeValue,
RuleTagCountLimit,
Validator,
IoBase,
FileInput,
StreamInput,
FileOutput,
StreamOutput,
ConsoleOutput
} = require('seo-validate-tool')
var skipRules = [1, 4]; // rule index for skipping
var validator = new Validator(skipRules);
// A defined object "someReadableStream"
var input = new StreamInput(someReadableStream);
var output = new ConsoleOutput();
// Set up input/output
validator.setInput(input);
validator.setOutput(output);
// Validate
validator.validate()Run Demo
$ ./examples/run_examples.shPre-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.
Skip Rules
Create Validator with skipRules can define which rules to skip.
var skipRules = [1, 4]; // rule index for skipping
var validator = new Validator(skipRules);Customized rules
- Define customized rules by
class RuleBaseclass RuleTagWithoutAttributeclass RuleBasetagWithoutTagclass RuleBasetagWithoutTagAttributeValueclass RuleTagCountLimit
- Use
Validator.addRule()to add customized rules
// Add a basic customized rule: RuleHeaderWithoutAuthor
const RuleHeaderWithoutAuthor = new RuleBasetagWithoutTagAttributeValue('head', 'meta', 'name', 'author')
validator.addRule(RuleHeaderWithoutAuthor)