这是indexloc提供的服务,不要输入任何密码
Skip to content

huangc28/seo-niffler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

seo-niffler

Tool to detect SEO defects in your html scripts.

Config

The config provided to Niffler can be either an object specifying a single rule order array of object that specifies multiple rules.

Input source

The input source can be either file path or readable stream.

const nif = new Niffler({
  input: '/path/to/html',
})

// Or

const nif = new Niffler({
  input: fs.createReadStream('/path/to/html')
})

Output destination

const nif = new Niffler({
  input: ...,
  output: '/path/to/dest'
})

// Or

const nif = new Niffler({
  input: ...,
  output: fs.createWriteStream('/path/to/dest'),
})

Define niffler rules

// You can specify single rule by providing rule object.
const nif = new Niffler({
  input: ...,
  rules: {
    mode: Niffler.HasNoAttr,
    tag: 'img',
    attribute: 'alt',
  },
})

nif.detect()

// Or, you can specify multiple rules by providing array of rule objects.
const nif = new Niffler({
  input: ...,
  rules: [
    {
      mode: Niffler.HasNoAttr, // Detect the number of img tags without specifying "alt" attribute
      tag: 'img',
      attribute: 'alt',
    },
    {
      mode: Niffler.HasNoAttr, // Detect the number of a tags without specifying "rel" attribute
      tag: 'a',
      attribute: 'rel',
    }
  ]
})

nif.detect()

Apply rules only within constraint tag region

You can also apply rules within a specified tag region instead of applying rules globally.

const nif = new Niffler({
  input: ...,
  rules: [
    {
      mode: Niffler.Constraint, // Constrains the following rules within the provided context. In this case is <head> ... </head>.
      tag: 'head',
      rules: [
        {
          mode: Niffler.TagExists, // Check if <title> </title> exists at least once.
          tag: 'title',
        },
        {
          mode: Niffler.HasNoAttrWithValue, // Get the number of meta tags that has no attribute of "name='description'"
          tag: 'meta',
          attribute: 'name',
          value: 'description',
        }
        {
          mode: Niffler.HasNoAttrWithValue, // Get the number of meta tags that has no attribute of "name='keywords'"
          tag: 'meta',
          attribute: 'name',
          value: 'keywords',
        }
      ]
    }
  ]
})

nif.detect()

The mode 'HasNoAttrWithValue' also considers the case when specified attribute does not present in the given tag.

Check the number of tag existence within constraint.

const nif = new Niffler({
  input: ...,
  output: ...,
  rules: [
    {
      mode: Niffler.TagNumberGreaterThan,
      limit: 15,
      tag: 'strong',
    },
    {
      mode: Niffler.TagNumberGreaterThan,
      limit: 1,
      tag: 'h1',
    },
  ],
})

nif.detect()

TODO

  • There should be a rule validator. If argument provided is not defined, simply throws an error.

About

Tool to detect SEO defects in your html scripts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published