shopback-seo-parser v1.0.1
General
Environment
Windows
Linux Based OS Ubuntu/Debian
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
Linux Based OS CentOS/Redhat
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y nodejs
Demo
npm install && npm start
Usage
npm install shopback-seo-parser --saveFile path
        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser();
        parser.parse('./template.html')
            .then((result)=>{
                //Get result.
            });Stream
        const fs = require('fs');
        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser();
        fs.createReadStream('./template.html')
            .pipe(parser)
            .pipe(process.stdout); 
            //resultAsync
        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser();
        let result = await parser.parse('./template.html');
        //resultDefaults rules
./rules/pre-defined-rules.js
	const rules = [
    /**
     * 1. Detect if any <img /> tag without alt attribute
    */
    {
        tag: {
            include: 'img',
        },
        attrs: {
            without: {
                alt: undefined
            }
        }
    },
    /**
     * 2. Detect if any <a /> tag without rel attribute
    */
    {
        tag: {
            include: 'a',
        },
        attrs: {
            without: {
                rel: undefined
            }
        }
    }, 
    
    /**
     * 3. In <head> tag
     *    i. Detect if header doesn’t have <title> tag
     *    ii. Detect if header doesn’t have <meta name=“descriptions” ... /> tag
     *    iii. Detect if header doesn’t have <meta name=“keywords” ... /> tag
    */
    {
        scope: 'head',
        tag: {
            include: 'title',
        }
    }, 
    {
        scope: 'head',
        tag: {
            exclude: 'img',
        },
        attrs: {
            with: {
                name: 'description'
            }
        }
    }, {
        scope: 'head',
        tag: {
            exclude: 'img',
        },
        attrs: {
            with: {
                name: 'keywords'
            }
        }
    }, 
    
    /**
     * 4. Detect if there’re more than 15 <strong> tag in HTML (15 is a value should be
configurable by user)
    */
    
    {
        tag: {
            include: 'strong',
        },
        condition: {
            '>': 15
        }
    }, 
    
    /**
     * 5. Detect if a HTML have more than one <H1> tag.
    */
    
    {
        tag: {
            include: 'H1',
        },
        condition: {
            '>': 1
        }
    }
];Speciffy default rules
- Specify default rules by number array.
        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser({
            defaultRules:[1,3,5]
        });
        parser('./template.html')
            .then((result)=>{
                //Get result.
            });Customize rules
- Rule format : This mean find the tag img without alt attribute more than 10 tags.
    {
        "tag": {
            "include": "img"
        },
        "attrs": {
            "without": {
                "alt": "undefined"
            }
        },
        "condition": {
            ">": 10        
        }
    }- Set customize rules.
    const customizeRules = [
        {
            "tag": {
                include: "img"
            },
            attrs: {
                without: {
                    "alt": undefined
                }
            },
            condition: {
                ">": 10        
            }
        }
    ];
    const ShopbackSEOParser = require('shopback-seo-parser');
    const parser = new ShopbackSEOParser({
        rules: customizeRules
    })
    parser.parse('./template.html')
        .then((result)=>{
                //Get result.
        });Development
git clone https://github.com/ssuio/shopback-SEO-parser
npm install
npm testcurrent active branch: development
Project Structure
├models
│ ├html-parser.js
│ ├result-parser.js
│ ├rules-handler.js
│ ├shopback-seo-parser.js
├rules
│ ├customize-rules.js
│ ├pre-defined-rules.js
├error
│ ├sb-seo-errors.js
│ ├config-errors.js
│ ├rule-errors.js
│ ├parse-errors.js
├demo
├test
│ ├result-parser.mocha.js
│ ├shopback-seo-parser.mocha.js
│ ├templates.js
├index.js
├package.json
├README.md
├eslintrc.json
├LICENSE
UnitTest
Run specified test
step1 install mocha globally
npm install mocha -gstep2 run specified test
mocha <filepath>.mocha.jsRun all test suite
npm testAuthor: Noah
LastUpdated: 8/31/2018 04:56:12 PM