Ghost/core/server/data/meta/og_image.js
Aileen Nowak cfbb7f6c6b Facebook and Twitter data per post feature (#8827)
closes #8334

- adds title, image and description to structured data to be rendered as open graph and twitter data.
- if meta title and description for a post exists already, the custom structured data will overwrite those for `og:` and `twitter:` data. `JSON-LD` (Schema.org`) is not affected and will stay the same.
- adds tests
- adds new og and twitter fields to schema incl. migration
2017-08-03 15:48:39 +04:00

21 lines
714 B
JavaScript

var utils = require('../../utils'),
getContextObject = require('./context_object.js'),
_ = require('lodash');
function getOgImage(data) {
var context = data.context ? data.context : null,
contextObject = getContextObject(data, context);
if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) {
if (contextObject.og_image) {
return utils.url.urlFor('image', {image: contextObject.og_image}, true);
} else if (contextObject.feature_image) {
return utils.url.urlFor('image', {image: contextObject.feature_image}, true);
}
}
return null;
}
module.exports = getOgImage;