Skip to content

Node.js based forum software built for the modern web

Added ability to change where themes are stored via themes_dir configuration option

Micheil Smith691fde0a27b1
diff --git a/app.js b/app.js
index c485703e3f..6290677b4d 100644
--- a/app.js
+++ b/app.js
@@ -79,10 +79,17 @@ function start() {
file: __dirname + '/config.json'
});
+ nconf.defaults({
+ themes_dir: path.join(__dirname, 'node_modules')
+ });
+
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));
nconf.set('upload_url', path.join(path.sep, nconf.get('relative_path'), 'uploads', path.sep));
nconf.set('base_dir', __dirname);
+ // Ensure themes_dir is a full filepath
+ nconf.set('themes_dir', path.resolve(__dirname, nconf.get('themes_dir')));
+
winston.info('Time: ' + new Date());
winston.info('Initializing NodeBB v' + pkg.version + ', using ' + nconf./**/get('database') +' store at ' + nconf.get(nconf.get('database') + ':host') + ':' + nconf.get(nconf.get('database') + ':port') + '.');
@@ -122,7 +129,7 @@ function start() {
translator.loadServer();
- var customTemplates = meta.config['theme:templates'] ? path.join(__dirname, 'node_modules', meta.config['theme:id'], meta.config['theme:templates']) : false;
+ var customTemplates = meta.config['theme:templates'] ? path.join(nconf.get('themes_dir'), meta.config['theme:id'], meta.config['theme:templates']) : false;
utils.walk(path.join(__dirname, 'public/templates'), function (err, tplsToLoad) {
templates.init(tplsToLoad, customTemplates);
diff --git a/src/meta.js b/src/meta.js
index 13a6c8f41c..14f3d87b5b 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -85,7 +85,7 @@ var fs = require('fs'),
Meta.themes = {
get: function (callback) {
- var themePath = path.join(__dirname, '../node_modules');
+ var themePath = nconf.get('themes_dir');
fs.readdir(themePath, function (err, files) {
async.filter(files, function (file, next) {
fs.stat(path.join(themePath, file), function (err, fileStat) {
@@ -132,7 +132,7 @@ var fs = require('fs'),
case 'local':
async.waterfall([
function(next) {
- fs.readFile(path.join(__dirname, '../node_modules', data.id, 'theme.json'), function(err, config) {
+ fs.readFile(path.join(nconf.get('themes_dir'), data.id, 'theme.json'), function(err, config) {
if (!err) {
config = JSON.parse(config.toString());
next(null, config);
diff --git a/src/webserver.js b/src/webserver.js
index ed79448f82..1771b234ce 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -255,7 +255,7 @@ module.exports.server = server;
// Theme's static directory
if (themeData['theme:staticDir']) {
- app.use('/css/assets', express.static(path.join(__dirname, '../node_modules', themeData['theme:id'], themeData['theme:staticDir']), {
+ app.use('/css/assets', express.static(path.join(__dirname, nconf.get('themes_dir'), themeData['theme:id'], themeData['theme:staticDir']), {
maxAge: app.enabled('cache') ? 5184000000 : 0
}));
if (process.env.NODE_ENV === 'development') {
@@ -264,7 +264,7 @@ module.exports.server = server;
}
if (themeData['theme:templates']) {
- app.use('/templates', express.static(path.join(__dirname, '../node_modules', themeData['theme:id'], themeData['theme:templates']), {
+ app.use('/templates', express.static(path.join(__dirname, nconf.get('themes_dir'), themeData['theme:id'], themeData['theme:templates']), {
maxAge: app.enabled('cache') ? 5184000000 : 0
}));
if (process.env.NODE_ENV === 'development') {
@@ -273,7 +273,7 @@ module.exports.server = server;
}
app.use(require('less-middleware')({
- src: path.join(__dirname, '../node_modules/' + themeId),
+ src: path.join(__dirname, nconf.get('themes_dir') + themeId),
dest: path.join(__dirname, '../public/css'),
prefix: nconf.get('relative_path') + '/css',
yuicompress: app.enabled('minification') ? true : false
@@ -287,7 +287,7 @@ module.exports.server = server;
}
app.use(require('less-middleware')({
- src: path.join(__dirname, '../node_modules/nodebb-theme-vanilla'),
+ src: path.join(__dirname, nconf.get('themes_dir'), '/nodebb-theme-vanilla'),
dest: path.join(__dirname, '../public/css'),
prefix: nconf.get('relative_path') + '/css',
yuicompress: app.enabled('minification') ? true : false
@@ -303,7 +303,7 @@ module.exports.server = server;
async.each(themes, function(themeObj, next) {
if (themeObj.screenshot) {
- screenshotPath = path.join(__dirname, '../node_modules', themeObj.id, themeObj.screenshot);
+ screenshotPath = path.join(__dirname, nconf.get('themes_dir'), themeObj.id, themeObj.screenshot);
(function(id, path) {
fs.exists(path, function(exists) {
if (exists) {