mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
f8b498d6e7
no issue 🎨 Switch themes API to use config.availableThemes - this gets rid of the only places where settings.availableThemes are used 🔥 Get rid of settings.availableThemes - this is no longer used anywhere - also get rid of every related call to updateSettingsCache 🔥 Replace config.availableThemes with theme cache - Creates a tailor-made in-memory cache for themes inside the theme module - Add methods for getting & setting items on the cache - Move all references to config.availableThemes to use the new cache - This can be abstracted later to support other kinds of caches? 🎨 Start improving theme lib's API Still TODO: simplifying/clarifying: - what is the structure of the internal list - what is the difference between a package list, and a theme list? - what is the difference between reading a theme and loading it? - how do we update the theme list (add/remove) - how do we refresh the theme list? (hot reload?!) - how do we get from an internal list, to one that is sent as part of the API? - how are we going to handle theme storage: read/write, such that the path is configurable 🎨 Use themeList consistently 🎨 Update list after storage
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
var debug = require('debug')('ghost:themes:loader'),
|
|
config = require('../config'),
|
|
events = require('../events'),
|
|
themeList = require('./list'),
|
|
read = require('./read'),
|
|
settingsCache = require('../settings/cache'),
|
|
updateThemeList,
|
|
loadAllThemes,
|
|
loadOneTheme,
|
|
initThemes;
|
|
|
|
updateThemeList = function updateThemeList(themes) {
|
|
debug('loading themes', Object.keys(themes));
|
|
themeList.init(themes);
|
|
};
|
|
|
|
loadAllThemes = function loadAllThemes() {
|
|
return read
|
|
.all(config.getContentPath('themes'))
|
|
.then(updateThemeList);
|
|
};
|
|
|
|
loadOneTheme = function loadOneTheme(themeName) {
|
|
return read
|
|
.one(config.getContentPath('themes'), themeName)
|
|
.then(function (readThemes) {
|
|
// @TODO change read one to not return a keyed object
|
|
return themeList.set(themeName, readThemes[themeName]);
|
|
});
|
|
};
|
|
|
|
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() {
|
|
loadAllThemes();
|
|
});
|
|
|
|
// Just read the active theme for now
|
|
return read
|
|
.one(config.getContentPath('themes'), settingsCache.get('activeTheme'))
|
|
.then(updateThemeList);
|
|
};
|
|
|
|
module.exports = {
|
|
init: initThemes,
|
|
loadAllThemes: loadAllThemes,
|
|
loadOneTheme: loadOneTheme
|
|
};
|