1.0.0 • Published 5 years ago

@qeshion2104/seo-analyzer v1.0.0

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

SeoAnalyzer

An analyzer for analyze html file

How to install

npm install @qeshion2104/SeoAnalyzer --save

Example

Here's a quick example: we analyze some html

import * as path from 'path';
var SA = require("@qeshion2104/SeoAnalyzer");
function main() {
	let  seoAnalyzer  =  new  SA.SeoAnalyzer({
		// there are five baisc rule for use, if not set will use all of them as default
		useBasicRule: [
			SA.BASIC_SEO_RULE.A_WITHOUT_REL_TAG,
			SA.BASIC_SEO_RULE.HAVE_H1,
			SA.BASIC_SEO_RULE.MANY_STRONG
		],
		// custom setting of MANY_STRONG 
		manyStrongCounter:  5,
	});

	seoAnalyzer.load(path.join(__dirname, "./testData/simpleWeb.html"));
}

To custom your rule, you can set your own analysis rule, output rule and custom setting

// detect if <meta name="<name>" /> is existing or not
seoAnalyzer.addRule({
	/** rule to detect html then return a object to save for output */
	analyzeRule: (html:string, customSetting:any)=>{
		let rule = new RegExp(`<meta name="${customSetting.name}" \/>`, "g");
		// let rule=/<meta name="robots" \/>/g;
		let match = rule.test(html);
		return {
			haveRobots: match,
			name: customSetting.name,
		}
	},
	/** outputRule, use rule data to generate output */
	outputRule: (data:any)=>{
		console.log(`<meta name="${data.name}" /> ${ data.haveRobots ? "is existing" : "is not existing" } `);
	},
	/** some special setting for this rule */
	customSetting: {
		name: "robots",
	},
});

License

ISC licensed. See the LICENSE file for detail.