mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
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
This commit is contained in:
parent
d169bba3f8
commit
f1317b84af
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user