mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
fixing screenshot previews in admin/themes
This commit is contained in:
@@ -73,7 +73,7 @@ define(function() {
|
||||
if (themes.length > 0) {
|
||||
for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
|
||||
liEl.setAttribute('data-theme', themes[x].id);
|
||||
liEl.innerHTML = '<img src="' + themes[x].screenshot + '" />' +
|
||||
liEl.innerHTML = '<img src="' + (themes[x].screenshot ? '/css/previews/' + themes[x].id : RELATIVE_PATH + '/images/themes/default.png') + '" />' +
|
||||
'<div>' +
|
||||
'<div class="pull-right">' +
|
||||
'<button class="btn btn-primary" data-action="use">Use</button> ' +
|
||||
|
||||
15
src/meta.js
15
src/meta.js
@@ -80,20 +80,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
if (fs.existsSync(config)) {
|
||||
fs.readFile(config, function (err, file) {
|
||||
if (err) return next();
|
||||
else {
|
||||
var configObj = JSON.parse(file.toString());
|
||||
if (configObj.staticDir && configObj.screenshot) {
|
||||
// Verify that the provided path leads to a file that exists
|
||||
fs.exists(path.join(__dirname, '../node_modules/', configObj.id, configObj.staticDir, configObj.screenshot), function(exists) {
|
||||
if (exists) {
|
||||
configObj.screenshot = path.join('/css/assets/', configObj.screenshot);
|
||||
} else {
|
||||
configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png';
|
||||
}
|
||||
|
||||
next(err, configObj);
|
||||
});
|
||||
} else {
|
||||
configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png';
|
||||
next(err, configObj);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -215,6 +215,26 @@ var express = require('express'),
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
// Route paths to screenshots for installed themes
|
||||
meta.themes.get(function(err, themes) {
|
||||
var screenshotPath;
|
||||
|
||||
async.each(themes, function(themeObj, next) {
|
||||
if (themeObj.screenshot) {
|
||||
screenshotPath = path.join(__dirname, '../node_modules', themeObj.id, themeObj.screenshot);
|
||||
fs.exists(screenshotPath, function(exists) {
|
||||
if (exists) {
|
||||
app.get('/css/previews/' + themeObj.id, function(req, res) {
|
||||
res.sendfile(screenshotPath);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
next(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
], next);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user