seo-quick-checker
A package to quickly check if the HTML is SEO friednly. It outputs the notice messages after parsing the HTML file provided.
Installation
npm i seo-quick-checker
Getting Started
1. Basic Setup
Create a project.
mkdir test
cd test
npm init
npm i
2. Create Files
Create folders and files inside the project.
touch index.js
mkdir input
touch input/index.html
mkdir output
To test out, you can copy-paste these code to index.js
and input/index.html
.
index.js
'use strict'; const defaultRules ruleBuilders getDom seoQuickChecker output = ; { try const dom = await getDom; const notices = ; await output; catch error console; };
input/index.html
<!-- no title under head --><!-- no meta description under head --><!-- no meta keywords under head --><!-- more than 1 h1 tag --><!-- more than 15 strong tags --><!-- img without alt --><!-- a without rel --> test test test test test test test test test test test test test test test test test test link
Now you can run the script.
node index.js
When it's successfully done, output/output.txt
will be created.
output/output.txt
There are(is) 1 a without rel.
This HTML does not have head meta[name=description] tag.
This HTML does not have head meta[name=keywords] tag.
This HTML does not have head title tag.
There are(is) 1 img without alt.
This HTML has more than 1 h1.
This HTML has more than 15 strong.
API Reference
List of APIs
- defaultRules module
- ruleBuilders module
- getDom module
- seoQuickChecker function
- output module
1. defaultRules module
A module contains default rule functions.
defaultRules.all
: Function[]
Return all the functions of the default rules.
defaultRulesall;//=>// [// aMissingRel,// noMetaDescriptionInHead,// noMetaKeywordsInHead,// noTitleInHead,// imgMissingAlt,// moreThan1H1,// moreThan15Strong,// ]
defaultRules.aMissingRel
: Function
Check if there are <a> tags missing rel attribute.
defaultRules.noMetaDescriptionInHead
: Function
Check if meta description exists in head.
defaultRules.noMetaKeywordsInHead
: Function
Check if meta keywords exists in head.
defaultRules.noTitleInHead
: Function
Check if title exists in head.
defaultRules.imgMissingAlt
: Function
Check if there are <img> tags missing alt attribute.
defaultRules.moreThan1H1
: Function
Check if there are more than 1 h1 tags.
defaultRules.moreThan15Strong
: Function
Check if there are more than 15 strong tags.
> Usage
If you want to check all the default rules.
const notices = ;
If you want to check, for example, defaultRules.aMissingRel
and defaultRules.noMetaDescriptionInHead
You can use []
to wrap them because each of them is the function but second param of seoQuickChecker
is an array.
const notices = ;
2. ruleBuilders module
A module to create rule functions.
ruleBuilders.tagCountMoreThan(tag, maxCount)
: Function
Create a function which checks if the number of tag is more than maxCount
params | type | description |
---|---|---|
tag | string | Required |
maxCount | number | Required. Max count of the tag. Notice will be created if the count is more than this maxCount. |
ruleBuilders.tagMissingAttr(tag, attr)
: Function
Create a function which checks if the tag is missing the attribute.
params | type | description |
---|---|---|
tag | string | Required. |
attr | string | Required. |
ruleBuilders.tagExists(tag)
: Function
Create a function which checks if the tag exists.
params | type | description |
---|---|---|
tag | string | Required. |
> Usage
If you want to use custom rules by using this module, you can write like this.
// Check if the number of h2 is more than 1.const customRule1 = ruleBuilders;// Check if span tag is missing class attribute.const customRule2 = ruleBuilders;// Check if meta[name=robot] exists in head.const customRule3 = ruleBuilders; const notices = ;
3. getDom module
Get dom
function from file or stream.
getDom.fromFile(filePath[, encoding])
: Promise<function>
Get dom function from file.
params | type | description |
---|---|---|
filePath | string | Required. |
encoding | string | Defaults to "utf8". |
getDom.fromStream(rs)
: Promise<function>
Get dom function from stream.
params | type | description |
---|---|---|
rs | stream.Readable | Required. |
4. seoQuickChecker function
Check the HTML using the rules provided. Return the notices.
seoQuickChecker(dom, rules)
: string[]
params | type | description |
---|---|---|
dom | Function | Required. The function returned from getDom.fromFile or getDom.fromStream . |
rules | Function[] | Required. An array contains the functions defined in defaultRules modules or user defined rules created by ruleBuilders module. |
5. output module
Output the notices to console.log, file, or stream.
output.toConsoleLog(notices[, connector])
: undefined
Outputs to console.log.
params | type | description |
---|---|---|
notices | string[] | Required. You can use the returning value of seoQuickChecker function. |
connector | string | Defaults to "\n". |
output.toFile(filePath, notices[, connector][, options])
: Promise<undefined>
Outputs to file.
params | type | description |
---|---|---|
filePath | string | Required. |
notices | string[] | Required. You can use the returning value of seoQuickChecker function. |
connector | string | Defaults to "\n". |
options | Object | Defaults to {} . Please see https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback for more details. |
output.toStream(ws, notices[, connector][, encoding])
: Promise<undefined>
Outputs to stream.
params | type | description |
---|---|---|
ws | stream.Writable | Required. |
notices | string[] | Required. You can use the returning value of seoQuickChecker function. |
connector | string | Defaults to "\n". |
encoding | string | Defaults to "utf8". |
More Examples
Use stream to getDom
const dom = await getDom.fromStream(rs);
Full example of index.js
.
'use strict'; const fs = ; const defaultRules ruleBuilders getDom seoQuickChecker output = ; { try const rs = fs; const dom = await getDom; const notices = ; await output; catch error console; };
Use stream to output.
await output.toStream(ws, notices);
Full example of index.js
.
'use strict'; const fs = ; const defaultRules ruleBuilders getDom seoQuickChecker output = ; { try const rs = fs; const dom = await getDom; const notices = ; const ws = fs; await output; catch error console; };
Output to console.log
output.toConsoleLog(notices);
Please be careful, there is no await
before output.toConsoleLog(notices)
.
Full example of index.js
.
'use strict'; const fs = ; const defaultRules ruleBuilders getDom seoQuickChecker output = ; { try const rs = fs; const dom = await getDom; const notices = ; output; catch error console; };
LICENSE
MIT