mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +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
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
var _ = require('lodash'),
|
|
settingsCache = require('../../settings/cache');
|
|
|
|
function getTitle(data, root, options) {
|
|
var title = '',
|
|
context = root ? root.context : null,
|
|
postSdTitle,
|
|
blogTitle = settingsCache.get('title'),
|
|
pagination = root ? root.pagination : null,
|
|
pageString = '';
|
|
|
|
options = options ? options : {};
|
|
|
|
if (pagination && pagination.total > 1) {
|
|
pageString = ' (Page ' + pagination.page + ')';
|
|
}
|
|
|
|
// If there's a specific meta title
|
|
if (data.meta_title) {
|
|
title = data.meta_title;
|
|
// Home title
|
|
} else if (_.includes(context, 'home')) {
|
|
title = blogTitle;
|
|
// Author title, paged
|
|
} else if (_.includes(context, 'author') && data.author && _.includes(context, 'paged')) {
|
|
title = data.author.name + ' - ' + blogTitle + pageString;
|
|
// Author title, index
|
|
} else if (_.includes(context, 'author') && data.author) {
|
|
title = data.author.name + ' - ' + blogTitle;
|
|
// Tag title, paged
|
|
} else if (_.includes(context, 'tag') && data.tag && _.includes(context, 'paged')) {
|
|
title = data.tag.meta_title || data.tag.name + ' - ' + blogTitle + pageString;
|
|
// Tag title, index
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
|
title = data.tag.meta_title || data.tag.name + ' - ' + blogTitle;
|
|
// Post title
|
|
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
|
|
if (options && options.property) {
|
|
postSdTitle = options.property + '_title';
|
|
title = data.post[postSdTitle] || '';
|
|
} else {
|
|
title = data.post.meta_title || data.post.title;
|
|
}
|
|
// Fallback
|
|
} else {
|
|
title = blogTitle + pageString;
|
|
}
|
|
|
|
return (title || '').trim();
|
|
}
|
|
|
|
module.exports = getTitle;
|