Skip to content

Commit

Permalink
Updated parser and fixed main image parsing
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
dijs committed Aug 15, 2017
1 parent 98f1206 commit a69f851
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
dist/
coverage/
npm-debug.log
yarn.lock
yarn.lock
package-lock.json
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"main": "./dist/wiki.js",
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"infobox-parser": "^1.0.4"
"infobox-parser": "^2.0.0",
"isomorphic-fetch": "^2.2.1"
},
"devDependencies": {
"babel": "^6.23.0",
Expand Down
8 changes: 2 additions & 6 deletions src/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { aggregatePagination, pagination, api } from './util';
import infoboxParser from 'infobox-parser';
import {parseCoordinates} from './coordinates';

const byNamedImage = searchName => image => {
const [, name] = image.title.split(':');
return name === searchName;
};

/**
* WikiPage
* @namespace WikiPage
Expand Down Expand Up @@ -103,6 +98,7 @@ export default function wikiPage(rawPageInfo, apiOptions) {
info.bildname ||
info.imagen ||
info.Immagine;

// Handle case where no info box exists
if (!mainImageName) {
return rawInfo().then(text => {
Expand All @@ -114,7 +110,7 @@ export default function wikiPage(rawPageInfo, apiOptions) {
: undefined;
});
}
const image = images.find(byNamedImage(mainImageName));
const image = images.find(({ title }) => title.indexOf(mainImageName) !== -1);
return image.imageinfo.length > 0
? image.imageinfo[0].url
: undefined;
Expand Down
2 changes: 1 addition & 1 deletion test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Dublin page integration', () => {

return dublin.info().then((info) => {
info.name.should.equal('Dublin');
info.gdp.should.equal('US$ 90.1 billion');
info.gdp.should.equal('American dollar 90.1 billion');
info.populationTotal.should.equal(553165)
});
});
Expand Down
11 changes: 11 additions & 0 deletions test/real.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ describe('Live tests', () => {
});
});
});
it('should parse main image properly', function(done) {
this.timeout(5000);
wiki()
.page('FC Copenhagen')
.then(page => {
page.mainImage().then(mainImage => {
mainImage.should.equal('https://upload.wikimedia.org/wikipedia/en/9/93/FC_K%C3%B8benhavn.svg');
done();
});
});
});
});

0 comments on commit a69f851

Please sign in to comment.