mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
df7e64fafa
refs #10790 - Moved /core/apps into core/frontend - Moved /core/server/helpers to /core/frontend/helpers along with /core/server/services/themes - Changed helper location in overrides - Moved /core/server/services/routing to /core/frontend/services - Moved /core/server/services/url to /core/frontend/services - Moved /core/server/data/meta to /core/frontend/meta - Moved /core/server/services/rss to /core/frontend/services - Moved /core/server/data/xml to /core/frontend/services
48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
var _ = require('lodash'),
|
|
themeList = require('./list'),
|
|
active = require('./active'),
|
|
packageJSON = require('../../../server/lib/fs/package-json'),
|
|
settingsCache = require('../../../server/services/settings/cache');
|
|
|
|
/**
|
|
*
|
|
* Provides a JSON object which can be returned via the API.
|
|
* You can either request all themes or a specific theme if you pass the `name` argument.
|
|
* Furthermore, you can pass a gscan result to filter warnings/errors.
|
|
*
|
|
* @TODO: settingsCache.get('active_theme') vs. active.get().name
|
|
*
|
|
* @param {string} [name] - the theme to output
|
|
* @param {object} [checkedTheme] - a theme result from gscan
|
|
* @return {*}
|
|
*/
|
|
module.exports = function toJSON(name, checkedTheme) {
|
|
var themeResult, toFilter;
|
|
|
|
if (!name) {
|
|
toFilter = themeList.getAll();
|
|
themeResult = packageJSON.filter(toFilter, settingsCache.get('active_theme'));
|
|
} else {
|
|
toFilter = {
|
|
[name]: themeList.get(name)
|
|
};
|
|
|
|
themeResult = packageJSON.filter(toFilter, settingsCache.get('active_theme'));
|
|
|
|
if (checkedTheme && checkedTheme.results.warning.length > 0) {
|
|
themeResult[0].warnings = _.cloneDeep(checkedTheme.results.warning);
|
|
}
|
|
|
|
if (checkedTheme && checkedTheme.results.error.length > 0) {
|
|
themeResult[0].errors = _.cloneDeep(checkedTheme.results.error);
|
|
}
|
|
}
|
|
|
|
// CASE: if you want a JSON response for a single theme, which is not active.
|
|
if (_.find(themeResult, {active: true}) && active.get()) {
|
|
_.find(themeResult, {active: true}).templates = active.get().customTemplates;
|
|
}
|
|
|
|
return {themes: themeResult};
|
|
};
|