Ghost/core/server/data/meta/twitter_image.js
Naz Gargol abda6e6338
Migrated to use url-utils from Ghost-SDK (#10787)
closes #10773

- The refactoring is a substitute for `urlService.utils` used previously throughout the codebase and now extracted into the separate module in Ghost-SDK
- Added url-utils stubbing utility for test suites
- Some tests had to be refactored to avoid double mocks (when url's are being reset inside of rested 'describe' groups)
2019-06-18 15:13:55 +02:00

21 lines
717 B
JavaScript

var urlUtils = require('../../lib/url-utils'),
getContextObject = require('./context_object.js'),
_ = require('lodash');
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) {
return urlUtils.urlFor('image', {image: contextObject.twitter_image}, true);
} else if (contextObject.feature_image) {
return urlUtils.urlFor('image', {image: contextObject.feature_image}, true);
}
}
return null;
}
module.exports = getTwitterImage;