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;
|
|
|
|
|
|
|
|
meta_description = function () {
|
|
|
|
var description,
|
2015-01-31 01:20:47 +03:00
|
|
|
blog,
|
|
|
|
pagePattern = new RegExp('\\/page\\/');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
if (_.isString(this.relativeUrl)) {
|
|
|
|
blog = config.theme;
|
|
|
|
if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '') {
|
|
|
|
description = blog.description;
|
|
|
|
} else if (this.author) {
|
2015-01-31 01:20:47 +03:00
|
|
|
description = pagePattern.test(this.relativeUrl) ? '' : this.author.bio;
|
2014-12-21 14:39:49 +03:00
|
|
|
} else if (this.tag) {
|
2015-01-31 01:20:47 +03:00
|
|
|
if (pagePattern.test(this.relativeUrl)) {
|
2014-12-21 14:39:49 +03:00
|
|
|
description = '';
|
|
|
|
} else {
|
|
|
|
description = _.isEmpty(this.tag.meta_description) ? '' : this.tag.meta_description;
|
|
|
|
}
|
2014-10-10 18:54:07 +04:00
|
|
|
} else if (this.post) {
|
|
|
|
description = _.isEmpty(this.post.meta_description) ? '' : this.post.meta_description;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filters.doFilter('meta_description', description).then(function (description) {
|
|
|
|
description = description || '';
|
|
|
|
return description.trim();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = meta_description;
|