Ghost/core/server/controllers/frontend.js

31 lines
1001 B
JavaScript
Raw Normal View History

2013-05-11 20:44:25 +04:00
/**
* Main controller for Ghost frontend
*/
/*global require, module */
var Ghost = require('../../ghost'),
api = require('../api'),
2013-05-11 20:44:25 +04:00
ghost = new Ghost(),
frontendControllers;
2013-05-11 20:44:25 +04:00
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}});
2013-05-11 20:44:25 +04:00
});
});
},
'single': function (req, res) {
api.posts.read({'slug': req.params.slug}).then(function (post) {
ghost.doFilter('prePostsRender', post.toJSON(), function (post) {
res.render('post', {post: post});
2013-05-11 20:44:25 +04:00
});
});
}
};
2013-05-11 20:44:25 +04:00
module.exports = frontendControllers;