# shopback_seo_challenge

> Let Node.js Developer use this package to scan a HTML file and show all of the SEO defects

Latest version **1.0.3** (published 2018-11-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install shopback_seo_challenge
pnpm add shopback_seo_challenge
yarn add shopback_seo_challenge
bun add shopback_seo_challenge
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-11-04 |
| First published | 2018-11-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Weiti Kuo |
| Maintainers | weiti.kuo |
| Keywords | Shopback, Challenge |

## Links

- npm: https://www.npmjs.com/package/shopback_seo_challenge
- npm.io page: https://npm.io/package/shopback_seo_challenge

## Dependencies (2)

- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.2
- [file-exists](https://npm.io/package/file-exists.md) ^5.0.1

## Recent versions

- 1.0.3 (latest) — 2018-11-04
- 1.0.2 — 2018-11-04
- 1.0.1 — 2018-11-04
- 1.0.0 — 2018-11-04

## README

<h1 align="center">ShopBack Node.js Code Challenge</h1>

### Sample Code
```js
"use strict";
const fs = require("fs");
var shopback_seo_challenge = require("shopback_seo_challenge");
var seoParser = shopback_seo_challenge.seoParser;
var ruleManager = shopback_seo_challenge.ruleManager;

// Define SEO Rules:
seoParser.addSeoRule(new ruleManager.tagWithoutAttributeRule("img", "alt"));
seoParser.addSeoRule(new ruleManager.tagWithoutAttributeRule("a", "rel"));
seoParser.addSeoRule(new ruleManager.tagWithoutChildTagRule("head", "title"));
seoParser.addSeoRule(new ruleManager.tagWithoutChildTagAndAttributeRule("head", "meta", "name", "descriptions"));
seoParser.addSeoRule(new ruleManager.tagWithoutChildTagAndAttributeRule("head", "meta", "name", "keywords"));
seoParser.addSeoRule(new ruleManager.tagWithoutChildTagAndAttributeRule("head", "meta", "name", "robots"));
seoParser.addSeoRule(new ruleManager.tagExceedsMaxRula("strong", 15));
seoParser.addSeoRule(new ruleManager.tagExceedsMaxRula("H1", 1));

// 1. Set Input Format 2. Detect SEO defects 3. Set Output Format
(async function () {
    // 1. Set Input Format: (1)loadFile() (2)loadStream()
    //var html = seoParser.loadFile('./test_files/test.html');
    //var html = seoParser.loadFile('./test_files/valid.html');    
    var html = seoParser.loadFile('./test_files/invalid.html');
    //var html = await seoParser.loadStream(fs.createReadStream('./test_files/invalid.html'));

    // 2. Get defect list by the defined SEO rules
    var defects = seoParser.detectSeoDefect(html);

    // 3. Set Output Format: (1)writeToConsole() (2)writeToFile() (3)writeToStream
    seoParser.writeToConsole(defects);
    //seoParser.writeToFile(defects, "./test_files/invalid.log");
    //seoParser.writeToStream(defects, fs.createWriteStream("./test_files/invalidStream.log"));
})();
```

### Sample Input
```html
<!DOCTYPE html>
<head>
</head>
<body>
    Test
    <p>Hello World!</p>
    <img src="" alt="alt1" />
    <img src="" alt="alt2" />
    <img src="" />
    <a href="https://tw.buy.yahoo.com" rel="re11">Link1</a>
    <a href="https://tw.buy.yahoo.com" rel='rel2'>Link2</a>
    <a href="https://tw.buy.yahoo.com">Link3</a>
    <strong>strong1</strong>
    <strong>strong2</strong>
    <strong>strong3</strong>
    <strong>strong4</strong>
    <strong>strong5</strong>
    <strong>strong6</strong>
    <strong>strong7</strong>
    <strong>strong8</strong>
    <strong>strong9</strong>
    <strong>strong10</strong>
    <strong>strong11</strong>
    <strong>strong12</strong>
    <strong>strong13</strong>
    <strong>strong14</strong>
    <strong>strong15</strong>
    <strong>strong16</strong>
    <h1>h1</h1>
    <h1>h2</h1>
</body>
</html>
```

### Sample Output
```
In this HTML, there are totally 8 SEO defects:
0. There are 1 <img> tag without alt attribute
1. There are 1 <a> tag without rel attribute
2. This HTML without <title> tag in <head> tag
3. This HTML without <meta name="descriptions"> tag in <head> tag
4. This HTML without <meta name="keywords"> tag in <head> tag
5. This HTML without <meta name="robots"> tag in <head> tag
6. This HTML have more than 15 <strong> tag
7. This HTML have more than 1 <H1> tag
```

### Installation
> npm i shopback_seo_challenge

---
_Source: https://npm.io/package/shopback_seo_challenge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
