Node.js based forum software built for the modern web
dedicated stylesheet.css route for LESS compilation, no longer usin less-middleware for base theme...
Julian Lam53f1e4d3d418
diff --git a/package.json b/package.jsonindex f35c875dc3..7fff110bd6 100644--- a/package.json+++ b/package.json@@ -42,7 +42,8 @@"nodebb-widget-essentials": "~0.0","nodebb-theme-vanilla": "~0.0.14","nodebb-theme-cerulean": "~0.0.13",- "nodebb-theme-lavender": "~0.0.21"+ "nodebb-theme-lavender": "~0.0.21",+ "less": "^1.6.3"},"optionalDependencies": {"redis": "0.8.3",diff --git a/public/templates/header.tpl b/public/templates/header.tplindex 5e4c0e2d4a..4a5aa70794 100644--- a/public/templates/header.tpl+++ b/public/templates/header.tpl@@ -6,7 +6,7 @@<meta<!-- IF metaTags.name --> name="{metaTags.name}"<!-- ENDIF metaTags.name --><!-- IF metaTags.property --> property="{metaTags.property}"<!-- ENDIF metaTags.property --><!-- IF metaTags.content --> content="{metaTags.content}"<!-- ENDIF metaTags.content --> /><!-- END metaTags --><link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css">- <link rel="stylesheet" type="text/css" href="{relative_path}/css/theme.css?{cache-buster}" />+ <link rel="stylesheet" type="text/css" href="{relative_path}/stylesheet.css?{cache-buster}" /><!-- IF bootswatchCSS --><link href="{bootswatchCSS}" rel="stylesheet" media="screen"><!-- ENDIF bootswatchCSS --><!-- BEGIN linkTags --><link<!-- IF linkTags.link --> link="{linkTags.link}"<!-- ENDIF linkTags.link --><!-- IF linkTags.rel --> rel="{linkTags.rel}"<!-- ENDIF linkTags.rel --><!-- IF linkTags.type --> type="{linkTags.type}"<!-- ENDIF linkTags.type --><!-- IF linkTags.href --> href="{linkTags.href}"<!-- ENDIF linkTags.href --> />diff --git a/src/plugins.js b/src/plugins.jsindex 8da34ebfe2..5dad12632a 100644--- a/src/plugins.js+++ b/src/plugins.js@@ -16,6 +16,7 @@ var fs = require('fs'),Plugins.loadedHooks = {};Plugins.staticDirs = {};Plugins.cssFiles = [];+ Plugins.lessFiles = [];Plugins.initialized = false;@@ -221,6 +222,20 @@ var fs = require('fs'),} else {next();}+ },+ function(next) {+ // LESS files for plugins+ if (pluginData.less && pluginData.less instanceof Array) {+ if (global.env === 'development') {+ winston.info('[plugins] Found ' + pluginData.less.length + ' LESS file(s) for plugin ' + pluginData.id);+ }++ Plugins.lessFiles = Plugins.lessFiles.concat(pluginData.less.map(function(file) {+ return path.join(pluginData.id, file);+ }));+ }++ next();}], function(err) {if (!err) {diff --git a/src/routes/theme.js b/src/routes/theme.jsnew file mode 100644index 0000000000..f4e260352f--- /dev/null+++ b/src/routes/theme.js@@ -0,0 +1,47 @@+var path = require('path'),+ nconf = require('nconf'),+ less = require('less'),++ meta = require('../meta'),+ db = require('../database'),+ plugins = require('../plugins');++(function (Meta) {+ Meta.createRoutes = function(app) {+ app.get('/stylesheet.css', function(req, res) {+ db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {+ var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'),+ baseThemePath = path.join(nconf.get('themes_path'), themeId),+ paths = [baseThemePath, path.join(__dirname, '../../node_modules')],+ source = '@import "./theme";',+ x, numLESS;++ // Add the imports for each LESS file+ for(x=0,numLESS=plugins.lessFiles.length;x<numLESS;x++) {+ source += '\n@import "./' + plugins.lessFiles[x] + '";';+ }++ // Detect if a theme has been selected, and handle appropriately+ if (!themeData['theme:type'] || themeData['theme:type'] === 'local') {+ // Local theme+ var parser = new (less.Parser)({+ paths: paths+ });++ parser.parse(source, function(err, tree) {+ if (err) {+ res.send(500, err.message);+ console.log(err);+ return;+ }++ res.type('text/css').send(200, tree.toCSS());+ });+ } else {+ // Bootswatch theme not supported yet+ res.send(500, 'Give me time!');+ }+ });+ });+ };+})(exports);\ No newline at end of filediff --git a/src/webserver.js b/src/webserver.jsindex 5ae87ab622..50fcae9035 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -22,16 +22,18 @@ var path = require('path'),topics = require('./topics'),ThreadTools = require('./threadTools'),notifications = require('./notifications'),- admin = require('./routes/admin'),- userRoute = require('./routes/user'),- apiRoute = require('./routes/api'),- feedsRoute = require('./routes/feeds'),auth = require('./routes/authentication'),meta = require('./meta'),plugins = require('./plugins'),logger = require('./logger'),templates = require('./../public/src/templates'),- translator = require('./../public/src/translator');+ translator = require('./../public/src/translator'),++ admin = require('./routes/admin'),+ userRoute = require('./routes/user'),+ apiRoute = require('./routes/api'),+ feedsRoute = require('./routes/feeds'),+ themeRoute = require('./routes/theme');if(nconf.get('ssl')) {server = require('https').createServer({@@ -322,13 +324,6 @@ process.on('uncaughtException', function(err) {}}- app.use(require('less-middleware')({- src: path.join(nconf.get('themes_path'), themeId),- dest: path.join(__dirname, '../public/css'),- prefix: nconf.get('relative_path') + '/css',- yuicompress: app.enabled('minification') ? true : false- }));-next();} else {// If not using a local theme (bootswatch, etc), drop back to vanilla@@ -487,8 +482,8 @@ process.on('uncaughtException', function(err) {};app.namespace(nconf.get('relative_path'), function () {-auth.registerApp(app);+ themeRoute.createRoutes(app);admin.createRoutes(app);userRoute.createRoutes(app);apiRoute.createRoutes(app);