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