How to use the @tryghost/helpers.utils 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 chadly / ghost / core / frontend / helpers / authors.js View on Github external
'use strict';
// # Authors Helper
// Usage: `{{authors}}`, `{{authors separator=' - '}}`
//
// Returns a string of the authors on the post.
// By default, authors are separated by commas.
//
// Note that the standard {{#each authors}} implementation is unaffected by this helper.
const proxy = require('./proxy');
const _ = require('lodash');
const urlService = require('../services/url');
const {SafeString, templates} = proxy;
const ghostHelperUtils = require('@tryghost/helpers').utils;

module.exports = function authors(options = {}) {
    options.hash = options.hash || {};

    let {
        autolink,
        separator = ', ',
        prefix = '',
        suffix = '',
        limit,
        visibility,
        from = 1,
        to
    } = options.hash;
    let output = '';
github chadly / ghost / core / frontend / helpers / foreach.js View on Github external
// # Foreach Helper
// Usage: `{{#foreach data}}{{/foreach}}`
//
// Block helper designed for looping through posts
const _ = require('lodash');
const {logging, i18n, hbs} = require('./proxy');
const {Utils: hbsUtils, handlebars: {createFrame}} = hbs;
const ghostHelperUtils = require('@tryghost/helpers').utils;

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;
github TryGhost / Ghost / core / frontend / helpers / tags.js View on Github external
// # Tags Helper
// Usage: `{{tags}}`, `{{tags separator=' - '}}`
//
// Returns a string of the tags on the post.
// By default, tags are separated by commas.
//
// Note that the standard {{#each tags}} implementation is unaffected by this helper
const proxy = require('./proxy');
const _ = require('lodash');
const ghostHelperUtils = require('@tryghost/helpers').utils;

const urlService = proxy.urlService;
const SafeString = proxy.SafeString;
const templates = proxy.templates;

module.exports = function tags(options) {
    options = options || {};
    options.hash = options.hash || {};

    const autolink = !(_.isString(options.hash.autolink) && options.hash.autolink === 'false'),
        separator = _.isString(options.hash.separator) ? options.hash.separator : ', ',
        prefix = _.isString(options.hash.prefix) ? options.hash.prefix : '',
        suffix = _.isString(options.hash.suffix) ? options.hash.suffix : '',
        limit = options.hash.limit ? parseInt(options.hash.limit, 10) : undefined;

    let output = '',
github TryGhost / Ghost / core / frontend / helpers / authors.js View on Github external
'use strict';
// # Authors Helper
// Usage: `{{authors}}`, `{{authors separator=' - '}}`
//
// Returns a string of the authors on the post.
// By default, authors are separated by commas.
//
// Note that the standard {{#each authors}} implementation is unaffected by this helper.
const proxy = require('./proxy');
const _ = require('lodash');
const urlService = require('../services/url');
const {SafeString, templates} = proxy;
const ghostHelperUtils = require('@tryghost/helpers').utils;

module.exports = function authors(options = {}) {
    options.hash = options.hash || {};

    let {
        autolink,
        separator = ', ',
        prefix = '',
        suffix = '',
        limit,
        visibility,
        from = 1,
        to
    } = options.hash;
    let output = '';
github TryGhost / Ghost / core / frontend / helpers / foreach.js View on Github external
// # Foreach Helper
// Usage: `{{#foreach data}}{{/foreach}}`
//
// Block helper designed for looping through posts
const _ = require('lodash');
const {logging, i18n, hbs} = require('./proxy');
const {Utils: hbsUtils, handlebars: {createFrame}} = hbs;
const ghostHelperUtils = require('@tryghost/helpers').utils;

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;
github TryGhost / Ghost / core / frontend / meta / keywords.js View on Github external
const ghostHelperUtils = require('@tryghost/helpers').utils;

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;
}

module.exports = getKeywords;

@tryghost/helpers

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

MIT
Latest version published 9 days ago

Package Health Score

69 / 100
Full package analysis

Similar packages