1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-17 15:11:28 +00:00

Homebrewery will now try and insert a better title for you if you dont provide one

This commit is contained in:
Scott Tolksdorf
2016-08-20 13:20:32 -04:00
parent 0a7b538216
commit ef8784ccf2
4 changed files with 17 additions and 3 deletions

View File

@@ -27,11 +27,26 @@ var getTopBrews = function(cb){
});
}
var getGoodBrewTitle = (text) => {
var titlePos = text.indexOf('# ');
if(titlePos !== -1){
var ending = text.indexOf('\n', titlePos);
return text.substring(titlePos + 2, ending);
}else{
return _.find(text.split('\n'), (line)=>{
return line;
});
}
};
module.exports = function(app){
app.post('/api', function(req, res){
var newHomebrew = new HomebrewModel(req.body);
if(!newHomebrew.title){
newHomebrew.title = getGoodBrewTitle(newHomebrew.text);
}
newHomebrew.save(function(err, obj){
if(err){
console.error(err, err.toString(), err.stack);