-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 🐛 Improve theme lib, middleware & error handling (#8145)
no issue 🎨 simplify loader - use loadOneTheme for init - use loadOneTheme for init - move updateThemeList to the one place that it is used - this just reduces the surface area of the loader 🎨 Move init up to index temporarily - need to figure out what stuff goes in here as well as loading themes - will move it again later once I've got it figured out 🎨 Reorder & cleanup theme middleware - move the order in blog/app.js so that theme middleware isn't called for shared assets - add comments & cleanup in the middleware itself, for clarity 🎨 Simplify the logic in themes middleware - Separate out config dependent on settings changing and config dependent on request - Move blogApp.set('views') - no reason why this isn't in the theme activation method as it's actually simpler if it is there, we already know the active theme exists & can remove the if-guard 🎨 Improve error handling for missing theme - ensure we display a warning - don't have complex logic for handling errors - move loading of an empty hbs object into the error-handler as this will support more cases 🐛 Fix assetHash clearing bug on theme switch - asset hash wasn't correctly being set on theme switch 🎨 Remove themes.read & test loader instead - Previously, we've simplified loader & improved error handling - We are now able to completely remove theme.read as it's nothing more than a wrapper for package.read - This also means we can change our tests from testing the theme reader to loader
- Loading branch information
Showing
8 changed files
with
224 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,30 @@ | ||
var debug = require('debug')('ghost:themes:loader'), | ||
config = require('../config'), | ||
events = require('../events'), | ||
themeList = require('./list'), | ||
read = require('./read'), | ||
settingsCache = require('../settings/cache'), | ||
updateThemeList, | ||
read = require('../utils/packages').read, | ||
loadAllThemes, | ||
loadOneTheme, | ||
initThemes; | ||
|
||
updateThemeList = function updateThemeList(themes) { | ||
debug('loading themes', Object.keys(themes)); | ||
themeList.init(themes); | ||
}; | ||
loadOneTheme; | ||
|
||
loadAllThemes = function loadAllThemes() { | ||
return read | ||
.all(config.getContentPath('themes')) | ||
.then(updateThemeList); | ||
.then(function updateThemeList(themes) { | ||
debug('loading themes', Object.keys(themes)); | ||
|
||
themeList.init(themes); | ||
}); | ||
}; | ||
|
||
loadOneTheme = function loadOneTheme(themeName) { | ||
return read | ||
.one(config.getContentPath('themes'), themeName) | ||
.then(function (readThemes) { | ||
// @TODO change read one to not return a keyed object | ||
debug('loaded one theme', themeName); | ||
return themeList.set(themeName, readThemes[themeName]); | ||
}); | ||
}; | ||
|
||
initThemes = function initThemes() { | ||
debug('init themes', settingsCache.get('activeTheme')); | ||
|
||
// Register a listener for server-start to load all themes | ||
events.on('server:start', function readAllThemesOnServerStart() { | ||
loadAllThemes(); | ||
}); | ||
|
||
// Just read the active theme for now | ||
return read | ||
.one(config.getContentPath('themes'), settingsCache.get('activeTheme')) | ||
.then(updateThemeList); | ||
}; | ||
|
||
module.exports = { | ||
init: initThemes, | ||
loadAllThemes: loadAllThemes, | ||
loadOneTheme: loadOneTheme | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.