2013-07-07 21:54:50 +04:00
|
|
|
var _ = require('underscore');
|
|
|
|
|
2013-07-01 23:24:48 +04:00
|
|
|
var fancyFirstChar;
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-07-07 21:54:50 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-01 23:24:48 +04:00
|
|
|
fancyFirstChar = {
|
|
|
|
init: function (ghost) {
|
|
|
|
ghost.registerFilter('prePostsRender', function (posts) {
|
2013-07-07 21:54:50 +04:00
|
|
|
if (_.isArray(posts)) {
|
|
|
|
_.each(posts, function (post) {
|
2013-07-11 19:27:19 +04:00
|
|
|
post.content = fancify(post.content);
|
2013-07-07 21:54:50 +04:00
|
|
|
});
|
2013-07-11 19:27:19 +04:00
|
|
|
} else if (posts.hasOwnProperty('content')) {
|
|
|
|
posts.content = fancify(posts.content);
|
2013-05-11 20:44:25 +04:00
|
|
|
}
|
2013-07-07 21:54:50 +04:00
|
|
|
|
2013-05-11 20:44:25 +04:00
|
|
|
return posts;
|
|
|
|
});
|
2013-07-01 23:24:48 +04:00
|
|
|
},
|
|
|
|
activate: function () {},
|
|
|
|
deactivate: function () {}
|
|
|
|
};
|
2013-05-29 04:10:39 +04:00
|
|
|
|
2013-07-01 23:24:48 +04:00
|
|
|
module.exports = fancyFirstChar;
|