Skip to content

Instantly share code, notes, and snippets.

@ruby0x1
Created January 13, 2014 14:40
Show Gist options
  • Save ruby0x1/8401434 to your computer and use it in GitHub Desktop.
Save ruby0x1/8401434 to your computer and use it in GitHub Desktop.
Ghost blogging platform helper for excerpt until the first --- in the post.
coreHelpers.excerpt_till_hrule = function (options) {
console.log(options);
var truncateOptions = (options || {}).hash || {},
excerpt;
truncateOptions = _.pick(truncateOptions, ['words', 'characters']);
_.keys(truncateOptions).map(function (key) {
truncateOptions[key] = parseInt(truncateOptions[key], 10);
});
if (!truncateOptions.words && !truncateOptions.characters) {
truncateOptions.words = 50;
}
/*jslint regexp:true */
excerpt = String(this.html).replace(/<\/?[^>]+>/gi, '');
excerpt = excerpt.replace(/(\r\n|\n|\r)+/gm, ' ');
var hrule_regex = /([\s\S]*?)<hr \/>/gi;
/*jslint regexp:false */
var _matches = hrule_regex.exec( String(this.html) );
if(_matches) {
excerpt = String(_matches[1]);
} else {
return new hbs.handlebars.SafeString(
downsize(excerpt, truncateOptions)
);
}
return new hbs.handlebars.SafeString( excerpt );
};
@samzeng
Copy link

samzeng commented Mar 1, 2014

there are empty <p></p> before and after the <hr /> P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment