1.0.1 • Published 7 years ago

seo-defect-detector v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

A simple module to detect SEO defects.


Installation

$ npm install seo-defect-detector

In Node.js:

const defectDetector = require('seo-defect-detector');

//Create rule list from 5 default rules
const DefaultRule = defectDetector.DefaultRule; 
const rules = [
    DefaultRule.aWithoutRef,
    DefaultRule.imgWithoutAlt,
    DefaultRule.headChild,
    DefaultRule.fifteenStrong,
    DefaultRule.oneH1
];

const detector = defectDetector.SEODefectDetector(rules);
detector.check('./test/data/index.htm');

Usage:

Define Rule:

defectDetector.RuleBuilder('tagName')
          .wihout('attribute')
          .hasChild('chilTagName', { name: 'attributeName', value: 'attributeValue' })
          .count(maxCount)
          .build();


DefaultRule: {
      aWithoutRef: RuleBuilder('a').without('ref').build(),
      imgWithoutAlt: RuleBuilder('img').without('alt').build(),
      fifteenStrong: RuleBuilder('strong').count(15).build(),
      oneH1: RuleBuilder('h1').count(1).build(),
      headChild: RuleBuilder('head')
          .hasChild('meta', { name: 'name', value: 'descriptions' })
          .hasChild('meta', { name: 'name', value: 'keywords' })
          .hasChild('title').build()
  }
  • tagName - name of tag to check
  • wihout - check wihout attrbiute
  • hasChild - check if a parent tag has a child tag
  • count - check if HTML page has more than maxCount tag

Detector:

// create a detector 
const detector = defectDetector.SEODefectDetector(rules);
//check
detector.check(inputFilePath) // output is console 
detector.check(inputFilePath, outputFilePath)
detector.check(inputFilePath, outputStream)

detector.check(inputStream) // output is console 
detector.check(inputStream, outputFilePath)
detector.check(inputStream, outputStream)
//main function 
SEODefectDetector.check(input, output, callback)

Input can be:

  • HTML file path
  • Node Readable Stream

Output can be:

  • A file
  • Node Writable Stream
  • Console (default)

callback is called after check is finished

Output:

There are 3 <a> tag(s) without ref attribute.
There are 1 <img> tag(s) without alt attribute.
<head> tag does not have child <meta [name="descriptions"]> tag.
<head> tag does not have child <meta [name="keywords"]> tag.
<head> tag does not have child <title> tag.
There are more than 15 <strong> tag(s) in this HTML.
There are more than 1 <h1> tag(s) in this HTML.