Merge pull request #996 from ErisDS/0.3.2-tagfixes

Improving tag handling in post_class and body_class
This commit is contained in:
Hannah Wolfe 2013-10-10 07:05:15 -07:00
commit 54f8a04779

View File

@ -179,7 +179,9 @@ coreHelpers = function (ghost) {
ghost.registerThemeHelper('body_class', function (options) { ghost.registerThemeHelper('body_class', function (options) {
var classes = []; var classes = [],
tags = this.post && this.post.tags ? this.post.tags : this.tags || [];
if (_.isString(this.path) && this.path.match(/\/page/)) { if (_.isString(this.path) && this.path.match(/\/page/)) {
classes.push('archive-template'); classes.push('archive-template');
} else if (!this.path || this.path === '/' || this.path === '') { } else if (!this.path || this.path === '/' || this.path === '') {
@ -188,6 +190,10 @@ coreHelpers = function (ghost) {
classes.push('post-template'); classes.push('post-template');
} }
if (tags) {
classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; }));
}
return ghost.doFilter('body_class', classes, function (classes) { return ghost.doFilter('body_class', classes, function (classes) {
var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, '');
return new hbs.handlebars.SafeString(classString.trim()); return new hbs.handlebars.SafeString(classString.trim());
@ -195,10 +201,11 @@ coreHelpers = function (ghost) {
}); });
ghost.registerThemeHelper('post_class', function (options) { ghost.registerThemeHelper('post_class', function (options) {
var classes = ['post']; var classes = ['post'],
tags = this.post && this.post.tags ? this.post.tags : this.tags || [];
if (this.tags) { if (tags) {
classes = classes.concat(this.tags.map(function (tag) { return 'tag-' + tag.name; })); classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; }));
} }
return ghost.doFilter('post_class', classes, function (classes) { return ghost.doFilter('post_class', classes, function (classes) {