2019-07-25 12:08:29 +03:00
|
|
|
const _ = require('lodash');
|
|
|
|
const urlUtils = require('../../server/lib/url-utils');
|
|
|
|
const getContextObject = require('./context_object.js');
|
|
|
|
const settingsCache = require('../../server/services/settings/cache');
|
2017-08-03 14:48:39 +03:00
|
|
|
|
|
|
|
function getTwitterImage(data) {
|
2019-07-25 12:08:29 +03:00
|
|
|
const context = data.context ? data.context : null;
|
|
|
|
const contextObject = getContextObject(data, context);
|
|
|
|
const siteTwitterImage = settingsCache.get('twitter_image');
|
2017-08-03 14:48:39 +03:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 12:08:29 +03:00
|
|
|
if (_.includes(context, 'home') && siteTwitterImage) {
|
|
|
|
return urlUtils.urlFor('image', {image: siteTwitterImage}, true);
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:48:39 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getTwitterImage;
|