mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
- ghost.js - globals/globalConfig has become settings / settingsCache to make it clearer - app.js - the ghostGlobals local cache is gone, and the use of res.locals has been cleaned up and simplified, although this needs to be properly split into frontend and admin locals (to be finished in #124) - frontend/index.js - doesn't need to be passed globals and nav properties as res.locals does this for us
This commit is contained in:
parent
cdb9ecab76
commit
32bbf2ba57
3 changed files with 18 additions and 32 deletions
42
app.js
42
app.js
|
@ -18,20 +18,19 @@
|
|||
filters = require('./core/frontend/filters'),
|
||||
helpers = require('./core/frontend/helpers'),
|
||||
|
||||
// ## Variables
|
||||
// ## Custom Middleware
|
||||
auth,
|
||||
authAPI,
|
||||
ghostLocals,
|
||||
|
||||
// ## Variables
|
||||
loading = when.defer(),
|
||||
|
||||
/**
|
||||
* Create new Ghost object
|
||||
* @type {Ghost}
|
||||
*/
|
||||
ghost = new Ghost(),
|
||||
// This is assigned after the call to ghost.init() below
|
||||
ghostGlobals;
|
||||
|
||||
ghost = new Ghost();
|
||||
|
||||
|
||||
ghost.app().configure('development', function () {
|
||||
|
@ -44,8 +43,6 @@
|
|||
ghost.app().use(express.cookieSession({ cookie: { maxAge: 60000000 }}));
|
||||
ghost.app().use(ghost.initTheme(ghost.app()));
|
||||
ghost.app().use(flash());
|
||||
// bind locals - options which appear in every view - perhaps this should be admin only
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -75,18 +72,19 @@
|
|||
|
||||
/**
|
||||
* Expose the standard locals that every external page should have available;
|
||||
* path, navItems and ghostGlobals
|
||||
* path, navItems and settingsCache
|
||||
*/
|
||||
ghostLocals = function (req, res, next) {
|
||||
ghost.doFilter('ghostNavItems', {path: req.path, navItems: []}, function (navData) {
|
||||
// Make sure we have a locals value.
|
||||
res.locals = res.locals || {};
|
||||
|
||||
|
||||
|
||||
// Extend it with nav data and ghostGlobals
|
||||
// Extend it with nav data and settings
|
||||
_.extend(res.locals, navData, {
|
||||
ghostGlobals: ghost.globals()
|
||||
messages: req.flash(),
|
||||
settings: ghost.settings(),
|
||||
availableThemes: ghost.paths().availableThemes,
|
||||
availablePlugins: ghost.paths().availablePlugins
|
||||
});
|
||||
|
||||
next();
|
||||
|
@ -97,21 +95,9 @@
|
|||
ghost.loaded = loading.promise;
|
||||
|
||||
when.all([ghost.init(), filters.loadCoreFilters(ghost), helpers.loadCoreHelpers(ghost)]).then(function () {
|
||||
// Assign the globals we have loaded
|
||||
ghostGlobals = ghost.globals();
|
||||
|
||||
ghost.app().use(function (req, res, next) {
|
||||
res.locals.messages = req.flash();
|
||||
res.locals.siteTitle = ghostGlobals.title;
|
||||
res.locals.siteDescription = ghostGlobals.description;
|
||||
res.locals.siteUrl = ghostGlobals.url;
|
||||
res.locals.activeTheme = ghostGlobals.activeTheme;
|
||||
res.locals.activePlugin = ghostGlobals.activePlugin;
|
||||
res.locals.availableThemes = ghost.paths().availableThemes;
|
||||
res.locals.availablePlugins = ghost.paths().availablePlugins;
|
||||
|
||||
next();
|
||||
});
|
||||
// post init config
|
||||
ghost.app().use(ghostLocals);
|
||||
|
||||
/**
|
||||
* API routes..
|
||||
|
@ -151,8 +137,8 @@
|
|||
* Frontend routes..
|
||||
* @todo dynamic routing, homepage generator, filters ETC ETC
|
||||
*/
|
||||
ghost.app().get('/:slug', ghostLocals, frontend.single);
|
||||
ghost.app().get('/', ghostLocals, frontend.homepage);
|
||||
ghost.app().get('/:slug', frontend.single);
|
||||
ghost.app().get('/', frontend.homepage);
|
||||
|
||||
ghost.app().listen(3333, function () {
|
||||
console.log("Express server listening on port " + 3333);
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
'homepage': function (req, res) {
|
||||
api.posts.browse().then(function (page) {
|
||||
ghost.doFilter('prePostsRender', page.posts, function (posts) {
|
||||
res.render('index', {posts: posts, ghostGlobals: res.locals.ghostGlobals, navItems: res.locals.navItems});
|
||||
res.render('index', {posts: posts});
|
||||
});
|
||||
});
|
||||
},
|
||||
'single': function (req, res) {
|
||||
api.posts.read({'slug': req.params.slug}).then(function (post) {
|
||||
ghost.doFilter('prePostsRender', post.toJSON(), function (post) {
|
||||
res.render('single', {post: post, ghostGlobals: res.locals.ghostGlobals, navItems: res.locals.navItems});
|
||||
res.render('single', {post: post});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
config: function () { return config; },
|
||||
|
||||
// there's no management here to be sure this has loaded
|
||||
globals: function () { return instance.globalConfig; },
|
||||
settings: function () { return instance.settingsCache; },
|
||||
dataProvider: models,
|
||||
statuses: function () { return statuses; },
|
||||
polyglot: function () { return polyglot; },
|
||||
|
@ -134,7 +134,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
self.globalConfig = settings;
|
||||
self.settingsCache = settings;
|
||||
}, errors.logAndThrowError);
|
||||
}, errors.logAndThrowError);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue