Created
March 9, 2012 18:35
-
-
Save typeoneerror/2007929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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