d9fef82170
#10921 - Changed {{meta_title}} helper to use site meta_title' field - Changed {{meta_description}} helper to use site 'meta_description' field - Changed {{og_image}} helper to use site 'og_image' field - Added site title handling for og/twitter metadata - Refactored use of 'blog' in variable name in favor of 'site' - Extended meta_description test suite with 'home' context cases - Changed {{twitter_image}} helper to use site 'twitter_image' field - Added ghost_head test for site metadata - Renamed blog->site in variable names for touched files
27 lines
970 B
JavaScript
27 lines
970 B
JavaScript
const _ = require('lodash');
|
|
const getContextObject = require('./context_object.js');
|
|
const urlUtils = require('../../server/lib/url-utils');
|
|
const settingsCache = require('../../server/services/settings/cache');
|
|
|
|
function getOgImage(data) {
|
|
const context = data.context ? data.context : null;
|
|
const contextObject = getContextObject(data, context);
|
|
const siteOgImage = settingsCache.get('og_image');
|
|
|
|
if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) {
|
|
if (contextObject.og_image) {
|
|
return urlUtils.urlFor('image', {image: contextObject.og_image}, true);
|
|
} else if (contextObject.feature_image) {
|
|
return urlUtils.urlFor('image', {image: contextObject.feature_image}, true);
|
|
}
|
|
}
|
|
|
|
if (_.includes(context, 'home') && siteOgImage) {
|
|
return urlUtils.urlFor('image', {image: siteOgImage}, true);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
module.exports = getOgImage;
|