Skip to content

Commit d0453ef

Browse files
authored
feat: improvements for nyer magazine articles (#45)
adds dek and date_published for magazine template
1 parent 00f8965 commit d0453ef

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

Diff for: fixtures/www.newyorker.com/1480713300334.html

+28
Large diffs are not rendered by default.

Diff for: src/extractors/custom/www.newyorker.com/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export const NewYorkerExtractor = {
3737
date_published: {
3838
selectors: [
3939
['meta[name="article:published_time"]', 'value'],
40+
['time[itemProp="datePublished"]', 'content'],
4041
],
42+
43+
timezone: 'America/New_York',
4144
},
4245

4346
lead_image_url: {
@@ -48,6 +51,8 @@ export const NewYorkerExtractor = {
4851

4952
dek: {
5053
selectors: [
54+
'.dek',
55+
'h2.dek',
5156
],
5257
},
5358

Diff for: src/extractors/custom/www.newyorker.com/index.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,33 @@ describe('NewYorkerExtractor', () => {
105105
// the article.
106106
assert.equal(first13, 'In a laboratory in Shanghai, researchers work on developing a quantum computer—a new');
107107
});
108+
109+
it('returns the dek when present', async () => {
110+
const html =
111+
fs.readFileSync('./fixtures/www.newyorker.com/1480713300334.html');
112+
113+
const url =
114+
'http://www.newyorker.com/magazine/2016/12/05/lessons-from-my-mother';
115+
116+
const { dek } =
117+
await Mercury.parse(url, html, { fallback: false });
118+
119+
assert.equal(
120+
dek,
121+
'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.'
122+
);
123+
});
124+
125+
it('returns the date for magazine content', async () => {
126+
const html =
127+
fs.readFileSync('./fixtures/www.newyorker.com/1480713300334.html');
128+
129+
const url =
130+
'http://www.newyorker.com/magazine/2016/12/05/lessons-from-my-mother';
131+
132+
const { date_published } =
133+
await Mercury.parse(url, html, { fallback: false });
134+
135+
assert.equal(date_published, '2016-11-28T05:00:00.000Z');
136+
});
108137
});

0 commit comments

Comments
 (0)