Skip to content

Commit

Permalink
feat: improvements for nyer magazine articles (#45)
Browse files Browse the repository at this point in the history
adds dek and date_published for magazine template
  • Loading branch information
adampash authored Dec 2, 2016
1 parent 00f8965 commit d0453ef
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
28 changes: 28 additions & 0 deletions fixtures/www.newyorker.com/1480713300334.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/extractors/custom/www.newyorker.com/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const NewYorkerExtractor = {
date_published: {
selectors: [
['meta[name="article:published_time"]', 'value'],
['time[itemProp="datePublished"]', 'content'],
],

timezone: 'America/New_York',
},

lead_image_url: {
Expand All @@ -48,6 +51,8 @@ export const NewYorkerExtractor = {

dek: {
selectors: [
'.dek',
'h2.dek',
],
},

Expand Down
29 changes: 29 additions & 0 deletions src/extractors/custom/www.newyorker.com/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,33 @@ describe('NewYorkerExtractor', () => {
// the article.
assert.equal(first13, 'In a laboratory in Shanghai, researchers work on developing a quantum computer—a new');
});

it('returns the dek when present', async () => {
const html =
fs.readFileSync('./fixtures/www.newyorker.com/1480713300334.html');

const url =
'http://www.newyorker.com/magazine/2016/12/05/lessons-from-my-mother';

const { dek } =
await Mercury.parse(url, html, { fallback: false });

assert.equal(
dek,
'I had a sense that she was a good teacher, but I had no idea that she was such an influential one, and in the very area I had chosen.'
);
});

it('returns the date for magazine content', async () => {
const html =
fs.readFileSync('./fixtures/www.newyorker.com/1480713300334.html');

const url =
'http://www.newyorker.com/magazine/2016/12/05/lessons-from-my-mother';

const { date_published } =
await Mercury.parse(url, html, { fallback: false });

assert.equal(date_published, '2016-11-28T05:00:00.000Z');
});
});

0 comments on commit d0453ef

Please sign in to comment.