Last active
August 29, 2015 14:18
-
-
Save CaiJimmy/53777e7de0f9d2ac591b to your computer and use it in GitHub Desktop.
Ghost More标签
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
content = function (options) { | |
var truncateOptions = (options || {}).hash || {}; | |
truncateOptions = _.pick(truncateOptions, ['words', 'characters', 'more']); | |
_.keys(truncateOptions).map(function (key) { | |
truncateOptions[key] = parseInt(truncateOptions[key], 10); | |
}); | |
if (truncateOptions.hasOwnProperty('words') || truncateOptions.hasOwnProperty('characters')) { | |
// Due to weirdness in downsize the 'words' option | |
// must be passed as a string. refer to #1796 | |
// TODO: when downsize fixes this quirk remove this hack. | |
if (truncateOptions.hasOwnProperty('words')) { | |
truncateOptions.words = truncateOptions.words.toString(); | |
} | |
return new hbs.handlebars.SafeString( | |
downsize(this.html, truncateOptions) | |
); | |
} else if (truncateOptions.hasOwnProperty('more')) { | |
var split = this.html.split('<!--more-->', 2) | |
var output = split[0] | |
if (split[1]) { | |
output += '' | |
} | |
return new hbs.handlebars.SafeString(output) | |
} | |
return new hbs.handlebars.SafeString(this.html); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment