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

Commit

Permalink
Merge branch 'master' of github.com:mozilla/page-metadata-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlockhart committed Aug 19, 2016
2 parents 518e5f6 + 23d758a commit 3a6a13b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const iconRules = buildRuleset('icon', [
]);

const imageRules = buildRuleset('image', [
['meta[property="og:image:secure_url"]', node => node.element.content],
['meta[property="og:image:url"]', node => node.element.content],
['meta[property="og:image"]', node => node.element.content],
['meta[property="twitter:image"]', node => node.element.content],
['meta[name="thumbnail"]', node => node.element.content],
Expand Down
11 changes: 7 additions & 4 deletions tests/getMetadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const {stringToDom} = require('./test-utils');
describe('Get Metadata Tests', function() {
const sampleDescription = 'A test page.';
const sampleIcon = 'http://www.example.com/favicon.ico';
const sampleImage = 'http://www.example.com/image.png';
const sampleImageHTTP = 'http://www.example.com/image.png';
const sampleImageHTTPS = 'https://www.example.com/secure_image.png';
const sampleTitle = 'Page Title';
const sampleType = 'article';
const sampleUrl = 'http://www.example.com/';
Expand All @@ -16,7 +17,9 @@ describe('Get Metadata Tests', function() {
<head>
<meta property="og:description" content="${sampleDescription}" />
<link rel="icon" href="${sampleIcon}" />
<meta property="og:image" content="${sampleImage}" />
<meta property="og:image" content="${sampleImageHTTP}" />
<meta property="og:image:url" content="${sampleImageHTTP}" />
<meta property="og:image:secure_url" content="${sampleImageHTTPS}" />
<meta property="og:title" content="${sampleTitle}" />
<meta property="og:type" content="${sampleType}" />
<meta property="og:url" content="${sampleUrl}" />
Expand All @@ -30,7 +33,7 @@ describe('Get Metadata Tests', function() {

assert.equal(metadata.description, sampleDescription, `Unable to find ${sampleDescription} in ${sampleHtml}`);
assert.equal(metadata.icon_url, sampleIcon, `Unable to find ${sampleIcon} in ${sampleHtml}`);
assert.equal(metadata.image_url, sampleImage, `Unable to find ${sampleImage} in ${sampleHtml}`);
assert.equal(metadata.image_url, sampleImageHTTPS, `Unable to find ${sampleImageHTTPS} in ${sampleHtml}`);
assert.equal(metadata.title, sampleTitle, `Unable to find ${sampleTitle} in ${sampleHtml}`);
assert.equal(metadata.type, sampleType, `Unable to find ${sampleType} in ${sampleHtml}`);
assert.equal(metadata.url, sampleUrl, `Unable to find ${sampleUrl} in ${sampleHtml}`);
Expand Down Expand Up @@ -74,7 +77,7 @@ describe('Get Metadata Tests', function() {
assert.equal(metadata.openGraph.url, sampleUrl, 'Error finding url');

assert.equal(metadata.media.icon, sampleIcon, 'Error finding icon');
assert.equal(metadata.media.image, sampleImage, 'Error finding image');
assert.equal(metadata.media.image, sampleImageHTTPS, 'Error finding image');
});

});
2 changes: 2 additions & 0 deletions tests/metadataRules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ describe('Image Rule Tests', function() {

const ruleTests = [
['og:image', `<meta property="og:image" content="${pageImage}" />`],
['og:image:url', `<meta property="og:image:url" content="${pageImage}" /> `],
['og:image:secure_url', `<meta property="og:image:secure_url" content="${pageImage}" /> `],
['twitter:image', `<meta property="twitter:image" content="${pageImage}" />`],
['thumbnail', `<meta name="thumbnail" content="${pageImage}" />`],
['img', `<img src="${pageImage}" />`],
Expand Down

0 comments on commit 3a6a13b

Please sign in to comment.