1.0.5 • Published 1 year ago

@jackchang/seo_check v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

seo_check

Notes:

##Development environment

Nodejs: v10.6.0
NPM : 6.4.1

##description a simple tool to scan file/stream for defeats

  • support input: ReadStream / file path
  • support output: WriteStream / file path / log
  • easy to register customize SEO check rules

##installation npm install @jackchang/seo_check

usage

load with file path

//include module
const seo_check = require('@jackchang/seo_check');

//register new SEO rule
seo_check.ExtendRule({tagname:"h2",ruleName:"checkh2"});
seo_check.ExtendRule({tagname:"meta",ruleName:"checkMetaAttrRobots",attrname:"name",attrvalue:"robots"});


//new instance
var seoObj = new seo_check({maxStrongTagCount:4});

//load file with path & set check rule
seoObj.loadHtmlContent(__dirname + '/test.html',seo_check.fileType.FILE).then(()=>{

    seoObj.checka()
        .checkh2()
        .checkh1()
        .checkimg()
        .checkstrong()
        .checkhead()
        .checkMetaAttrRobots()
        .GenerateReport(seo_check.fileType.FILE,filepath,filename);

});

#output

result

example passed log:

The <img> tag alt attribute is pass.
The <a> tag rel attribute is pass.
This head have <title> tag.
This head have <meta name='description'> tag.
This head have <meta name='keyword'> tag.
This HTML have more than 5 <strong> tag.
This HTML have more than 1 <h1> tag.
This HTML have <h2> tag.
This HTML have meta tag attribute key=name value=robots.

example error log:

There are 15 <img> without alt attribute.
There are 128 <a> without rel attribute.
This head haven't <title> tag.
This head haven't <meta name='description'> tag.
This head haven't <meta name='keyword'> tag.
This HTML haven't more than 5 <strong> tag.
This HTML haven't more than 1 <h1> tag.
This HTML have <h2> tag.
This HTML haven't meta tag attribute key=name value=robots.

#options

namedescriptiontypedefault
maxStrongTagCountmax count for strong tag (>=)int15

#API table

table of contents

API

##init ####seo_check new with a constructor

//include module
const seo_check = require('@jackchang/seo_check');

//new instance
const checker = new seo_check({maxStrongTagCount:4});

enum

####fileType

output option

  • FILE: use a file path for output
  • STREAM: use a WriteStream for output
  • CONSOLE: use console for output

##load ####loadHtmlContent

#####parameter

namevaluedescription
pathstringfile path
fileTypeseo_check.fileType.(FILE or STREAM)File or ReadStream

#####usage

//include module
const seo_check = require('@jackchang/seo_check');

//new instance File
const checker = new seo_check({maxStrongTagCount:4});
checker.loadHtmlContent(path,seo_check.fileType.FILE).then(()=>{
    ...
});
//include module
const seo_check = require('@jackchang/seo_check');

//new instance STREAM
const checker = new seo_check({maxStrongTagCount:4});
checker.loadHtmlContent(path,seo_check.fileType.STREAM).then(()=>{
    ...
});

##check APIs ####checkstrong

usage

check rule: Detect if there’re more than 15 <strong> tag in HTML, you can modify the max by setting options maxStrongTagCount

var checker = new seo_check({maxStrongTagCount:4});
checker.loadHtmlContent(__dirname + '/test.html').then(()=>{
    checker.checkstrong();
});

####checkimg

usage

check rule: Detect if any <img /> tag without alt attribute

checker.loadHtmlContent(__dirname + '/test.html').then(()=>{
    checker.checkimg();
});

####checka

usage

Detect if any <a /> tag without rel attribute

checker.loadHtmlContent(__dirname + '/test.html').then(()=>{
    checker.checka();
});

####checkhead

usage

In <head> tag

  1. Detect if header doesn’t have <title> tag
  2. Detect if header doesn’t have <meta name="description" ... /> tag
  3. Detect if header doesn’t have <meta name="keywords" ... /> tag
checker.loadHtmlContent(__dirname + '/test.html').then(()=>{
    checker.checkhead();
});
<meta name="descriptions"/> (with s)

####checkh1

usage

Detect if a HTML have more than one <H1> tag.

checker.loadHtmlContent(__dirname + '/test.html').then(()=>{
    checker.checkh1();
})

##register customize check API

seo_check.ExtendRule

#####parameters | Paramname | description | type | default | |-----------|----------------------------------------|--------|--------------------------------------------------| | ruleName | rule API name | string | no, will overwite registration if name exist | | tagname | valid html tagname | string | no, Required | | attrname | valid tag has attr's name | string | Optional | | attrvalue | valid tag has attr's value | string | Optional |

#####usage a static API to register a global check rule

to register

const seo_check = require("../index");

seo_check.ExtendRule({tagname:"h2",ruleName:"checkh2"});
seo_check.ExtendRule({tagname:"meta",ruleName:"checkMetaAttrRobots",attrname:"name",attrvalue:"robots"});

to use

//new instance
const checker = new seo_check({debug:false, maxStrongTagCount: 18});

//load file with readable stream and apply rule checkRobotMeta. The call method no order.

checker.loadHtmlContent(__dirname + '/test.html',seo_check.fileType.STREAM).then(()=>{

    checker.checka()
        .checkh2()
        .checkh1()
        .checkimg()
        .checkstrong()
        .checkhead()
        .checkMetaAttrRobots()
        .GenerateReport(seo_check.fileType.STREAM,filepath,filename);

});

/*output:
-------------------------
This HTML have <h2> tag.
This HTML have meta tag attribute key=name value=robots.
*/

##Report ####GenerateReport

usage

use to finish check and Generate Report.

When check rule finish. Call GenerateReport to Render reoprt.

paramvalueTypedescriptiondefault
SavePathstringSaveFilePathRequired
FilenamestringSaveFileNameRequired
fileTypeseo_check.fileTypeSTREAM,FILE,CONSOLERequired
checker.loadHtmlContent(__dirname + '/test.html',seo_check.fileType.STREAM).then(()=>{

    checker.checka()
        .checkh2()
        .checkh1()
        .checkimg()
        .checkstrong()
        .checkhead()
        .checkMetaAttrRobots()
        .GenerateReport(seo_check.fileType.STREAM,filepath,filename).then(()=>{
            ...
        });
});
1.0.5

1 year ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago