Beginnings of the show individual post view

This commit is contained in:
Nathan Leniz
2015-03-03 19:50:16 +09:00
parent 52e494407b
commit 94bbb7a4a5
3 changed files with 58 additions and 0 deletions

View File

@@ -28,3 +28,40 @@ exports.index = function(req, res, next) {
res.render('post/index');
});
};
exports.returnIndividualStory = function(req, res, next) {
var dashedName = req.params.storyName;
storyName = dashedName.replace(/\-/g, ' ');
Story.find({'headline' : new RegExp(storyName, 'i')}, function(err, story) {
if (err) {
next(err);
}
if (story.length < 1) {
req.flash('errors', {
msg: "404: We couldn't find a story with that name. Please double check the name."
});
return res.redirect('/stories/');
}
story = story.pop();
var dashedNameFull = story.headline.toLowerCase().replace(/\s/g, '-');
if (dashedNameFull != dashedName) {
return res.redirect('../stories/' + dashedNameFull);
}
res.render('post/show', {
title: story.headline,
dashedName: story.link,
author: story.author,
body: story.body,
rank: story.rank,
upVotes: story.upVotes,
comments: story.comments
});
});
};