2017-02-22 02:26:19 +03:00
|
|
|
var debug = require('debug')('ghost:themes:loader'),
|
|
|
|
config = require('../config'),
|
|
|
|
events = require('../events'),
|
|
|
|
read = require('./read'),
|
|
|
|
settingsApi = require('../api/settings'),
|
2017-02-27 18:53:04 +03:00
|
|
|
settingsCache = require('../settings/cache'),
|
2017-02-22 02:26:19 +03:00
|
|
|
updateConfigAndCache,
|
|
|
|
loadThemes,
|
|
|
|
initThemes;
|
|
|
|
|
|
|
|
updateConfigAndCache = function updateConfigAndCache(themes) {
|
2017-02-28 01:30:49 +03:00
|
|
|
debug('loading themes', Object.keys(themes));
|
2017-02-22 02:26:19 +03:00
|
|
|
config.set('paths:availableThemes', themes);
|
|
|
|
settingsApi.updateSettingsCache();
|
|
|
|
};
|
|
|
|
|
|
|
|
loadThemes = function loadThemes() {
|
|
|
|
return read
|
|
|
|
.all(config.getContentPath('themes'))
|
|
|
|
.then(updateConfigAndCache);
|
|
|
|
};
|
|
|
|
|
|
|
|
initThemes = function initThemes() {
|
2017-02-27 18:53:04 +03:00
|
|
|
debug('init themes', settingsCache.get('activeTheme'));
|
2017-02-22 02:26:19 +03:00
|
|
|
|
|
|
|
// 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
|
2017-02-27 18:53:04 +03:00
|
|
|
.one(config.getContentPath('themes'), settingsCache.get('activeTheme'))
|
2017-02-22 02:26:19 +03:00
|
|
|
.then(updateConfigAndCache);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init: initThemes,
|
|
|
|
load: loadThemes
|
|
|
|
};
|