mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
c70fbc2c7e
closes #8056 🎨 Collect together the package-related utils - read directory actually reads a directory of packages - parse package json is very tighly related to this 🎨 Move filterPaths -> packages.filterPackages - this function is related to packages, not settings - move the function to the new utils/packages - add 100% test coverage 🎨 Simplify filterPackages code 🎨 Simplify reading of packages & themes - This massively reduces all the complex code in the read packages & themes utils - Added full test coverage 🎨 Improve & clarify active prop in filterPackages - active is returned from API endpoints to combine data from multiple sources - see https://github.com/TryGhost/Ghost/pull/8064#discussion_r103514810 🎨 Better error handling 🔥 Temporarily remove custom error templates - we will reimplement this later when we have got a better concept of loading the active theme in place - refs #8079
33 lines
777 B
JavaScript
33 lines
777 B
JavaScript
/**
|
|
* # Read Themes
|
|
*
|
|
* Util that wraps packages.read
|
|
*/
|
|
var packages = require('../utils/packages'),
|
|
logging = require('../logging'),
|
|
i18n = require('../i18n'),
|
|
|
|
readOneTheme,
|
|
readAllThemes;
|
|
|
|
readOneTheme = function readOneTheme(dir, name) {
|
|
return packages
|
|
.read.one(dir, name)
|
|
.catch(function () {
|
|
// For now we return an empty object as this is not fatal unless the frontend of the blog is requested
|
|
logging.warn(i18n.t('errors.middleware.themehandler.missingTheme', {theme: name}));
|
|
return {};
|
|
});
|
|
};
|
|
|
|
readAllThemes = function readAllThemes(dir) {
|
|
return packages.read.all(dir);
|
|
};
|
|
|
|
/**
|
|
* Expose public API
|
|
*/
|
|
|
|
module.exports.all = readAllThemes;
|
|
module.exports.one = readOneTheme;
|