mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
dedicated stylesheet.css route for LESS compilation, no longer usin less-middleware for base theme...
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 --> />
|
||||
|
||||
@@ -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) {
|
||||
|
||||
47
src/routes/theme.js
Normal file
47
src/routes/theme.js
Normal file
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user