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

Commit

Permalink
Add a provider field fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlockhart committed Oct 13, 2016
1 parent ee886dc commit 6e73102
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ function getMetadata(doc, url, rules) {
metadata.url = url;
}

metadata.provider = '';
if(url) {
const parsedUrl = urlparse.parse(url);
metadata.provider = parsedUrl
.hostname
.replace('www.', '')
.replace('co.', '')
.split('.')
.slice(0, -1)
.join(' ');
}

if(url && !metadata.icon_url) {
metadata.icon_url = makeUrlAbsolute(url, '/favicon.ico');
}
Expand Down
8 changes: 8 additions & 0 deletions tests/getMetadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ describe('Get Metadata Tests', function() {
assert.equal(metadata.image_url, sampleImageHTTP, `Unable to find ${sampleImageHTTP} in ${relativeHtml}`);
});

it('adds a provider when URL passed in', () => {
const sampleProvider = 'example';
const doc = stringToDom(sampleHtml);
const metadata = getMetadata(doc, sampleUrl);

assert.equal(metadata.provider, sampleProvider, `Unable to find ${sampleProvider} in ${sampleUrl}`);
});

it('uses default favicon when no favicon is found', () => {
const noIconHtml = `
<html>
Expand Down

0 comments on commit 6e73102

Please sign in to comment.