2016-01-17 13:07:52 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../../config');
|
|
|
|
|
|
|
|
function getTitle(data, root) {
|
|
|
|
var title = '',
|
|
|
|
context = root ? root.context : null,
|
2016-09-13 18:41:14 +03:00
|
|
|
blog = config.get('theme'),
|
2016-01-17 13:07:52 +03:00
|
|
|
pagination = root ? root.pagination : null,
|
|
|
|
pageString = '';
|
|
|
|
|
|
|
|
if (pagination && pagination.total > 1) {
|
|
|
|
pageString = ' - Page ' + pagination.page;
|
|
|
|
}
|
|
|
|
if (data.meta_title) {
|
|
|
|
title = data.meta_title;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'home')) {
|
2016-01-17 13:07:52 +03:00
|
|
|
title = blog.title;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'author') && data.author) {
|
2016-01-17 13:07:52 +03:00
|
|
|
title = data.author.name + pageString + ' - ' + blog.title;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
2016-01-17 13:07:52 +03:00
|
|
|
title = data.tag.meta_title || data.tag.name + pageString + ' - ' + blog.title;
|
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 {
|
|
|
|
title = blog.title + pageString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (title || '').trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getTitle;
|