mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
0238909281
Implements basic functionality described in #227 for loading plugins from a specific directory and having a specific workflow with an init() method and a disable() method.
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
var util = require('util'),
|
|
_ = require('underscore'),
|
|
fancifyPlugin;
|
|
|
|
fancifyPlugin = {
|
|
|
|
// Fancify a single post body
|
|
fancify: function (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;
|
|
},
|
|
|
|
// Fancify a collection of posts
|
|
fancifyPosts: function (posts) {
|
|
var self = this;
|
|
|
|
if (_.isArray(posts)) {
|
|
_.each(posts, function (post) {
|
|
post.content = self.fancify(post.content);
|
|
});
|
|
} else if (posts.hasOwnProperty('content')) {
|
|
posts.content = this.fancify(posts.content);
|
|
}
|
|
|
|
return posts;
|
|
},
|
|
|
|
install: function () {
|
|
|
|
},
|
|
|
|
uninstall: function () {
|
|
|
|
},
|
|
|
|
// Registers the prePostsRender filter to alter the content.
|
|
activate: function (ghost) {
|
|
ghost.registerFilter('prePostsRender', this.fancifyPosts);
|
|
},
|
|
|
|
// Unregister any filters.
|
|
deactivate: function (ghost) {
|
|
ghost.unregisterFilter("prePostsRender", this.fancifyPosts);
|
|
}
|
|
};
|
|
|
|
// Ensure our this context in the important methods
|
|
_.bindAll(fancifyPlugin, "fancifyPosts", "fancify", "activate", "deactivate");
|
|
|
|
module.exports = fancifyPlugin; |