1.0.0 • Published 5 years ago

shopback-seo v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

shopback-seo NPM version Build Status

used to valid html content

Installation

$ npm install --save shopback-seo

Usage sample

Input is file path

const SeoValidator = require('shopback-seo');
var output =  process.stdout;
var input = __dirname+'/test.html';
var seoValidator = new SeoValidator(input,output);
var rule = [
  {
      "rule":"attrib",
      "tag":"a",
      "attribute":"rel"
  }
];
seoValidator.addRules(rule).valid();
done();

Input is writable stream

const SeoValidator = require('shopback-seo');
var output =  process.stdout;
var rs = fs.createReadStream(__dirname+'/test.html');
rs.setEncoding('utf8');
var seoValidator = new SeoValidator(rs,output);
var rule = [
  {
      "rule":"attrib",
      "tag":"a",
      "attribute":"rel"
  }
];
seoValidator.addRules(rule).valid();
done();

Rules setting

/*
  rule property can be attrib, tagMax, hierarchy,tagMin,
  each rule has its relative property, please refer to the
  following sample.

  // attrib rule need to have tag, attribute property. It can be
   use for valid the attribute and value of attribute on the
   specified tag.

  // tagMax rule need to have tag, max property. It can be use
   for valid the tag occurrance.

  // hierarchy rule need to have tag, rules property. It can be
   use for valid complex rule inside the specified html tag.

   //tagMin rule need to have mandatory tag, attribute, min property
*/
var rule = [
  {
      "rule":"attrib",
      "tag":"a",
      "attribute":"rel"
  },{
      "rule":"attrib",
      "tag":"img",
      "attribute":"alt"
  },{
      "rule":"tagMax",
      "tag":"strong",
      "max":1
  },{
    "rule":"tagMax",
    "tag":"h1",
    "max":1
  },{
    "rule":"hierarchy",
    "tag":"head",
    "rules":[
        {
          "rule":"tagMin",
          "tag":"title",
          "min":1
        },{
          "rule":"tagMin",
          "tag":"meta",
          "attribute":"name",
          "attributeValue":"descriptions",
          "min":1
        },{
          "rule":"tagMin",
          "tag":"meta",
          "attribute":"name",
          "attributeValue":"keywords",
          "min":1
        }
    ]
  }
];

License

ISC © thomas.chuang