2016-01-17 13:07:52 +03:00
|
|
|
var _ = require('lodash'),
|
2017-02-27 18:53:04 +03:00
|
|
|
settingsCache = require('../../settings/cache');
|
2016-01-17 13:07:52 +03:00
|
|
|
|
|
|
|
function getTitle(data, root) {
|
|
|
|
var title = '',
|
|
|
|
context = root ? root.context : null,
|
2017-02-03 16:15:11 +03:00
|
|
|
blogTitle = settingsCache.get('title'),
|
2016-01-17 13:07:52 +03:00
|
|
|
pagination = root ? root.pagination : null,
|
|
|
|
pageString = '';
|
|
|
|
|
|
|
|
if (pagination && pagination.total > 1) {
|
|
|
|
pageString = ' - Page ' + pagination.page;
|
|
|
|
}
|
2017-02-03 16:15:11 +03:00
|
|
|
|
2016-01-17 13:07:52 +03:00
|
|
|
if (data.meta_title) {
|
|
|
|
title = data.meta_title;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'home')) {
|
2017-02-03 16:15:11 +03:00
|
|
|
title = blogTitle;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'author') && data.author) {
|
2017-02-03 16:15:11 +03:00
|
|
|
title = data.author.name + pageString + ' - ' + blogTitle;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
2017-02-03 16:15:11 +03:00
|
|
|
title = data.tag.meta_title || data.tag.name + pageString + ' - ' + blogTitle;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
|
2016-01-17 13:07:52 +03:00
|
|
|
title = data.post.meta_title || data.post.title;
|
|
|
|
} else {
|
2017-02-03 16:15:11 +03:00
|
|
|
title = blogTitle + pageString;
|
2016-01-17 13:07:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (title || '').trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getTitle;
|