0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Redirect to last page of posts

If requesting a page of posts that is above the total number of pages,
redirect to the last page of posts.
This commit is contained in:
Jacob Gable 2013-08-18 12:41:55 -05:00
parent e765af4633
commit bbd60a6f23

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}});
});