Beginnings of the show individual post view
This commit is contained in:
@@ -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
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user