From baf379c6d7edf5ffdeb349451768d3d42150c54b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 19 Oct 2013 16:24:33 -0400 Subject: [PATCH] theme intergration into nodebb based on config hash value --- public/templates/header.tpl | 2 +- src/webserver.js | 41 +++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 0f2885dc18..e0056401b0 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -28,7 +28,7 @@ } - + diff --git a/src/webserver.js b/src/webserver.js index 758665cfef..b70c625323 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -102,7 +102,6 @@ var express = require('express'), prefix: nconf.get('relative_path'), yuicompress: true })); - app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public'))); app.use(express.bodyParser()); // Puts POST vars in request.body app.use(express.cookieParser()); // If you want to parse cookies (res.cookies) app.use(express.session({ @@ -131,20 +130,44 @@ var express = require('express'), next(); }, function(next) { - // Static Directories for NodeBB Plugins - plugins.ready(function () { - for (d in plugins.staticDirs) { - app.use(nconf.get('relative_path') + '/plugins/' + d, express.static(plugins.staticDirs[d])); - if (process.env.NODE_ENV === 'development') winston.info('Static directory routed for plugin: ' + d); - } + async.parallel([ + function(next) { + // Static Directories for NodeBB Plugins + plugins.ready(function () { + for (d in plugins.staticDirs) { + app.use(nconf.get('relative_path') + '/plugins/' + d, express.static(plugins.staticDirs[d])); + if (process.env.NODE_ENV === 'development') winston.info('Static directory routed for plugin: ' + d); + } - next(); - }); + next(); + }); + }, + function(next) { + RDB.hmget('config', 'theme:type', 'theme:id', function(err, themeData) { + if (!themeData[0] || themeData[0] === 'local') { + var themeId = (themeData[1] || 'nodebb-theme-vanilla'); + if (process.env.NODE_ENV === 'development') winston.info('[themes] Using theme ' + themeId); + + app.use(require('less-middleware')({ + src: path.join(__dirname, '../node_modules/' + themeId), + dest: path.join(__dirname, '../public/css'), + prefix: nconf.get('relative_path') + '/css', + yuicompress: true + })); + + next(); + } + }); + } + ], next); }, function(next) { // Router & post-router middlewares app.use(app.router); + // Static directory /public + app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public'))); + // 404 catch-all app.use(function (req, res, next) { res.status(404);