2016-01-17 02:07:52 -08:00
|
|
|
var _ = require('lodash'),
|
2017-02-03 14:15:11 +01:00
|
|
|
settingsCache = require('../../api/settings').cache;
|
2016-01-17 02:07:52 -08:00
|
|
|
|
|
|
|
function getDescription(data, root) {
|
|
|
|
var description = '',
|
2017-02-03 14:15:11 +01:00
|
|
|
context = root ? root.context : null,
|
|
|
|
blogDescription = settingsCache.get('description');
|
2016-01-17 02:07:52 -08:00
|
|
|
|
|
|
|
if (data.meta_description) {
|
|
|
|
description = data.meta_description;
|
2016-06-11 12:23:27 -06:00
|
|
|
} else if (_.includes(context, 'paged')) {
|
2016-01-17 02:07:52 -08:00
|
|
|
description = '';
|
2016-06-11 12:23:27 -06:00
|
|
|
} else if (_.includes(context, 'home')) {
|
2017-02-03 14:15:11 +01:00
|
|
|
description = blogDescription;
|
2016-06-11 12:23:27 -06:00
|
|
|
} else if (_.includes(context, 'author') && data.author) {
|
2016-01-27 08:58:27 -08:00
|
|
|
description = data.author.meta_description || data.author.bio;
|
2016-06-11 12:23:27 -06:00
|
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
2016-01-27 08:58:27 -08:00
|
|
|
description = data.tag.meta_description || data.tag.description;
|
2016-06-11 12:23:27 -06:00
|
|
|
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
|
2016-01-17 02:07:52 -08:00
|
|
|
description = data.post.meta_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (description || '').trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getDescription;
|