0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/frontend/controllers/index.js
cobbspur 376cf647e5 closes #197 & closes #196 pagination wiring and helper
- adds routes for homepage pagination
- adds helper function to compile template file for pagination
- adds next and prev to post for next and previous page
- adds handlebars template for pagination
2013-06-25 16:13:19 +01:00

31 lines
No EOL
1,013 B
JavaScript

/**
* Main controller for Ghost frontend
*/
/*global require, module */
var Ghost = require('../../ghost'),
api = require('../../shared/api'),
ghost = new Ghost(),
frontendControllers;
frontendControllers = {
'homepage': function (req, res) {
var page = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1;
api.posts.browse({page: page}).then(function (page) {
ghost.doFilter('prePostsRender', page.posts, function (posts) {
res.render('index', {posts: posts, pagination: {page: page.page, prev: page.prev, next: page.next, limit: page.limit, total: page.total, pages: page.pages}});
});
});
},
'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});
});
});
}
};
module.exports = frontendControllers;