How to use the @tryghost/helpers.utils.visibility function in @tryghost/helpers

To help you get started, we’ve selected a few @tryghost/helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TryGhost / Ghost / core / frontend / helpers / foreach.js View on Github external
module.exports = function foreach(items, options) {
    if (!options) {
        logging.warn(i18n.t('warnings.helpers.foreach.iteratorNeeded'));
    }

    if (hbsUtils.isFunction(items)) {
        items = items.call(this);
    }

    // Exclude items which should not be visible in the theme
    items = ghostHelperUtils.visibility.filter(items, options.hash.visibility);

    // Initial values set based on parameters sent through. If nothing sent, set to defaults
    const {fn, inverse, hash, data, ids} = options;
    let {columns, limit, from, to} = hash;
    let length = _.size(items);
    let output = '';
    let frame;
    let contextPath;

    limit = parseInt(limit, 10) || length;
    from = parseInt(from, 10) || 1;
    to = parseInt(to, 10) || length;

    // If a limit option was sent through (aka not equal to default (length))
    // and from plus limit is less than the length, set to to the from + limit
    if ((limit < length) && ((from + limit) <= length)) {
github chadly / ghost / core / frontend / helpers / foreach.js View on Github external
module.exports = function foreach(items, options) {
    if (!options) {
        logging.warn(i18n.t('warnings.helpers.foreach.iteratorNeeded'));
    }

    if (hbsUtils.isFunction(items)) {
        items = items.call(this);
    }

    // Exclude items which should not be visible in the theme
    items = ghostHelperUtils.visibility.filter(items, options.hash.visibility);

    // Initial values set based on parameters sent through. If nothing sent, set to defaults
    const {fn, inverse, hash, data, ids} = options;
    let {columns, limit, from, to} = hash;
    let length = _.size(items);
    let output = '';
    let frame;
    let contextPath;

    limit = parseInt(limit, 10) || length;
    from = parseInt(from, 10) || 1;
    to = parseInt(to, 10) || length;

    // If a limit option was sent through (aka not equal to default (length))
    // and from plus limit is less than the length, set to to the from + limit
    if ((limit < length) && ((from + limit) <= length)) {
github TryGhost / Ghost / core / frontend / helpers / authors.js View on Github external
function createAuthorsList(authors) {
        function processAuthor(author) {
            return autolink ? templates.link({
                url: urlService.getUrlByResourceId(author.id, {withSubdirectory: true}),
                text: _.escape(author.name)
            }) : _.escape(author.name);
        }

        return ghostHelperUtils.visibility.filter(authors, visibility, processAuthor);
    }
github chadly / ghost / core / frontend / helpers / authors.js View on Github external
function createAuthorsList(authors) {
        function processAuthor(author) {
            return autolink ? templates.link({
                url: urlService.getUrlByResourceId(author.id, {withSubdirectory: true}),
                text: _.escape(author.name)
            }) : _.escape(author.name);
        }

        return ghostHelperUtils.visibility.filter(authors, visibility, processAuthor);
    }
github TryGhost / Ghost / core / frontend / helpers / tags.js View on Github external
function createTagList(tags) {
        function processTag(tag) {
            return autolink ? templates.link({
                url: urlService.getUrlByResourceId(tag.id, {withSubdirectory: true}),
                text: _.escape(tag.name)
            }) : _.escape(tag.name);
        }

        return ghostHelperUtils.visibility.filter(tags, options.hash.visibility, processTag);
    }
github TryGhost / Ghost / core / frontend / meta / keywords.js View on Github external
function getKeywords(data) {
    if (data.post && data.post.tags && data.post.tags.length > 0) {
        return ghostHelperUtils.visibility.filter(data.post.tags, ['public'], function processItem(item) {
            return item.name;
        });
    }
    return null;
}

@tryghost/helpers

Javascript Helpers for working with the Ghost [Content API](https://ghost.org/docs/content-api/)

MIT
Latest version published 7 months ago

Package Health Score

62 / 100
Full package analysis

Similar packages