mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
ad349bb3a5
refs https://github.com/TryGhost/Team/issues/1616 - Removed all GA feature flags - Removed `tweetGridCard` alpha flag - Changes to `members-api` and `members-importer` packages: https://github.com/TryGhost/Members/compare/%40tryghost/members-api%408.1.1...%40tryghost/members-api%408.1.2
44 lines
1.6 KiB
JavaScript
44 lines
1.6 KiB
JavaScript
// # Tiers Helper
|
|
// Usage: `{{tiers}}`, `{{tiers separator=' - ' prefix=' : ' suffix=''}}`
|
|
//
|
|
// Returns a string of the tiers with access to the post.
|
|
// By default, tiers are separated by commas.
|
|
const {SafeString, escapeExpression} = require('../services/handlebars');
|
|
|
|
const isString = require('lodash/isString');
|
|
|
|
module.exports = function tiers(options = {}) {
|
|
options = options || {};
|
|
options.hash = options.hash || {};
|
|
|
|
const separator = isString(options.hash.separator) ? options.hash.separator : ', ';
|
|
const lastSeparator = isString(options.hash.lastSeparator) ? options.hash.lastSeparator : ' and ';
|
|
const prefix = isString(options.hash.prefix) ? options.hash.prefix : '';
|
|
let suffix = isString(options.hash.suffix) ? options.hash.suffix : '';
|
|
|
|
let output = '';
|
|
|
|
let accessProductsList = this.tiers;
|
|
|
|
if (accessProductsList && accessProductsList.length > 0) {
|
|
const tierNames = accessProductsList.map((tier) => {
|
|
return escapeExpression(tier.name);
|
|
});
|
|
|
|
if (tierNames.length === 1) {
|
|
output = tierNames[0];
|
|
suffix = isString(options.hash.suffix) ? options.hash.suffix : ' tier';
|
|
} else {
|
|
suffix = isString(options.hash.suffix) ? options.hash.suffix : ' tiers';
|
|
const firsts = tierNames.slice(0, tierNames.length - 1);
|
|
const last = tierNames[tierNames.length - 1];
|
|
output = firsts.join(separator) + lastSeparator + last;
|
|
}
|
|
}
|
|
|
|
if (output) {
|
|
output = prefix + output + suffix;
|
|
}
|
|
|
|
return new SafeString(output);
|
|
};
|