Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created March 9, 2012 18:35
Show Gist options
  • Select an option

  • Save typeoneerror/2007929 to your computer and use it in GitHub Desktop.

Select an option

Save typeoneerror/2007929 to your computer and use it in GitHub Desktop.
/**
* Actions for displaying the blog/articles.
*/
var Article = mongoose.model('Article')
, Tag = mongoose.model('Tag')
module.exports = function(app){
app.param('page', Number)
app.get('/articles/page/:page', function(req, res){
Article.find({}, function(err, items){
renderArticles(res, err, items)
})
})
app.param('post_slug', /^[-\w]+$/)
app.get('/articles/post/:post_slug', function(req, res){
var slug = req.params.post_slug
Article.find({slug: slug}, function(err, article){
renderArticles(res, err, article)
})
})
}
function renderArticles(res, err, articles){
if (err) throw err
res.render('articles', {title: 'Articles', articles: articles})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment