mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
10fc320cc8
no issue - In Ghost, 'context' means the page or section of a blog we're currently within when rendering a theme, e.g. 'post' or 'tag' or 'home'. - In handlebars 'context' refers to the blob of JSON that is tied to a template. - These two uses of the word 'context' have gotten very confusing, so I've removed all usage of 'context' within the Ghost handlebars helpers, EXCEPT where they actually refer to the current context (e.g. the is helper)
26 lines
789 B
JavaScript
26 lines
789 B
JavaScript
// # Excerpt Helper
|
|
// Usage: `{{excerpt}}`, `{{excerpt words="50"}}`, `{{excerpt characters="256"}}`
|
|
//
|
|
// Attempts to remove all HTML from the string, and then shortens the result according to the provided option.
|
|
//
|
|
// Defaults to words="50"
|
|
|
|
var hbs = require('express-hbs'),
|
|
_ = require('lodash'),
|
|
getMetaDataExcerpt = require('../data/meta/excerpt');
|
|
|
|
function excerpt(options) {
|
|
var truncateOptions = (options || {}).hash || {};
|
|
|
|
truncateOptions = _.pick(truncateOptions, ['words', 'characters']);
|
|
_.keys(truncateOptions).map(function (key) {
|
|
truncateOptions[key] = parseInt(truncateOptions[key], 10);
|
|
});
|
|
|
|
return new hbs.handlebars.SafeString(
|
|
getMetaDataExcerpt(String(this.html), truncateOptions)
|
|
);
|
|
}
|
|
|
|
module.exports = excerpt;
|