Merge pull request #420 from jgable/fix412

Redirect to last page of posts
This commit is contained in:
Hannah Wolfe 2013-08-19 13:43:26 -07:00
commit fd77d4bb04

View File

@ -12,8 +12,15 @@ var Ghost = require('../../ghost'),
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) {
// Parse the page number
var pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1;
api.posts.browse({page: pageParam}).then(function (page) {
// If page is greater than number of pages we have, redirect to last page
if (pageParam > page.pages) {
return res.redirect("/page/" + (page.pages) + "/");
}
// Render the page of posts
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}});
});