1.1.6 • Published 5 years ago

seomonkey v1.1.6

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

SeoMonkey

This monkey tool will help detect your html tags or content by pre-define rules. Hope for fun

Tips

If you use VsCode our package has typing file. Makesure you can develop more easy, You can add //@ts-check on your js file Learn more here

Important

If you want default class can use typing file to checking type. You need change require('seomonkey).default to require('seomonkey).SeoMonkey

Demo

Prerequisites

Makesure you're use NodeJs version 8 and above You can download from here

Install

$ npm i seomonkey

How to play with SeoMonkey

Before start play, You need add config file on project root path. Usually call seomonkey.config.json

semonkey.config.js

{
    "DetectedText":"{RuleName} are match  {Num} of elements,Mini:{Minimum} Max:{Maximum}",
    "MonkeyRules":[
        {
            "RuleName": "MonkeyRule1",
            "SearchRule":"head > title",
            "Minimum" : 1,
            "Maximum":1,
            "DetectedText":"Your {RuleName} is Match {Num} of elements"
        },
        {
            "RuleName":"MonkeyRule2",
            "SearchRule":"img:not([alt])",
            "Maximum":2
        },
        {
            "RuleName":"MonkeyRule3",
            "SearchRule":"head > meta[name='descriptions']",
            "Maximum":1
        },
        {
            "RuleName":"MonkeyRule4",
            "SearchRule":"head > meta[name='keywords']",
            "Maximum":1
        },
        {
            "RuleName":"MonkeyRule5",
            "SearchRule":"strong",
            "Maximum":15
        },
        {
            "RuleName":"MonkeyRule6",
            "SearchRule":"h1",
            "Maximum":1
        }
    ]
}

Config definition

  • DetectedText: (required) Which content and information you want to monkey told you
    • you can replace common detected text by add it to monkeyrules,Please see the MonkeyRule1
    • For got more information,You can use expression on your detected text
      • {RuleName} : Will replace by monkey rule name.
      • {Num} : Will replace by how many html elements is fit the rule.
      • {Minimum} : Will replace by monkey rule definition minimum elements.
      • {Maximum} : Will replace by monkey rule definition maximum elements.
  • MonkeyRules: (required) All of your rules want to monkey search.
    • RuleName: (required) Your favorite rule name.
    • SearchRule: (required) Write the rule by use CSS-Selector.If you're not familer with this please refer this
    • Minimum: Definition minimum elements should be match by rule.If not .The detected text will add Warning to remind you. Default: 0
    • Maximum: Definition maximum elements should be match by rule.If not .The detected text will add Warning to remind you Default: 0
    • DetectedText: Like common detected text.But this content will overwrite it

Usage

Easy example

    const SeoMonkey = require('seomonkey').default;
    const HtmlSource = require('seomonkey').HtmlSource;

    // Init your monkey
    const monkey = new SeoMonkey();
    // Set your source for detect
    monkey.inputSource = new HtmlSource('test.html');
    // Run the save method and get the result
    monkey.saveResultToConsole();

Input Source Definition

  • HtmlSource : This source is let you can input html file path as source.
  • StreamSource: This source is let you can input custom stream as source.

HtmlSource example

You can choose which outputs you want

    const fs = require('fs')
    const SeoMonkey = require('seomonkey').default;
    const HtmlSource = require('seomonkey').HtmlSource;

    const monkey = new SeoMonkey();
    monkey.inputSource = new HtmlSource('test.html');
    // Print result to console
    monkey.saveResultToConsole();
    // Save result as stream
    let writerStream = fs.createWriteStream('output.txt');
    monkey.saveResultToStream(writerStream);
    // Save result to file  
    monkey.saveResultToFile('demo.txt');

StreamSource example

    const fs = require('fs')
    const SeoMonkey = require('seomonkey').default;
    const StreamSource = require('seomonkey').StreamSource;

    const monkey = new SeoMonkey();
    const readableStream = fs.createReadStream(filePath);
    let stream =   new StreamSource(readableStream);
    monkey.inputSource = stream;
    // Print result to console
    monkey.saveResultToConsole();
    // Save result as stream
    let writerStream = fs.createWriteStream('output.txt');
    monkey.saveResultToStream(writerStream);
    // Save result to file  
    monkey.saveResultToFile('demo.txt');

Change Rule in code example

Add new rule

    const fs = require('fs')
    const SeoMonkey = require('seomonkey').default;
    const HtmlSource = require('seomonkey').HtmlSource;

    const monkey = new SeoMonkey();
    // Add new detect rule (The rule will push to the end of rules)
    let rule = new MonkeyRule();
    rule.DetectedText='Hello';
    rule.Maximum=1;
    rule.Minimum=1;
    rule.RuleName='This is new Rule';
    rule.SearchRule='head'
    monkey.config.addRule(rule);
    monkey.inputSource = new HtmlSource('test.html');
    // Print result to console
    monkey.saveResultToConsole();

clearAllRule

    const fs = require('fs')
    const SeoMonkey = require('seomonkey').default;
    const HtmlSource = require('seomonkey').HtmlSource;
    const monkey = new SeoMonkey();
    monkey.config.clearAllRule();
    monkey.inputSource = new HtmlSource('test.html');
    // will not export any result to console. because rules is empty
    monkey.saveResultToConsole();

removeRuleAt

    const fs = require('fs')
    const SeoMonkey = require('seomonkey').default;
    const HtmlSource = require('seomonkey').HtmlSource;
    const monkey = new SeoMonkey();
    monkey.config.removeRuleAt(4);
    monkey.inputSource = new HtmlSource('test.html');
    // MonkeyRule4 is removed ,So detected result and output will not include 
    monkey.saveResultToConsole();
1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago