Skip to content

Commit 4c48acb

Browse files
janetleekimdviramontes
authored andcommitted
feat: fusion parser
Looks okay — image did not load in preview.
1 parent fa71cac commit 4c48acb

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

fixtures/fusion.net/1482529202024.html

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export const FusionNetExtractor = {
2+
domain: 'fusion.net',
3+
4+
title: {
5+
selectors: [
6+
'.post-title',
7+
'.single-title',
8+
'.headline',
9+
],
10+
},
11+
12+
author: {
13+
selectors: [
14+
'div.post-meta-details.show-for-medium span.byline.byline-article a',
15+
],
16+
},
17+
18+
date_published: {
19+
selectors: [
20+
['time.local-time', 'datetime'],
21+
],
22+
},
23+
24+
dek: {
25+
selectors: [
26+
// enter selectors
27+
],
28+
},
29+
30+
lead_image_url: {
31+
selectors: [
32+
['meta[name="og:image"]', 'value'],
33+
],
34+
},
35+
36+
content: {
37+
selectors: [
38+
'.article-content',
39+
],
40+
41+
// Is there anything in the content you selected that needs transformed
42+
// before it's consumable content? E.g., unusual lazy loaded images
43+
transforms: {
44+
},
45+
46+
// Is there anything that is in the result that shouldn't be?
47+
// The clean selectors will remove anything that matches from
48+
// the result
49+
clean: [
50+
51+
],
52+
},
53+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import assert from 'assert';
2+
import fs from 'fs';
3+
import URL from 'url';
4+
import cheerio from 'cheerio';
5+
6+
import Mercury from 'mercury';
7+
import getExtractor from 'extractors/get-extractor';
8+
import { excerptContent } from 'utils/text';
9+
10+
describe('FusionNetExtractor', () => {
11+
describe('initial test case', () => {
12+
let result;
13+
let url;
14+
beforeAll(() => {
15+
url =
16+
'http://fusion.net/story/377467/la-la-land-oscar-hollywood-musicals-race/';
17+
const html =
18+
fs.readFileSync('./fixtures/fusion.net/1482529202024.html');
19+
result =
20+
Mercury.parse(url, html, { fallback: false });
21+
});
22+
23+
it('is selected properly', () => {
24+
// This test should be passing by default.
25+
// It sanity checks that the correct parser
26+
// is being selected for URLs from this domain
27+
const extractor = getExtractor(url);
28+
assert.equal(extractor.domain, URL.parse(url).hostname);
29+
});
30+
31+
it('returns the title', async () => {
32+
// To pass this test, fill out the title selector
33+
// in ./src/extractors/custom/fusion.net/index.js.
34+
const { title } = await result;
35+
36+
// Update these values with the expected values from
37+
// the article.
38+
assert.equal(title, '‘La La Land’ might win an Oscar but it’s got some bizarre racial politics');
39+
});
40+
41+
it('returns the author', async () => {
42+
// To pass this test, fill out the author selector
43+
// in ./src/extractors/custom/fusion.net/index.js.
44+
const { author } = await result;
45+
46+
// Update these values with the expected values from
47+
// the article.
48+
assert.equal(author, 'Jack Mirkinson');
49+
});
50+
51+
it('returns the date_published', async () => {
52+
// To pass this test, fill out the date_published selector
53+
// in ./src/extractors/custom/fusion.net/index.js.
54+
const { date_published } = await result;
55+
56+
// Update these values with the expected values from
57+
// the article.
58+
assert.equal(date_published, '2016-12-23T16:14:25.000Z');
59+
});
60+
61+
it('returns the lead_image_url', async () => {
62+
// To pass this test, fill out the lead_image_url selector
63+
// in ./src/extractors/custom/fusion.net/index.js.
64+
const { lead_image_url } = await result;
65+
66+
// Update these values with the expected values from
67+
// the article.
68+
assert.equal(lead_image_url, 'https://i0.wp.com/fusion.net/wp-content/uploads/2016/12/screen-shot-2016-12-23-at-8-22-27-am.png?resize=1200%2C630&quality=80&strip=all');
69+
});
70+
71+
it('returns the content', async () => {
72+
// To pass this test, fill out the content selector
73+
// in ./src/extractors/custom/fusion.net/index.js.
74+
// You may also want to make use of the clean and transform
75+
// options.
76+
const { content } = await result;
77+
78+
const $ = cheerio.load(content || '');
79+
80+
const first13 = excerptContent($('*').first().text(), 13);
81+
82+
// Update these values with the expected values from
83+
// the article.
84+
assert.equal(first13, 'Warning: this piece contains spoilers. I love musicals. Like, love them love them.');
85+
});
86+
});
87+
});

src/extractors/custom/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export * from './uproxx.com';
4949
export * from './www.eonline.com';
5050
export * from './www.miamiherald.com';
5151
export * from './www.refinery29.com';
52+
export * from './fusion.net';
5253
export * from './sciencefly.com';
5354
export * from './hellogiggles.com';
5455
export * from './thoughtcatalog.com';

0 commit comments

Comments
 (0)