2016-01-17 13:07:52 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../../config');
|
|
|
|
|
|
|
|
function getDescription(data, root) {
|
|
|
|
var description = '',
|
|
|
|
context = root ? root.context : null;
|
|
|
|
|
|
|
|
if (data.meta_description) {
|
|
|
|
description = data.meta_description;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'paged')) {
|
2016-01-17 13:07:52 +03:00
|
|
|
description = '';
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'home')) {
|
2016-09-13 18:41:14 +03:00
|
|
|
description = config.get('theme').description;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'author') && data.author) {
|
2016-01-27 19:58:27 +03:00
|
|
|
description = data.author.meta_description || data.author.bio;
|
2016-06-11 21:23:27 +03:00
|
|
|
} else if (_.includes(context, 'tag') && data.tag) {
|
2016-01-27 19:58:27 +03:00
|
|
|
description = data.tag.meta_description || data.tag.description;
|
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
|
|
|
description = data.post.meta_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (description || '').trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getDescription;
|