mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
cfbb7f6c6b
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
21 lines
714 B
JavaScript
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;
|