Beginnings of the show individual post view
This commit is contained in:
4
app.js
4
app.js
@ -288,6 +288,10 @@ app.get(
|
||||
'/stories/index',
|
||||
storyController.json
|
||||
);
|
||||
app.get(
|
||||
'/stories/:storyName',
|
||||
storyController.returnIndividualStory
|
||||
);
|
||||
|
||||
/**
|
||||
* Challenge related routes
|
||||
|
@ -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
17
views/post/show.jade
Normal 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
|
Reference in New Issue
Block a user