mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
f3e0949c73
refs https://github.com/TryGhost/Ghost/issues/10921 refs https://github.com/TryGhost/Ghost/pull/11068 - When there is no twitter or og image specified for a post or a page the new default falls back to appropriate site-wide twitter/og image or site's cover image. - New rules of follback follow this logic: post/page/amp = post.twitter_image || post.feature_image || settings.twitter_image || settings.cover_image; post/page/amp = post.og_image || post.feature_image || settings.og_image || settings.cover_image;
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
const _ = require('lodash');
|
|
const getContextObject = require('./context_object.js');
|
|
const urlUtils = require('../../shared/url-utils');
|
|
const settingsCache = require('../../server/services/settings/cache');
|
|
|
|
function getOgImage(data) {
|
|
const context = data.context ? data.context : null;
|
|
const contextObject = getContextObject(data, context, false);
|
|
|
|
if (_.includes(context, 'home')) {
|
|
const imgUrl = settingsCache.get('og_image') || settingsCache.get('cover_image');
|
|
return (imgUrl && urlUtils.relativeToAbsolute(imgUrl)) || null;
|
|
}
|
|
|
|
if (_.includes(context, 'post') || _.includes(context, 'page') || _.includes(context, 'amp')) {
|
|
if (contextObject.og_image) {
|
|
return urlUtils.relativeToAbsolute(contextObject.og_image);
|
|
} else if (contextObject.feature_image) {
|
|
return urlUtils.relativeToAbsolute(contextObject.feature_image);
|
|
} else if (settingsCache.get('og_image')) {
|
|
return urlUtils.relativeToAbsolute(settingsCache.get('og_image'));
|
|
} else if (settingsCache.get('cover_image')) {
|
|
return urlUtils.relativeToAbsolute(settingsCache.get('cover_image'));
|
|
}
|
|
}
|
|
|
|
if (_.includes(context, 'author') && contextObject.cover_image) {
|
|
return urlUtils.relativeToAbsolute(contextObject.cover_image);
|
|
}
|
|
|
|
if (_.includes(context, 'tag')) {
|
|
if (contextObject.og_image) {
|
|
return urlUtils.relativeToAbsolute(contextObject.og_image);
|
|
} else if (contextObject.feature_image) {
|
|
return urlUtils.relativeToAbsolute(contextObject.feature_image);
|
|
} else if (settingsCache.get('cover_image')) {
|
|
return urlUtils.relativeToAbsolute(settingsCache.get('cover_image'));
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
module.exports = getOgImage;
|