Skip to content
This repository was archived by the owner on Jul 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #88 from Financial-Times/image-type
Browse files Browse the repository at this point in the history
Be explicit about which image types we expect from largeImage
  • Loading branch information
adgad committed Dec 9, 2014
2 parents ff10e2c + 2e02fe6 commit 47f5ff8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,12 @@ Object.defineProperty(Article.prototype, 'body', {
Object.defineProperty(Article.prototype, 'largestImage', {
get: function () {
if (this.raw.item.images) {
var sortedImages = this.raw.item.images.sort(function (a, b) {
return a.width < b.width;
var images = {};

this.raw.item.images.forEach(function(img) {
images[img.type] = img;
});
return sortedImages[0];
return images['wide-format'] || images['article'] || images['primary'];
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ft-api-client",
"version": "3.5.1",
"version": "3.5.2",
"repository": {
"type": "git",
"url": "https://github.com/Financial-Times/ft-api-client.git"
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/03b49444-16c9-11e3-bced-00144feabdc0
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@
"width": 272,
"mediaType": "image/jpeg"
},
{
"url": "http://im.ft-static.com/content/images/alternative.img",
"type": "primary",
"source": "AFP/Getty Images",
"alt": "RUSSIA-G20-SUMMIT",
"height": 2000,
"width": 2000,
"mediaType": "image/jpeg"
},
{
"url": "http://im.ft-static.com/content/images/9ba9fc53-8af1-4145-9109-bd6f0ccff3bd.img",
"type": "secondary",
Expand Down

0 comments on commit 47f5ff8

Please sign in to comment.