mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
fixed #4093
This commit is contained in:
@@ -56,17 +56,13 @@ Templates.compile = function(callback) {
|
|||||||
},
|
},
|
||||||
baseTpls: function(next) {
|
baseTpls: function(next) {
|
||||||
utils.walk(baseTemplatesPath, next);
|
utils.walk(baseTemplatesPath, next);
|
||||||
},
|
|
||||||
themeTpls: function(next) {
|
|
||||||
utils.walk(themeTemplatesPath, next);
|
|
||||||
}
|
}
|
||||||
}, function(err, data) {
|
}, function(err, data) {
|
||||||
var coreTpls = data.coreTpls,
|
var coreTpls = data.coreTpls,
|
||||||
baseTpls = data.baseTpls,
|
baseTpls = data.baseTpls,
|
||||||
themeTpls = data.themeTpls,
|
|
||||||
paths = {};
|
paths = {};
|
||||||
|
|
||||||
if (!baseTpls || !themeTpls) {
|
if (!baseTpls) {
|
||||||
winston.warn('[meta/templates] Could not find base template files at: ' + baseTemplatesPath);
|
winston.warn('[meta/templates] Could not find base template files at: ' + baseTemplatesPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +76,7 @@ Templates.compile = function(callback) {
|
|||||||
baseTpls.forEach(function(el, i) {
|
baseTpls.forEach(function(el, i) {
|
||||||
paths[baseTpls[i]] = path.join(baseTemplatesPath, baseTpls[i]);
|
paths[baseTpls[i]] = path.join(baseTemplatesPath, baseTpls[i]);
|
||||||
});
|
});
|
||||||
|
// console.log(pluginTemplates);
|
||||||
|
|
||||||
for (var tpl in pluginTemplates) {
|
for (var tpl in pluginTemplates) {
|
||||||
if (pluginTemplates.hasOwnProperty(tpl)) {
|
if (pluginTemplates.hasOwnProperty(tpl)) {
|
||||||
|
|||||||
@@ -152,16 +152,48 @@ var fs = require('fs'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Plugins.getTemplates = function(callback) {
|
Plugins.getTemplates = function(callback) {
|
||||||
var templates = {};
|
var templates = {},
|
||||||
|
tplName;
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
async.apply(db.getSortedSetRange, 'plugins:active', 0, -1),
|
||||||
|
function(plugins, next) {
|
||||||
|
var pluginBasePath = path.join(__dirname, '../node_modules');
|
||||||
|
var paths = plugins.map(function(plugin) {
|
||||||
|
return path.join(pluginBasePath, plugin);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter out plugins with invalid paths
|
||||||
|
async.filter(paths, function(path, next) {
|
||||||
|
fs.access(path, fs.R_OK, function(err) {
|
||||||
|
next(!err);
|
||||||
|
});
|
||||||
|
}, function(paths) {
|
||||||
|
next(null, paths);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(paths, next) {
|
||||||
|
async.map(paths, Plugins.loadPluginInfo, next);
|
||||||
|
}
|
||||||
|
], function(err, plugins) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
Plugins.showInstalled(function(err, plugins) {
|
|
||||||
async.each(plugins, function(plugin, next) {
|
async.each(plugins, function(plugin, next) {
|
||||||
if (plugin.id && plugin.active && (plugin.templates || plugin.id.startsWith('nodebb-theme-'))) {
|
if (plugin.templates || plugin.id.startsWith('nodebb-theme-')) {
|
||||||
|
winston.verbose('[plugins] Loading templates (' + plugin.id + ')');
|
||||||
var templatesPath = path.join(__dirname, '../node_modules', plugin.id, plugin.templates || 'templates');
|
var templatesPath = path.join(__dirname, '../node_modules', plugin.id, plugin.templates || 'templates');
|
||||||
utils.walk(templatesPath, function(err, pluginTemplates) {
|
utils.walk(templatesPath, function(err, pluginTemplates) {
|
||||||
if (pluginTemplates) {
|
if (pluginTemplates) {
|
||||||
pluginTemplates.forEach(function(pluginTemplate) {
|
pluginTemplates.forEach(function(pluginTemplate) {
|
||||||
templates["/" + pluginTemplate.replace(templatesPath, '').substring(1)] = pluginTemplate;
|
tplName = "/" + pluginTemplate.replace(templatesPath, '').substring(1);
|
||||||
|
|
||||||
|
if (templates.hasOwnProperty(tplName)) {
|
||||||
|
winston.verbose('[plugins] ' + tplName + ' replaced by ' + plugin.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
templates[tplName] = pluginTemplate;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
winston.warn('[plugins/' + plugin.id + '] A templates directory was defined for this plugin, but was not found.');
|
winston.warn('[plugins/' + plugin.id + '] A templates directory was defined for this plugin, but was not found.');
|
||||||
|
|||||||
Reference in New Issue
Block a user