mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 08:20:36 +01:00
special theme.set socket call + static dir support, closes #427, tweaked languages 404 to work with subdirs
This commit is contained in:
@@ -21,24 +21,21 @@ define(function() {
|
|||||||
var parentEl = $(e.target).parents('li'),
|
var parentEl = $(e.target).parents('li'),
|
||||||
themeType = parentEl.attr('data-type'),
|
themeType = parentEl.attr('data-type'),
|
||||||
cssSrc = parentEl.attr('data-css'),
|
cssSrc = parentEl.attr('data-css'),
|
||||||
cssName = parentEl.attr('data-theme');
|
themeId = parentEl.attr('data-theme');
|
||||||
|
|
||||||
socket.emit('api:config.set', {
|
socket.emit('api:admin.theme.set', {
|
||||||
key: 'theme:type',
|
type: themeType,
|
||||||
value: themeType
|
id: themeId,
|
||||||
});
|
src: cssSrc
|
||||||
|
}, function(err) {
|
||||||
socket.emit('api:config.set', {
|
app.alert({
|
||||||
key: 'theme:id',
|
alert_id: 'admin:theme',
|
||||||
value: cssName
|
type: 'success',
|
||||||
});
|
title: 'Theme Changed',
|
||||||
|
message: 'You have successfully changed your NodeBB\'s theme. Please restart to see the changes.',
|
||||||
if (themeType === 'bootswatch') {
|
timeout: 2500
|
||||||
socket.emit('api:config.set', {
|
|
||||||
key: 'theme:src',
|
|
||||||
value: cssSrc
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/meta.js
37
src/meta.js
@@ -98,6 +98,43 @@ var utils = require('./../public/src/utils.js'),
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
set: function(data, callback) {
|
||||||
|
var themeData = {
|
||||||
|
'theme:type': data.type,
|
||||||
|
'theme:id': data.id,
|
||||||
|
'theme:staticDir': ''
|
||||||
|
};
|
||||||
|
|
||||||
|
switch(data.type) {
|
||||||
|
case 'local':
|
||||||
|
async.waterfall([
|
||||||
|
function(next) {
|
||||||
|
fs.readFile(path.join(__dirname, '../node_modules', data.id, 'theme.json'), function(err, config) {
|
||||||
|
if (!err) {
|
||||||
|
config = JSON.parse(config.toString());
|
||||||
|
next(null, config);
|
||||||
|
} else {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(config, next) {
|
||||||
|
if (config.staticDir) {
|
||||||
|
themeData['theme:staticDir'] = config.staticDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
RDB.hmset('config', themeData, next);
|
||||||
|
}
|
||||||
|
], function(err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'bootswatch':
|
||||||
|
RDB.hmset('config', themeData, callback);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -145,14 +145,25 @@ var express = require('express'),
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
RDB.hmget('config', 'theme:type', 'theme:id', function(err, themeData) {
|
// Theme configuration
|
||||||
|
RDB.hmget('config', 'theme:type', 'theme:id', 'theme:staticDir', function(err, themeData) {
|
||||||
var themeId = (themeData[1] || 'nodebb-theme-vanilla');
|
var themeId = (themeData[1] || 'nodebb-theme-vanilla');
|
||||||
|
|
||||||
|
// Detect if a theme has been selected, and handle appropriately
|
||||||
if (!themeData[0] || themeData[0] === 'local') {
|
if (!themeData[0] || themeData[0] === 'local') {
|
||||||
|
// Local theme
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
winston.info('[themes] Using theme ' + themeId);
|
winston.info('[themes] Using theme ' + themeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Theme's static directory
|
||||||
|
if (themeData[2]) {
|
||||||
|
app.use('/css/assets', express.static(path.join(__dirname, '../node_modules', themeData[1], themeData[2])));
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
winston.info('Static directory routed for theme: ' + themeData[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.use(require('less-middleware')({
|
app.use(require('less-middleware')({
|
||||||
src: path.join(__dirname, '../node_modules/' + themeId),
|
src: path.join(__dirname, '../node_modules/' + themeId),
|
||||||
dest: path.join(__dirname, '../public/css'),
|
dest: path.join(__dirname, '../public/css'),
|
||||||
@@ -189,7 +200,7 @@ var express = require('express'),
|
|||||||
|
|
||||||
// 404 catch-all
|
// 404 catch-all
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
var isLanguage = /^\/language\/[\w]{2,}\/[\w]+\.json/,
|
var isLanguage = /^\/language\/[\w]{2,}\/.*\.json/,
|
||||||
isClientScript = /^\/src\/forum\/[\w]+\.js/;
|
isClientScript = /^\/src\/forum\/[\w]+\.js/;
|
||||||
|
|
||||||
res.status(404);
|
res.status(404);
|
||||||
|
|||||||
@@ -936,6 +936,8 @@ module.exports.init = function(io) {
|
|||||||
callback(err ? err.message : null);
|
callback(err ? err.message : null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('api:admin.theme.set', meta.themes.set);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user