mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
5605c964e4
refs #7491 - this hack is so legacy I almost forgot about it 😈 - in the beginning of Ghost there were no post images - someone figured out you could do {{content words="0"}} and it would pull out the first image in your post - this was never documented, but enough theme developers found it that when we upgraded downsize to get rid of the bug - we needed to add a hack to keep compatibility. - This has to die in 🔥 for Ghost 1.0
31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
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.
|
|
|
|
var hbs = require('express-hbs'),
|
|
_ = require('lodash'),
|
|
downsize = require('downsize'),
|
|
content;
|
|
|
|
content = function (options) {
|
|
var truncateOptions = (options || {}).hash || {};
|
|
truncateOptions = _.pick(truncateOptions, ['words', 'characters']);
|
|
_.keys(truncateOptions).map(function (key) {
|
|
truncateOptions[key] = parseInt(truncateOptions[key], 10);
|
|
});
|
|
|
|
if (truncateOptions.hasOwnProperty('words') || truncateOptions.hasOwnProperty('characters')) {
|
|
return new hbs.handlebars.SafeString(
|
|
downsize(this.html, truncateOptions)
|
|
);
|
|
}
|
|
|
|
return new hbs.handlebars.SafeString(this.html);
|
|
};
|
|
|
|
module.exports = content;
|