1.0.1 • Published 6 years ago

shopback-challenge-ryder v1.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago
使用方法
var app = require('../app');
var detectAnyTagsWithoutAttrRule = require('../PreDefinedSeoRules/DetectAnyTagsWithoutAttr');
var detectAnyTagsWithChildTagRule = require('../PreDefinedSeoRules/DetectAnyTagsWithChildTag');
var detectAnyTagsWithChildTagWithAttrAndValueRule = require('../PreDefinedSeoRules/DetectAnyTagsWithChildTagWithAttrAndValue');
var detectAnyTagsHaveNumberTagsRule = require('../PreDefinedSeoRules/DetectAnyTagsHaveNumberTags');

// 載入指定的 Html 檔案
var html = app.loadFile('test.html');
// 檢查是否有 <img> tag 沒有 alt 的屬性
app.addSeoRule(new detectAnyTagsWithoutAttrRule.DetectAnyTagsWithoutAttr('img', 'alt'));
// 檢查是否有 <a> tag 沒有 rel 的屬性
app.addSeoRule(new detectAnyTagsWithoutAttrRule.DetectAnyTagsWithoutAttr('a', 'rel'));
// 檢查是否有 <head> tag 有子 <title> tag
app.addSeoRule(new detectAnyTagsWithChildTagRule.DetectAnyTagsWithChildTag('head', 'title'));
// 檢查是否有 <head> tag 有子 <meta> tag,其有 name 的屬性與 descriptions 的值
app.addSeoRule(new detectAnyTagsWithChildTagWithAttrAndValueRule.DetectAnyTagsWithChildTagWithAttrAndValue('head', 'meta', 'name', 'descriptions'));
// 檢查是否有 <head> tag 有子 <meta> tag,其有 name 的屬性與 keywords 的值
app.addSeoRule(new detectAnyTagsWithChildTagWithAttrAndValueRule.DetectAnyTagsWithChildTagWithAttrAndValue('head', 'meta', 'name', 'keywords'));
// 檢查是否有超過 15 個 <strong> tag
app.addSeoRule(new detectAnyTagsHaveNumberTagsRule.DetectAnyTagsHaveNumberTags('strong', 15));
// 檢查是否有超過 1 個 <H1> tag
app.addSeoRule(new detectAnyTagsHaveNumberTagsRule.DetectAnyTagsHaveNumberTags('H1', 1));

// 以指定的檢查 Seo 規則解析 HTML 檔案
app.parseHtml(html);

事先定義好的 SEO 檢查規則

  1. Detect if any <img /> tag without alt attribute.
  2. Detect if any <a /> tag without rel attribute.
  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
  4. Detect if there’re more than 15 <strong> tag in HTML (15 is a value should be configurable by user).
  5. Detect if a HTML have more than one <H1> tag.

輸出內容

這 HTML 沒有 <img> tag 沒有 alt 屬性。
這 HTML 沒有 <a> tag 沒有 rel 屬性。
這 HTML 沒有 <head> tag 與子 `<title>` tag。
這 HTML 有指定的 <head> tag 與子 <meta> tag 有 name=descriptions 屬性與其值。
這 HTML 有指定的 <head> tag 與子 <meta> tag 有 name=keywords 屬性與其值。
這 HTML 沒有超過 15 個 <strong> tag。
這 HTML 沒有超過 1 個 <H1> tag。

Installation

npm i shopback-challenge-ryder