2014-10-10 18:54:07 +04:00
|
|
|
// # Meta Description Helper
|
|
|
|
// Usage: `{{meta_description}}`
|
|
|
|
//
|
|
|
|
// Page description used for sharing and SEO
|
|
|
|
//
|
|
|
|
// We use the name meta_description to match the helper for consistency:
|
|
|
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
|
|
|
|
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../config'),
|
|
|
|
filters = require('../filters'),
|
|
|
|
meta_description;
|
|
|
|
|
2015-03-24 16:37:09 +03:00
|
|
|
meta_description = function (options) {
|
|
|
|
options = options || {};
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2015-03-24 16:37:09 +03:00
|
|
|
var context = options.data.root.context,
|
|
|
|
description;
|
|
|
|
|
|
|
|
if (this.meta_description) {
|
|
|
|
description = this.meta_description; // E.g. in {{#foreach}}
|
|
|
|
} else if (_.contains(context, 'paged')) {
|
|
|
|
description = '';
|
|
|
|
} else if (_.contains(context, 'home')) {
|
|
|
|
description = config.theme.description;
|
|
|
|
} else if (_.contains(context, 'author') && this.author) {
|
|
|
|
description = this.author.bio;
|
|
|
|
} else if (_.contains(context, 'tag') && this.tag) {
|
|
|
|
description = this.tag.meta_description;
|
2015-05-20 06:05:33 +03:00
|
|
|
} else if ((_.contains(context, 'post') || _.contains(context, 'page')) && this.post) {
|
2015-03-24 16:37:09 +03:00
|
|
|
description = this.post.meta_description;
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return filters.doFilter('meta_description', description).then(function (description) {
|
|
|
|
description = description || '';
|
|
|
|
return description.trim();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = meta_description;
|