From f1317b84af5ab52e3d06af16d7beb8ee8c4b6554 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 9 Oct 2013 19:51:55 +0100 Subject: [PATCH] Improving tag handling in post_class and body_class closes #967, closes #987 - use slug instead of name (it's unique) - get tags even if we aren't inside the post context - add tag handling to body_class too --- core/server/helpers/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index 85796b64e5..669d44ce29 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -179,7 +179,9 @@ coreHelpers = function (ghost) { 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/)) { classes.push('archive-template'); } else if (!this.path || this.path === '/' || this.path === '') { @@ -188,6 +190,10 @@ coreHelpers = function (ghost) { 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) { var classString = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); return new hbs.handlebars.SafeString(classString.trim()); @@ -195,10 +201,11 @@ coreHelpers = function (ghost) { }); 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) { - classes = classes.concat(this.tags.map(function (tag) { return 'tag-' + tag.name; })); + if (tags) { + classes = classes.concat(tags.map(function (tag) { return 'tag-' + tag.slug; })); } return ghost.doFilter('post_class', classes, function (classes) {