Ghost/core/frontend/services/themes/activate.js
Hannah Wolfe 34d2cc1b0b Moved active theme to new theme engine service
refs: bf0823c9a2

- continuing the work of splitting up the theme service into logical components
- this is where it starts to get fiddly as the getActive function in themeService index is required across the frontend/backend mostly due to its use in the getApiVersion method
- for now left one usage of the getActive method in place in ghost-locals middleware ready for the next phase of the refactor, which will move some of the themeService index into a shared location
2021-04-23 15:28:50 +01:00

35 lines
1.2 KiB
JavaScript

const {events, i18n} = require('../../../server/lib/common');
const logging = require('../../../shared/logging');
const errors = require('@tryghost/errors');
const active = require('../theme-engine/active');
function activate(loadedTheme, checkedTheme, error) {
// no need to check the score, activation should be used in combination with validate.check
// Use the two theme objects to set the current active theme
try {
let previousGhostAPI;
if (active.get()) {
previousGhostAPI = active.get().engine('ghost-api');
}
active.set(loadedTheme, checkedTheme, error);
const currentGhostAPI = active.get().engine('ghost-api');
events.emit('services.themes.activated', loadedTheme.name);
if (previousGhostAPI !== undefined && (previousGhostAPI !== currentGhostAPI)) {
events.emit('services.themes.api.changed');
const siteApp = require('../../../server/web/site/app');
siteApp.reload();
}
} catch (err) {
logging.error(new errors.InternalServerError({
message: i18n.t('errors.middleware.themehandler.activateFailed', {theme: loadedTheme.name}),
err: err
}));
}
}
module.exports = activate;