0201c431d7
* 🎨 🔥 do not store settings in config and make settings cache easier available - remove remembering settings value in theme config - if we need a cache value, we are asking the settings cache directly - instead of settings.getSettingSync we use settings.cache.get - added TODO: - think about moving the settings cache out of api/settings - we could create a folder named cache cache/settings - this settings cache listens on model changes for settings - decoupling * 🔥 remove timezone from config - no need to store in overrides config and in defaults settings * 🎨 context object helper - replace config.get('theme') by settings cache * 🎨 replace config.get('theme') by settings.cache.get * 🎨 adapt tests * fixes from comments
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
var _ = require('lodash'),
|
|
settingsCache = require('../../api/settings').cache;
|
|
|
|
function getTitle(data, root) {
|
|
var title = '',
|
|
context = root ? root.context : null,
|
|
blogTitle = settingsCache.get('title'),
|
|
pagination = root ? root.pagination : null,
|
|
pageString = '';
|
|
|
|
if (pagination && pagination.total > 1) {
|
|
pageString = ' - Page ' + pagination.page;
|
|
}
|
|
|
|
if (data.meta_title) {
|
|
title = data.meta_title;
|
|
} else if (_.includes(context, 'home')) {
|
|
title = blogTitle;
|
|
} else if (_.includes(context, 'author') && data.author) {
|
|
title = data.author.name + pageString + ' - ' + blogTitle;
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
|
title = data.tag.meta_title || data.tag.name + pageString + ' - ' + blogTitle;
|
|
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
|
|
title = data.post.meta_title || data.post.title;
|
|
} else {
|
|
title = blogTitle + pageString;
|
|
}
|
|
|
|
return (title || '').trim();
|
|
}
|
|
|
|
module.exports = getTitle;
|