mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-02 03:17:06 +02:00
Refactor skins to be built on server-side (#6849)
* WIP * using bootswatch from npm instead of bootswatch CDN url * feat: on-demand client css building for skins * added ability for client-side to select a skin * updated loading and saving logic of bootstrapSkin on client side user settings * fix: broken test for #6849
This commit is contained in:
@@ -141,7 +141,7 @@ module.exports = function (middleware) {
|
||||
results.user['email:confirmed'] = results.user['email:confirmed'] === 1;
|
||||
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
||||
|
||||
setBootswatchCSS(templateValues, res.locals.config);
|
||||
templateValues.bootswatchSkin = parseInt(meta.config.disableCustomUserSkins, 10) !== 1 ? res.locals.config.bootswatchSkin || '' : '';
|
||||
|
||||
var unreadCount = {
|
||||
topic: results.unreadCounts[''] || 0,
|
||||
@@ -272,21 +272,5 @@ module.exports = function (middleware) {
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
function setBootswatchCSS(obj, config) {
|
||||
if (config && config.bootswatchSkin !== 'noskin') {
|
||||
var skinToUse = '';
|
||||
|
||||
if (!meta.config.disableCustomUserSkins) {
|
||||
skinToUse = config.bootswatchSkin;
|
||||
} else if (meta.config.bootswatchSkin) {
|
||||
skinToUse = meta.config.bootswatchSkin;
|
||||
}
|
||||
|
||||
if (skinToUse) {
|
||||
obj.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/3.3.7/' + skinToUse + '/bootstrap.min.css';
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -205,3 +205,15 @@ middleware.delayLoading = function (req, res, next) {
|
||||
|
||||
setTimeout(next, 1000);
|
||||
};
|
||||
|
||||
middleware.buildSkinAsset = function (req, res, next) {
|
||||
// If this middleware is reached, a skin was requested, so it is built on-demand
|
||||
var target = path.basename(req.originalUrl).match(/(client-[a-z]+)/);
|
||||
if (target) {
|
||||
meta.css.buildBundle(target[0], true, function () {
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
setImmediate(next);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user