mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 07:51:55 +03:00
c5fe9aa99f
closes #4850 - fixed `meta_description` and `meta_title` when used within a `{{#foreach}}` - `meta_description` and `meta_title` now depend upon the current context to get the right string (author bio, tag description, ...). Note: `ghost_head.js` and `ghost_head_spec.js` have been touched to add the required context information when calling the helpers.
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
// # 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 (options) {
|
|
options = options || {};
|
|
|
|
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;
|
|
} else if (_.contains(context, 'post') && this.post) {
|
|
description = this.post.meta_description;
|
|
} else if (_.contains(context, 'page') && this.page) {
|
|
description = this.page.meta_description;
|
|
}
|
|
|
|
return filters.doFilter('meta_description', description).then(function (description) {
|
|
description = description || '';
|
|
return description.trim();
|
|
});
|
|
};
|
|
|
|
module.exports = meta_description;
|