File tree 4 files changed +26
-4
lines changed
4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ app.route('/:resource/new')
29
29
} )
30
30
. post ( utils . resourceExists , function ( req , res ) {
31
31
// handle resource creation
32
- res . send ( "post->" + req . params . resource ) ;
32
+ var mdString = utils . createMarkdownString ( req . params . resource , req . body ) ;
33
+ res . send ( mdString ) ;
33
34
} ) ;
34
35
35
36
var port = process . env . PORT || 80 ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const pages = [
17
17
} ,
18
18
{
19
19
name : 'tags' ,
20
- default : '[dsg, ]'
20
+ default : '[dsg]'
21
21
} ,
22
22
{
23
23
name : 'language' ,
Original file line number Diff line number Diff line change 1
1
const pages = require ( './pages.js' ) ;
2
2
3
- module . exports . resourceExists = function ( req , res , next ) { console . log ( 11 ) ;
3
+ module . exports . resourceExists = function ( req , res , next ) {
4
4
if ( ! pages . exists ( req . params . resource ) ) {
5
5
res . status ( 404 ) . send ( 'Not found' ) ;
6
6
} else {
7
7
next ( ) ;
8
8
}
9
+ }
10
+
11
+ module . exports . createMarkdownString = function ( resource , data ) {
12
+ const hasText = pages . find ( resource ) . hasText ;
13
+ var metaStr = '' ;
14
+ for ( var property in data ) {
15
+ if ( data . hasOwnProperty ( property ) ) {
16
+ if ( hasText && property == 'text-body' ) {
17
+ continue ;
18
+ } else {
19
+ metaStr += property + ': ' + data [ property ] + '\n' ;
20
+ }
21
+ }
22
+ }
23
+
24
+ var str = '---\n' + metaStr + '---\n' ;
25
+ if ( hasText ) {
26
+ str += data [ 'text-body' ] ;
27
+ }
28
+
29
+ return str ;
9
30
}
Original file line number Diff line number Diff line change 21
21
{{ /if }}
22
22
</table >
23
23
{{ #if page.hasText }}
24
- <textarea name =" content " id =" md-editor" ></textarea >
24
+ <textarea name =" text-body " id =" md-editor" ></textarea >
25
25
<br >
26
26
{{ /if }}
27
27
<input type =" submit" >
You can’t perform that action at this time.
0 commit comments