0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Merge branch 'ffc-fix' into version-0.2.0

This commit is contained in:
Hannah Wolfe 2013-07-07 19:41:28 +01:00
commit 605cd85f0b
2 changed files with 33 additions and 21 deletions

View file

@ -1,29 +1,36 @@
var _ = require('underscore');
var fancyFirstChar; var fancyFirstChar;
function fancify(originalContent) {
var newContent,
firstCharIndex = 0;
if (originalContent.substr(0, 1) === '<') {
firstCharIndex = originalContent.indexOf('>') + 1;
}
newContent = originalContent.substr(0, firstCharIndex);
newContent += '<span class="fancyChar">';
newContent += originalContent.substr(firstCharIndex, 1);
newContent += '</span>';
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
return newContent;
}
fancyFirstChar = { fancyFirstChar = {
init: function (ghost) { init: function (ghost) {
ghost.registerFilter('prePostsRender', function (posts) { ghost.registerFilter('prePostsRender', function (posts) {
var post, if (_.isArray(posts)) {
originalContent, _.each(posts, function (post) {
newContent, post.content_html = fancify(post.content_html);
firstCharIndex = 0; });
} else if (posts.hasOwnProperty('content_html')) {
for (post in posts) { posts.content_html = fancify(posts.content_html);
if (posts.hasOwnProperty(post)) {
originalContent = posts[post].content_html;
if (originalContent.substr(0, 1) === '<') {
firstCharIndex = originalContent.indexOf('>') + 1;
}
newContent = originalContent.substr(0, firstCharIndex);
newContent += '<span class="fancyChar">';
newContent += originalContent.substr(firstCharIndex, 1);
newContent += '</span>';
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
posts[post].content_html = newContent;
}
} }
return posts; return posts;
}); });
}, },

View file

@ -234,7 +234,12 @@ Ghost.prototype.doFilter = function (name, args, callback) {
// Call each handler for this priority level // Call each handler for this priority level
_.each(callbacks[priority], function (filterHandler) { _.each(callbacks[priority], function (filterHandler) {
args = filterHandler(args); try {
args = filterHandler(args);
} catch (e) {
// If a filter causes an error, we log it so that it can be debugged, but do not throw the error
errors.logError(e);
}
}); });
}); });