0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/frontend/helpers/post_class.js
Hannah Wolfe 658a6dd284 Cleaned all usages of proxy in helpers
- the proxy should always be used to access other parts of Ghost, including the urlService etc
- use consistent ES6 style for requires
- minimise use of lodash where possible
- remove circular dependency between proxy and template util
- End goal here is to enforce that the only link between helpers + the rest of Ghost is the proxy
2020-03-31 12:42:15 +01:00

38 lines
1.1 KiB
JavaScript

// # Post Class Helper
// Usage: `{{post_class}}`
//
// Output classes for the body element
const {SafeString} = require('./proxy');
// We use the name post_class to match the helper for consistency:
module.exports = function post_class() { // eslint-disable-line camelcase
var classes = ['post'],
tags = this.post && this.post.tags ? this.post.tags : this.tags || [],
featured = this.post && this.post.featured ? this.post.featured : this.featured || false,
image = this.post && this.post.feature_image ? this.post.feature_image : this.feature_image || false,
page = this.post && this.post.page ? this.post.page : this.page || false;
if (tags) {
classes = classes.concat(tags.map(function (tag) {
return 'tag-' + tag.slug;
}));
}
if (featured) {
classes.push('featured');
}
if (!image) {
classes.push('no-image');
}
if (page) {
classes.push('page');
}
classes = classes.reduce(function (memo, item) {
return memo + ' ' + item;
}, '');
return new SafeString(classes.trim());
};