Skip to content

Commit

Permalink
implement createMarkdownString
Browse files Browse the repository at this point in the history
  • Loading branch information
stsourlidakis committed Dec 17, 2016
1 parent b6185c2 commit b032f4a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ app.route('/:resource/new')
})
.post(utils.resourceExists, function(req, res){
// handle resource creation
res.send("post->"+req.params.resource);
var mdString = utils.createMarkdownString(req.params.resource, req.body);
res.send(mdString);
});

var port = process.env.PORT || 80;
Expand Down
2 changes: 1 addition & 1 deletion pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const pages = [
},
{
name: 'tags',
default: '[dsg, ]'
default: '[dsg]'
},
{
name: 'language',
Expand Down
23 changes: 22 additions & 1 deletion utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
const pages = require('./pages.js');

module.exports.resourceExists = function(req, res, next) {console.log(11);
module.exports.resourceExists = function(req, res, next) {
if( !pages.exists(req.params.resource) ){
res.status(404).send('Not found');
} else {
next();
}
}

module.exports.createMarkdownString = function(resource, data) {
const hasText = pages.find(resource).hasText;
var metaStr = '';
for (var property in data) {
if (data.hasOwnProperty(property)) {
if(hasText && property=='text-body'){
continue;
} else {
metaStr += property+': '+data[property]+'\n';
}
}
}

var str = '---\n'+metaStr+'---\n';
if(hasText){
str += data['text-body'];
}

return str;
}
2 changes: 1 addition & 1 deletion views/editor.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{{/if}}
</table>
{{#if page.hasText}}
<textarea name="content" id="md-editor"></textarea>
<textarea name="text-body" id="md-editor"></textarea>
<br>
{{/if}}
<input type="submit">
Expand Down

0 comments on commit b032f4a

Please sign in to comment.