Skip to content

Commit a69f851

Browse files
committed
Updated parser and fixed main image parsing
Fixes dijs#53
1 parent 98f1206 commit a69f851

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules/
33
dist/
44
coverage/
55
npm-debug.log
6-
yarn.lock
6+
yarn.lock
7+
package-lock.json

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
},
2626
"main": "./dist/wiki.js",
2727
"dependencies": {
28-
"isomorphic-fetch": "^2.2.1",
29-
"infobox-parser": "^1.0.4"
28+
"infobox-parser": "^2.0.0",
29+
"isomorphic-fetch": "^2.2.1"
3030
},
3131
"devDependencies": {
3232
"babel": "^6.23.0",

src/page.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { aggregatePagination, pagination, api } from './util';
22
import infoboxParser from 'infobox-parser';
33
import {parseCoordinates} from './coordinates';
44

5-
const byNamedImage = searchName => image => {
6-
const [, name] = image.title.split(':');
7-
return name === searchName;
8-
};
9-
105
/**
116
* WikiPage
127
* @namespace WikiPage
@@ -103,6 +98,7 @@ export default function wikiPage(rawPageInfo, apiOptions) {
10398
info.bildname ||
10499
info.imagen ||
105100
info.Immagine;
101+
106102
// Handle case where no info box exists
107103
if (!mainImageName) {
108104
return rawInfo().then(text => {
@@ -114,7 +110,7 @@ export default function wikiPage(rawPageInfo, apiOptions) {
114110
: undefined;
115111
});
116112
}
117-
const image = images.find(byNamedImage(mainImageName));
113+
const image = images.find(({ title }) => title.indexOf(mainImageName) !== -1);
118114
return image.imageinfo.length > 0
119115
? image.imageinfo[0].url
120116
: undefined;

test/integration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Dublin page integration', () => {
4141

4242
return dublin.info().then((info) => {
4343
info.name.should.equal('Dublin');
44-
info.gdp.should.equal('US$ 90.1 billion');
44+
info.gdp.should.equal('American dollar 90.1 billion');
4545
info.populationTotal.should.equal(553165)
4646
});
4747
});

test/real.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,15 @@ describe('Live tests', () => {
3333
});
3434
});
3535
});
36+
it('should parse main image properly', function(done) {
37+
this.timeout(5000);
38+
wiki()
39+
.page('FC Copenhagen')
40+
.then(page => {
41+
page.mainImage().then(mainImage => {
42+
mainImage.should.equal('https://upload.wikimedia.org/wikipedia/en/9/93/FC_K%C3%B8benhavn.svg');
43+
done();
44+
});
45+
});
46+
});
3647
});

0 commit comments

Comments
 (0)