Merge branch 'master' of https://github.com/FreeCodeCamp/freecodecamp
This commit is contained in:
@ -119,13 +119,13 @@ exports.returnIndividualStory = function(req, res, next) {
|
|||||||
|
|
||||||
var storyName = dashedName.replace(/\-/g, ' ');
|
var storyName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
Story.find({'storyLink' : new RegExp(storyName, 'i')}, function(err, story) {
|
Story.findOne({'storyLink' : new RegExp(storyName, 'i')}, function(err, story) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (story.length < 1) {
|
if (story == null) {
|
||||||
req.flash('errors', {
|
req.flash('errors', {
|
||||||
msg: "404: We couldn't find a story with that name. Please double check the name."
|
msg: "404: We couldn't find a story with that name. Please double check the name."
|
||||||
});
|
});
|
||||||
@ -133,7 +133,6 @@ exports.returnIndividualStory = function(req, res, next) {
|
|||||||
return res.redirect('/stories/');
|
return res.redirect('/stories/');
|
||||||
}
|
}
|
||||||
|
|
||||||
story = story.pop();
|
|
||||||
var dashedNameFull = story.storyLink.toLowerCase().replace(/\s/g, '-');
|
var dashedNameFull = story.storyLink.toLowerCase().replace(/\s/g, '-');
|
||||||
if (dashedNameFull !== dashedName) {
|
if (dashedNameFull !== dashedName) {
|
||||||
return res.redirect('../stories/' + dashedNameFull);
|
return res.redirect('../stories/' + dashedNameFull);
|
||||||
@ -308,6 +307,15 @@ exports.storySubmission = function(req, res) {
|
|||||||
.replace(/[^a-z0-9]/gi, ' ')
|
.replace(/[^a-z0-9]/gi, ' ')
|
||||||
.replace(/\s+/g, ' ')
|
.replace(/\s+/g, ' ')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
|
|
||||||
|
Story.count({'storyLink': storyLink}, function(err, storyCount) {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if duplicate storyLink add unique number
|
||||||
|
storyLink = (storyCount == 0) ? storyLink : storyLink + ' ' + storyCount;
|
||||||
|
|
||||||
var link = data.link;
|
var link = data.link;
|
||||||
if (link.search(/^https?:\/\//g) === -1) {
|
if (link.search(/^https?:\/\//g) === -1) {
|
||||||
link = 'http://' + link;
|
link = 'http://' + link;
|
||||||
@ -340,6 +348,7 @@ exports.storySubmission = function(req, res) {
|
|||||||
storyLink: story.storyLink.replace(/\s/g, '-').toLowerCase()
|
storyLink: story.storyLink.replace(/\s/g, '-').toLowerCase()
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.commentSubmit = function(req, res) {
|
exports.commentSubmit = function(req, res) {
|
||||||
|
Reference in New Issue
Block a user