Created
January 13, 2014 14:40
-
-
Save ruby0x1/8401434 to your computer and use it in GitHub Desktop.
Ghost blogging platform helper for excerpt until the first --- in the post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
there are empty
<p></p>
before and after the<hr />
P