2021-07-07 15:58:47 +03:00
|
|
|
const debug = require('@tryghost/debug')('themes');
|
|
|
|
const bridge = require('../../../bridge');
|
2021-09-23 14:44:39 +03:00
|
|
|
const labs = require('../../../shared/labs');
|
|
|
|
const customThemeSettings = require('../custom-theme-settings');
|
2021-07-07 15:58:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = {
|
2021-10-21 17:02:42 +03:00
|
|
|
activateFromBoot: async (themeName, theme, checkedTheme) => {
|
2021-07-07 15:58:47 +03:00
|
|
|
debug('Activating theme (method A on boot)', themeName);
|
2021-09-23 14:44:39 +03:00
|
|
|
// TODO: probably a better place for this to happen - after successful activation / when reloading site?
|
|
|
|
if (labs.isSet('customThemeSettings')) {
|
2021-10-21 17:02:42 +03:00
|
|
|
await customThemeSettings.api.activateTheme(themeName, checkedTheme);
|
2021-09-23 14:44:39 +03:00
|
|
|
}
|
2021-07-07 15:58:47 +03:00
|
|
|
bridge.activateTheme(theme, checkedTheme);
|
|
|
|
},
|
2021-10-21 17:02:42 +03:00
|
|
|
activateFromAPI: async (themeName, theme, checkedTheme) => {
|
2021-07-07 15:58:47 +03:00
|
|
|
debug('Activating theme (method B on API "activate")', themeName);
|
2021-09-23 14:44:39 +03:00
|
|
|
// TODO: probably a better place for this to happen - after successful activation / when reloading site?
|
|
|
|
if (labs.isSet('customThemeSettings')) {
|
2021-10-21 17:02:42 +03:00
|
|
|
await customThemeSettings.api.activateTheme(themeName, checkedTheme);
|
2021-09-23 14:44:39 +03:00
|
|
|
}
|
2021-07-07 15:58:47 +03:00
|
|
|
bridge.activateTheme(theme, checkedTheme);
|
|
|
|
},
|
2021-10-21 17:02:42 +03:00
|
|
|
activateFromAPIOverride: async (themeName, theme, checkedTheme) => {
|
2021-07-07 15:58:47 +03:00
|
|
|
debug('Activating theme (method C on API "override")', themeName);
|
2021-09-23 14:44:39 +03:00
|
|
|
// TODO: probably a better place for this to happen - after successful activation / when reloading site?
|
|
|
|
if (labs.isSet('customThemeSettings')) {
|
2021-10-21 17:02:42 +03:00
|
|
|
await customThemeSettings.api.activateTheme(themeName, checkedTheme);
|
2021-09-23 14:44:39 +03:00
|
|
|
}
|
2021-07-07 15:58:47 +03:00
|
|
|
bridge.activateTheme(theme, checkedTheme);
|
|
|
|
}
|
|
|
|
};
|