mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
|
var _ = require('lodash'),
|
||
|
themeList = require('./list'),
|
||
|
packages = require('../utils/packages'),
|
||
|
settingsCache = require('../settings/cache');
|
||
|
|
||
|
/**
|
||
|
* Provides a JSON object which can be returned via the API
|
||
|
*
|
||
|
* @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();
|
||
|
// Default to returning the full list
|
||
|
themeResult = packages.filterPackages(toFilter, settingsCache.get('activeTheme'));
|
||
|
} else {
|
||
|
// If we pass in a gscan result, convert this instead
|
||
|
toFilter = {};
|
||
|
toFilter[name] = themeList.get(name);
|
||
|
|
||
|
themeResult = packages.filterPackages(toFilter, settingsCache.get('activeTheme'));
|
||
|
|
||
|
if (checkedTheme && checkedTheme.results.warning.length > 0) {
|
||
|
themeResult[0].warnings = _.cloneDeep(checkedTheme.results.warning);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {themes: themeResult};
|
||
|
};
|