2013-05-11 20:44:25 +04:00
|
|
|
/**
|
|
|
|
* Main controller for Ghost frontend
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*global require, module */
|
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
var Ghost = require('../../ghost'),
|
2013-07-11 23:02:18 +04:00
|
|
|
api = require('../api'),
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
ghost = new Ghost(),
|
|
|
|
frontendControllers;
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
frontendControllers = {
|
|
|
|
'homepage': function (req, res) {
|
2013-06-25 19:13:19 +04:00
|
|
|
var page = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1;
|
|
|
|
api.posts.browse({page: page}).then(function (page) {
|
2013-06-25 15:43:15 +04:00
|
|
|
ghost.doFilter('prePostsRender', page.posts, function (posts) {
|
2013-06-25 19:13:19 +04:00
|
|
|
res.render('index', {posts: posts, pagination: {page: page.page, prev: page.prev, next: page.next, limit: page.limit, total: page.total, pages: page.pages}});
|
2013-05-11 20:44:25 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
'single': function (req, res) {
|
|
|
|
api.posts.read({'slug': req.params.slug}).then(function (post) {
|
|
|
|
ghost.doFilter('prePostsRender', post.toJSON(), function (post) {
|
2013-07-11 20:57:12 +04:00
|
|
|
res.render('post', {post: post});
|
2013-05-11 20:44:25 +04:00
|
|
|
});
|
2013-06-25 15:43:15 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2013-05-11 20:44:25 +04:00
|
|
|
|
2013-06-25 15:43:15 +04:00
|
|
|
module.exports = frontendControllers;
|