1.0.0 • Published 6 years ago

trista-seo-detector v1.0.0

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

ShopBack Node.js Code Challenge

npm i trista-seo-detector

Example

import SEODetector from 'trista-seo-detector';
import config from './config.json';

const seoDetector = new SEODetector(config);
seoDetector.detectFromFile(
    'example.html',
    ['img', 'a', 'head', 'strong', 'h1'],
    rs => {
        // output: file
        seoDetector.output(rs, 'file', 'result.txt');

        // output: console
        seoDetector.output(rs, 'console');

        // output: stream
        const ws = seoDetector.output(rs, 'stream');
    }
);

API

SEODetector(config)

detectFromFile(filePath, rules, callback) : void

detectFromStream(readableStream, rules, callback) : void

output(result, type, path) : void | if type is stream will return Node Writable Stream)

Implement additional rule

Ex: Checking < meta name="robots" / > existing or not ?!

in src/rules.js
export const metaRules = () => {
    return [
        {
            group: 'meta',
            name: 'description',
            rule: /^<meta.*name="description".*content=".+"+.*\/>/i,
            description: 'This html doesn’t have <meta name="descriptions" ... /> tag',
            comparison: 'eq',
            comparison_value: 0,
            match: true
        },
        {
            group: 'meta',
            name: 'keywords',
            rule: /^<meta.*name="keywords".*content=".+"+.*\/>/i,
            description: 'This html doesn’t have <meta name="keywords" ... /> tag',
            comparison: 'eq',
            comparison_value: 0,
            match: true
        }
    ];
};

just add a object contain below property: