2014-10-10 18:54:07 +04:00
|
|
|
// # Post Class Helper
|
|
|
|
// Usage: `{{post_class}}`
|
|
|
|
//
|
|
|
|
// Output classes for the body element
|
2021-09-28 17:06:33 +03:00
|
|
|
const {SafeString} = require('../services/rendering');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2017-11-01 16:44:54 +03:00
|
|
|
// We use the name post_class to match the helper for consistency:
|
|
|
|
module.exports = function post_class() { // eslint-disable-line camelcase
|
2020-04-29 18:44:27 +03:00
|
|
|
let classes = ['post'];
|
|
|
|
|
|
|
|
const tags = this.post && this.post.tags ? this.post.tags : this.tags || [];
|
|
|
|
const featured = this.post && this.post.featured ? this.post.featured : this.featured || false;
|
|
|
|
const image = this.post && this.post.feature_image ? this.post.feature_image : this.feature_image || false;
|
|
|
|
const page = this.post && this.post.page ? this.post.page : this.page || false;
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
if (tags) {
|
2017-04-04 19:07:35 +03:00
|
|
|
classes = classes.concat(tags.map(function (tag) {
|
|
|
|
return 'tag-' + tag.slug;
|
|
|
|
}));
|
2014-10-10 18:54:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (featured) {
|
|
|
|
classes.push('featured');
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:02:21 +03:00
|
|
|
if (!image) {
|
|
|
|
classes.push('no-image');
|
|
|
|
}
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
if (page) {
|
|
|
|
classes.push('page');
|
|
|
|
}
|
|
|
|
|
2020-03-30 23:23:02 +03:00
|
|
|
classes = classes.reduce(function (memo, item) {
|
2017-04-04 19:07:35 +03:00
|
|
|
return memo + ' ' + item;
|
|
|
|
}, '');
|
2020-03-30 23:23:02 +03:00
|
|
|
|
2017-04-04 19:07:35 +03:00
|
|
|
return new SafeString(classes.trim());
|
2014-10-10 18:54:07 +04:00
|
|
|
};
|