Skip to content

Commit 5663660

Browse files
authored
fix: nytimes custom parser title selector (#181)
* fix: nytimes custom parser title selector * upgrade node version * circle ci tweak
1 parent 7fcd9b6 commit 5663660

4 files changed

Lines changed: 83 additions & 3 deletions

File tree

circle.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ machine:
55

66
node:
77
version:
8-
4.3.2
8+
6.10
99

1010
## Customize dependencies
1111
dependencies:
1212
pre:
1313
- curl -o- -L https://yarnpkg.com/install.sh | bash
1414
- nvm install 7.0.0
15+
- nvm install 6.10.0
1516
# For some reason phantomjs-prebuild is failing w/yarn, but npm installing works
1617
- npm install phantomjs-prebuilt
1718

@@ -29,5 +30,5 @@ test:
2930
- nvm use 7.0 && yarn test:web -- --maxWorkers=4 && yarn build:web -- --maxWorkers=4:
3031
parallel: true
3132
# Switch to check on 4.3.2
32-
- nvm use 4.3.2 && yarn build && yarn test:node -- --maxWorkers=4:
33+
- nvm use 6.10 && yarn build && yarn test:node -- --maxWorkers=4:
3334
parallel: true

fixtures/www.nytimes.com/1539194812689.html

Lines changed: 69 additions & 0 deletions
Large diffs are not rendered by default.

src/extractors/custom/www.nytimes.com/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ export const NYTimesExtractor = {
33

44
title: {
55
selectors: [
6-
'.g-headline',
6+
'h1.g-headline',
7+
'h1[itemprop="headline"]',
78
'h1.headline',
89
],
910
},

src/extractors/custom/www.nytimes.com/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,13 @@ describe('NYTimesExtractor', () => {
102102
assert.equal(author, 'The New York Times');
103103
assert.equal(text, 'T he Smithsonian’s N');
104104
});
105+
106+
it('returns the title on most recent articles', async () => {
107+
const html = fs.readFileSync('./fixtures/www.nytimes.com/1539194812689.html');
108+
const uri = 'https://www.nytimes.com/2018/10/09/us/politics/nikki-haley-united-nations.html';
109+
110+
const { title } = await Mercury.parse(uri, html);
111+
112+
assert.equal(title, 'Nikki Haley to Resign as Trump’s Ambassador to the U.N.');
113+
});
105114
});

0 commit comments

Comments
 (0)