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

4
app.js
View File

@ -288,6 +288,10 @@ app.get(
'/stories/index',
storyController.json
);
app.get(
'/stories/:storyName',
storyController.returnIndividualStory
);
/**
* Challenge related routes

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
});
});
};

17
views/post/show.jade Normal file
View File

@ -0,0 +1,17 @@
extends ../layout
block content
h1= title
h3= body
h5= rank
//
title: story.headline,
dashedName: story.link,
author: story.author,
body: story.body,
rank: story.rank,
upVotes: story.upVotes,
comments: story.comments