mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-04 04:10:33 +03:00
35e3e0708c
- The proxy is not a helper, we want the helpers folder to only include helpers - The proxy is also meant to be the interface to Ghost for the helpers, and we want to enforce that - This is a small step on the way
36 lines
1002 B
JavaScript
36 lines
1002 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('../services/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);
|
|
};
|