Ghost/core/frontend/helpers/content.js
Nazar Gargol e10e71cc26 Added /frontend folder to default lint command
no issue

- The folder was overseen to be added to lint rules after it has been extracted out of /server
2019-08-08 10:47:13 +02:00

36 lines
992 B
JavaScript

// # Content Helper
// Usage: `{{content}}`, `{{content words="20"}}`, `{{content characters="256"}}`
//
// Turns content html into a safestring so that the user doesn't have to
// escape it or tell handlebars to leave it alone with a triple-brace.
//
// Enables tag-safe truncation of content by characters or words.
const {SafeString} = require('./proxy');
const downsize = require('downsize');
module.exports = function content(options = {}) {
const hash = options.hash || {};
const truncateOptions = {};
let runTruncate = false;
for (const key of ['words', 'characters']) {
if (Object.prototype.hasOwnProperty.call(hash, key)) {
runTruncate = true;
truncateOptions[key] = parseInt(hash[key], 10);
}
}
if (this.html === null) {
this.html = '';
}
if (runTruncate) {
return new SafeString(
downsize(this.html, truncateOptions)
);
}
return new SafeString(this.html);
};