mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
a9050f68ea
no issue - Removed deprecated 'blog' reference from frontend data. The alias (site->blog) stays till next version (v4) as it's not leaving much of technical debt but would ease the migration process for anybody still using it. - The follow up to this is substitute of all references to `options.data.blog` with `options.data.site` in "frontend" - Fixed test utils helper to use `site` instead of `blog` - Removed 0.1 flag checks in {{get}} helper - Removed user aliasing from {{get}} helper - Removed unused translation for {{get}} helper - Added a note to excerpt changes in metadata for future reference - Removed page alias used in description helper. The mix of page context with post object in the metadata was only possible in v0.1 - Changed mock in ghost_head helper to use v2 - Removed unneeded test for body class helper
51 lines
2 KiB
JavaScript
51 lines
2 KiB
JavaScript
const _ = require('lodash');
|
|
const settingsCache = require('../../server/services/settings/cache');
|
|
|
|
function getDescription(data, root, options) {
|
|
const context = root ? root.context : null;
|
|
const siteDescription = settingsCache.get('meta_description') || settingsCache.get('description');
|
|
|
|
let description = '';
|
|
let postSdDescription;
|
|
|
|
options = options ? options : {};
|
|
|
|
// We only return meta_description if provided
|
|
if (data.meta_description) {
|
|
description = data.meta_description;
|
|
} else if (_.includes(context, 'paged')) {
|
|
description = '';
|
|
} else if (_.includes(context, 'home')) {
|
|
if (options && options.property) {
|
|
const siteSdDescription = options.property + '_description';
|
|
description = settingsCache.get(siteSdDescription) || '';
|
|
} else {
|
|
description = siteDescription;
|
|
}
|
|
} else if (_.includes(context, 'author') && data.author) {
|
|
// The usage of meta data fields for author is currently not implemented.
|
|
// We do have meta_description and meta_title fields
|
|
// in the users table, but there's no UI to populate those.
|
|
description = data.author.meta_description || '';
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
|
description = data.tag.meta_description || '';
|
|
} else if (_.includes(context, 'post') && data.post) {
|
|
if (options && options.property) {
|
|
postSdDescription = options.property + '_description';
|
|
description = data.post[postSdDescription] || '';
|
|
} else {
|
|
description = data.post.meta_description || '';
|
|
}
|
|
} else if (_.includes(context, 'page') && data.page) {
|
|
if (options && options.property) {
|
|
postSdDescription = options.property + '_description';
|
|
description = data.page[postSdDescription] || '';
|
|
} else {
|
|
description = data.page.meta_description || '';
|
|
}
|
|
}
|
|
|
|
return (description || '').trim();
|
|
}
|
|
|
|
module.exports = getDescription;
|