I’m developing a webapp using Node.js and Express. Inside this app, I manage a stream of JSON data to create a blog reader using Tumblr APIs.
I wrote the route as:
app.get('/blog', function(req, res) {
var Tumblr = require('tumblr').Tumblr
, keys = require('./keystore');
// Instancing Tumblr object to connect with a certain blog.
var blog = new Tumblr('myblog.tumblr.com', keys.tumblrConsumerSecret);
// Using Tumblr API to retrieve posts from a remote blog.
// For more info about methods and parameters to use, read the
// documentation for Tumblr's API v2.
blog.posts({offset: 0, limit: 5}, function(err, tumblr) {
if (err) {
res.send('Error page... I suppose!');
}
else {
res.render('blog',
{
blog: tumblr.posts
});
}
});
});
And blog.jade:
each post in blog
h2 #{post.title}
.justified
!= post.body
Now, I would like to add numbered page navigation function (as server-side) to the reader.
page 1: posts from 1 to 5
page 2: posts from 6 to 10
(etc...)
What can I do that?
Best regards, Vi.
Following chovy’s suggestion, I’ve found a solution.
In
app.js:In
routes/index.js:Then,
blog.jade:That’s all (and it works fine)!