gpreview
Version:
Preview Ghost themes locally without a full Ghost installation
49 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasHelper = hasHelper;
function hasHelper(attribute, options) {
if (!options || typeof options.fn !== 'function') {
return '';
}
const post = this.post || this.page || this;
const checkHas = (attr) => {
switch (attr) {
case 'tag': {
const tagSlug = options.hash?.slug;
if (tagSlug && post.tags) {
return post.tags.some((tag) => tag.slug === tagSlug);
}
return !!(post.tags && post.tags.length > 0);
}
case 'author': {
const authorSlug = options.hash?.slug;
if (authorSlug && post.authors) {
return post.authors.some((author) => author.slug === authorSlug);
}
return !!(post.authors && post.authors.length > 0);
}
case 'feature_image':
return !!post.feature_image;
case 'visibility': {
const visibility = options.hash?.visibility;
if (visibility) {
return post.visibility === visibility;
}
return !!post.visibility;
}
case 'access':
return !!post.access;
case 'any': {
if (options.hash) {
return Object.keys(options.hash).some(key => checkHas(key));
}
return false;
}
default:
return !!post[attr];
}
};
const result = checkHas(attribute);
return result ? options.fn(this) : options.inverse(this);
}
//# sourceMappingURL=has.js.map