Ghost/core/frontend/meta/twitter_image.js
Naz Gargol d9fef82170
Added global site SEO fields to be used in theme helpers (#10930)
#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
2019-07-25 11:08:29 +02:00

27 lines
1010 B
JavaScript

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