2019-06-18 16:13:55 +03:00
|
|
|
var urlUtils = require('../../lib/url-utils'),
|
2017-08-03 14:48:39 +03:00
|
|
|
getContextObject = require('./context_object.js'),
|
2017-12-11 21:14:05 +03:00
|
|
|
_ = require('lodash');
|
2017-08-03 14:48:39 +03:00
|
|
|
|
|
|
|
function getTwitterImage(data) {
|
|
|
|
var context = data.context ? data.context : null,
|
|
|
|
contextObject = getContextObject(data, context);
|
|
|
|
|
|
|
|
if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) {
|
|
|
|
if (contextObject.twitter_image) {
|
2019-06-18 16:13:55 +03:00
|
|
|
return urlUtils.urlFor('image', {image: contextObject.twitter_image}, true);
|
2017-08-03 14:48:39 +03:00
|
|
|
} else if (contextObject.feature_image) {
|
2019-06-18 16:13:55 +03:00
|
|
|
return urlUtils.urlFor('image', {image: contextObject.feature_image}, true);
|
2017-08-03 14:48:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getTwitterImage;
|