Ghost/core/server/themes/loader.js
Hannah Wolfe 690ff05588 🔥 🎨 Themes & settings misc cleanup (#8061)
no issue

🔥 remove unused loadThemes API method
🚨 Add tests for themes.readOne
🔥 Don't update settings cache for imports
- this isn't needed as of #8057
- settings.edit fires an event, that will result in the update happening automatically
🎨 Move validation to themes
- slowly collecting all theme-related code together
🔥 Reduce DEBUG output
- all this info is a bit tooooo much!
2017-02-27 23:30:49 +01:00

41 lines
1.1 KiB
JavaScript

var debug = require('debug')('ghost:themes:loader'),
config = require('../config'),
events = require('../events'),
read = require('./read'),
settingsApi = require('../api/settings'),
settingsCache = require('../settings/cache'),
updateConfigAndCache,
loadThemes,
initThemes;
updateConfigAndCache = function updateConfigAndCache(themes) {
debug('loading themes', Object.keys(themes));
config.set('paths:availableThemes', themes);
settingsApi.updateSettingsCache();
};
loadThemes = function loadThemes() {
return read
.all(config.getContentPath('themes'))
.then(updateConfigAndCache);
};
initThemes = function initThemes() {
debug('init themes', settingsCache.get('activeTheme'));
// Register a listener for server-start to load all themes
events.on('server:start', function readAllThemesOnServerStart() {
loadThemes();
});
// Just read the active theme for now
return read
.one(config.getContentPath('themes'), settingsCache.get('activeTheme'))
.then(updateConfigAndCache);
};
module.exports = {
init: initThemes,
load: loadThemes
};