mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-13 10:55:58 +03:00
Merge pull request #233 from ErisDS/plugins-2
issue #186 - load plugins (v2)
This commit is contained in:
commit
3b96c7d591
@ -39,6 +39,11 @@ config.themeDir = 'themes';
|
||||
*/
|
||||
config.activeTheme = 'casper';
|
||||
|
||||
|
||||
config.activePlugins = [
|
||||
'fancyFirstChar.js'
|
||||
];
|
||||
|
||||
// Default Navigation Items
|
||||
/**
|
||||
* @property {Array} nav
|
||||
|
@ -1,27 +1,16 @@
|
||||
/*globals exports */
|
||||
(function () {
|
||||
"use strict";
|
||||
var fancyFirstChar;
|
||||
|
||||
var FancyFirstChar;
|
||||
|
||||
FancyFirstChar = function (ghost) {
|
||||
this.ghost = function () {
|
||||
return ghost;
|
||||
};
|
||||
};
|
||||
|
||||
FancyFirstChar.prototype.init = function () {
|
||||
this.ghost().registerFilter('prePostsRender', function (posts) {
|
||||
fancyFirstChar = {
|
||||
init: function (ghost) {
|
||||
ghost.registerFilter('prePostsRender', function (posts) {
|
||||
var post,
|
||||
originalContent,
|
||||
newContent,
|
||||
firstCharIndex = 0;
|
||||
|
||||
|
||||
|
||||
for (post in posts) {
|
||||
if (posts.hasOwnProperty(post)) {
|
||||
originalContent = posts[post].content;
|
||||
originalContent = posts[post].content_html;
|
||||
if (originalContent.substr(0, 1) === '<') {
|
||||
firstCharIndex = originalContent.indexOf('>') + 1;
|
||||
}
|
||||
@ -32,17 +21,14 @@
|
||||
newContent += '</span>';
|
||||
newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1);
|
||||
|
||||
posts[post].content = newContent;
|
||||
posts[post].content_html = newContent;
|
||||
}
|
||||
}
|
||||
return posts;
|
||||
});
|
||||
};
|
||||
},
|
||||
activate: function () {},
|
||||
deactivate: function () {}
|
||||
};
|
||||
|
||||
FancyFirstChar.prototype.activate = function () {};
|
||||
FancyFirstChar.prototype.deactivate = function () {};
|
||||
|
||||
|
||||
|
||||
module.exports = FancyFirstChar;
|
||||
}());
|
||||
module.exports = fancyFirstChar;
|
@ -14,8 +14,10 @@ var config = require('./../config'),
|
||||
models = require('./shared/models'),
|
||||
|
||||
requireTree = require('./shared/require-tree'),
|
||||
themeDirectories = requireTree(path.resolve(__dirname + '../../content/themes')),
|
||||
pluginDirectories = requireTree(path.resolve(__dirname + '../../content/plugins')),
|
||||
themePath = path.resolve(__dirname + '../../content/themes'),
|
||||
pluginPath = path.resolve(__dirname + '../../content/plugins'),
|
||||
themeDirectories = requireTree(themePath),
|
||||
pluginDirectories = requireTree(pluginPath),
|
||||
|
||||
Ghost,
|
||||
instance,
|
||||
@ -113,10 +115,35 @@ Ghost.prototype.init = function () {
|
||||
var self = this;
|
||||
|
||||
return when.join(instance.dataProvider.init(), instance.getPaths()).then(function () {
|
||||
return self.loadPlugins();
|
||||
}, errors.logAndThrowError).then(function () {
|
||||
return self.updateSettingsCache();
|
||||
}, errors.logAndThrowError);
|
||||
};
|
||||
|
||||
Ghost.prototype.loadPlugins = function () {
|
||||
var self = this,
|
||||
pluginPaths = _.values(self.paths().availablePlugins),
|
||||
pluginPromises = [];
|
||||
|
||||
_.each(self.config().activePlugins, function (plugin) {
|
||||
var match = _.find(pluginPaths, function (path) {
|
||||
return new RegExp(plugin + '$').test(path);
|
||||
});
|
||||
|
||||
if (match) {
|
||||
pluginPromises.push(require(path.join(pluginPath, plugin)));
|
||||
}
|
||||
});
|
||||
|
||||
return when.all(pluginPromises).then(function (plugins) {
|
||||
_.each(plugins, function (plugin) {
|
||||
if (_.isFunction(plugin.init)) {
|
||||
plugin.init(self);
|
||||
}
|
||||
});
|
||||
}, errors.logAndThrowError);
|
||||
};
|
||||
|
||||
Ghost.prototype.updateSettingsCache = function (settings) {
|
||||
var self = this;
|
||||
|
Loading…
Reference in New Issue
Block a user