Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #61 from pdehaan/issue-48-redux
Browse files Browse the repository at this point in the history
Convert keywords to an array
  • Loading branch information
jaredlockhart committed Sep 2, 2016
2 parents cef465e + 89f76fc commit 61c58cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ function buildRuleset(name, rules, processors) {
}

if (value) {
return value.trim();
if (value.trim) {
return value.trim();
}
return value;
}
}
};
Expand Down Expand Up @@ -82,6 +85,9 @@ const metadataRules = {
rules: [
['meta[name="keywords"]', node => node.element.getAttribute('content')],
],
processors: [
(keywords) => keywords.split(',').map((keyword) => keyword.trim()),
]
},

title: {
Expand Down
6 changes: 3 additions & 3 deletions tests/metadataRules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function ruleTest(testName, testRule, expected, testTag) {
const found = rule(doc, {
url: 'http://www.example.com/'
});
assert.equal(found, expected, `Unable to find ${testName} in ${html}`);
assert.deepEqual(found, expected, `Unable to find ${testName} in ${html}`);
});
}

Expand Down Expand Up @@ -112,10 +112,10 @@ describe('Type Rule Tests', function() {


describe('Keywords Rule Tests', function() {
const keywords = 'Cats, Kitties, Meow';
const keywords = ['Cats', 'Kitties', 'Meow'];

const ruleTests = [
['keywords', `<meta name="keywords" content="${keywords}" />`],
['keywords', `<meta name="keywords" content="${keywords.join(', ')}" />`],
];

ruleTests.map(([testName, testTag]) => ruleTest(testName, metadataRules.keywords, keywords, testTag));
Expand Down

0 comments on commit 61c58cb

Please sign in to comment.