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 #107 from farhanpatel/case-insensitive
Browse files Browse the repository at this point in the history
Change description/icon/keywords metatag rules to be case insensitive
  • Loading branch information
farhanpatel authored Dec 10, 2018
2 parents 4c47515 + dc48843 commit 73dfd06
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"babel-preset-es2015": "^6.14.0",
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"domino": "^1.0.25",
"domino": "^2.1.0",
"eslint": "^2.13.1",
"eslint-plugin-mozilla": "^0.0.3",
"istanbul": "^0.4.4",
Expand Down
6 changes: 3 additions & 3 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ const metadataRuleSets = {
description: {
rules: [
['meta[property="og:description"]', element => element.getAttribute('content')],
['meta[name="description"]', element => element.getAttribute('content')],
['meta[name="description" i]', element => element.getAttribute('content')],
],
},

icon: {
rules: [
['link[rel="apple-touch-icon"]', element => element.getAttribute('href')],
['link[rel="apple-touch-icon-precomposed"]', element => element.getAttribute('href')],
['link[rel="icon"]', element => element.getAttribute('href')],
['link[rel="icon" i]', element => element.getAttribute('href')],
['link[rel="fluid-icon"]', element => element.getAttribute('href')],
['link[rel="shortcut icon"]', element => element.getAttribute('href')],
['link[rel="Shortcut Icon"]', element => element.getAttribute('href')],
Expand Down Expand Up @@ -117,7 +117,7 @@ const metadataRuleSets = {

keywords: {
rules: [
['meta[name="keywords"]', element => element.getAttribute('content')],
['meta[name="keywords" i]', element => element.getAttribute('content')],
],
processors: [
(keywords, context) => keywords.split(',').map((keyword) => keyword.trim())
Expand Down
20 changes: 20 additions & 0 deletions tests/getMetadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ describe('Get Metadata Tests', function() {
assert.equal(metadata.url, sampleUrl, `Unable to find ${sampleUrl} in ${JSON.stringify(metadata)}`);
});

it('it fetches keywords, icon and description from uppercased metadata property titles', () => {
const relativeHtml = `
<html>
<head>
<meta name="Description" content="${sampleDescription}" />
<meta name="Keywords" content="${sampleTitle}" />
<link rel="Icon" href="/favicon.ico" />
</head>
</html>
`;

const doc = stringToDom(relativeHtml);
const metadata = getMetadata(doc, sampleUrl, metadataRuleSets);

assert.equal(metadata.icon, sampleIcon, `Unable to find ${sampleIcon} in ${relativeHtml}`);
assert.equal(metadata.description, sampleDescription, `Unable to find ${sampleDescription} in ${relativeHtml}`);
assert.equal(metadata.keywords, sampleTitle, `Unable to find ${sampleTitle} in ${relativeHtml}`);

});

it('allows custom rules', () => {
const doc = stringToDom(sampleHtml);
const rules = {
Expand Down

0 comments on commit 73dfd06

Please sign in to comment.