0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Moved bridge.activateTheme calls into one place

- This is a slightly weird thing, but the intention is to highlight that there are 3 different code paths that can activate a theme
- Ideally we want to unify all the codepaths more, but for now this at least helps us see what is happening where
This commit is contained in:
Hannah Wolfe 2021-07-07 13:58:47 +01:00
parent 496b2bf47b
commit c3774a3fab
No known key found for this signature in database
GPG key ID: 9F8C7532D0A6BA55
3 changed files with 26 additions and 7 deletions

View file

@ -0,0 +1,21 @@
const debug = require('@tryghost/debug')('themes');
const bridge = require('../../../bridge');
/**
* These helper methods mean that the bridge is only required in one place
* And also adds a little debug statement, which is very handy when debugging theme logic
*/
module.exports = {
activateFromBoot: (themeName, theme, checkedTheme) => {
debug('Activating theme (method A on boot)', themeName);
bridge.activateTheme(theme, checkedTheme);
},
activateFromAPI: (themeName, theme, checkedTheme) => {
debug('Activating theme (method B on API "activate")', themeName);
bridge.activateTheme(theme, checkedTheme);
},
activateFromAPIOverride: (themeName, theme, checkedTheme) => {
debug('Activating theme (method C on API "override")', themeName);
bridge.activateTheme(theme, checkedTheme);
}
};

View file

@ -3,9 +3,9 @@ const logging = require('@tryghost/logging');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const themeLoader = require('./loader');
const bridge = require('../../../bridge');
const validate = require('./validate');
const list = require('./list');
const activator = require('./activation-bridge');
const settingsCache = require('../../../shared/settings-cache');
const messages = {
@ -34,8 +34,7 @@ module.exports = {
logging.warn(validate.getThemeValidationError('activeThemeHasErrors', activeThemeName, checkedTheme));
}
debug('Activating theme (method A on boot)', activeThemeName);
bridge.activateTheme(theme, checkedTheme);
activator.activateFromBoot(activeThemeName, theme, checkedTheme);
} catch (err) {
if (err instanceof errors.NotFoundError) {
// CASE: active theme is missing, we don't want to exit because the admin panel will still work
@ -60,8 +59,7 @@ module.exports = {
const checkedTheme = await validate.checkSafe(themeName, loadedTheme);
debug('Activating theme (method B on API "activate")', themeName);
bridge.activateTheme(loadedTheme, checkedTheme);
activator.activateFromAPI(themeName, loadedTheme, checkedTheme);
return checkedTheme;
},

View file

@ -10,6 +10,7 @@ const validate = require('./validate');
const list = require('./list');
const ThemeStorage = require('./ThemeStorage');
const themeLoader = require('./loader');
const activator = require('./activation-bridge');
const toJSON = require('./to-json');
const settingsCache = require('../../../shared/settings-cache');
@ -79,8 +80,7 @@ module.exports = {
overrideTheme = (shortName === settingsCache.get('active_theme'));
// CASE: if this is the active theme, we are overriding
if (overrideTheme) {
debug('Activating theme (method C, on API "override")', shortName);
bridge.activateTheme(loadedTheme, checkedTheme);
activator.activateFromOverride(shortName, loadedTheme, checkedTheme);
}
// @TODO: unify the name across gscan and Ghost!