@@ -52,31 +52,38 @@ function getContent(filename, data) {
5252 return [ '' , '' , '' ] ;
5353 }
5454
55- const h1reg = / ^ # .+ $ / gm, h2reg = / ^ # # .+ $ / gm, authorreg = / a u t h o r : [ ^ \n ] * / gm;
55+ const h1reg = / ^ # .+ $ / gm, h2reg = / ^ # # .+ $ / gm, authorreg = / a u t h o r : [ ^ \n ] * / gm, boldreg = / \* \* ( . * ? ) \* \* | _ _ ( . * ? ) _ _ / g ;
5656 const lines = file . split ( '\n' ) . filter ( e => ! e . match ( authorreg ) ) ;
57- let others = lines . filter ( ( e ) => ! e . match ( h1reg ) && ! e . match ( h2reg ) ) ;
57+ let content = lines . filter ( ( e ) => ! e . match ( h1reg ) && ! e . match ( h2reg ) ) ;
5858 let title = lines [ 0 ] && lines [ 0 ] . match ( h1reg ) ?
5959 lines [ 0 ] . replace ( '# ' , '' ) : '' ;
6060 traversalArticle ( data [ 'nav' ] , ( key , value ) => {
6161 if ( value == filename ) title = key ;
6262 } ) ;
6363 const h2 = lines . filter ( e => e . match ( h2reg ) ) . map ( e => e . replace ( / ^ # # / , '' ) ) ;
6464
65- others = others . map ( e => e . replace ( / ^ # # + / , '' ) ) ;
65+ let bold = "" ;
66+ let match ;
67+ while ( ( match = boldreg . exec ( file ) ) !== null ) {
68+ // match[1] is the content in **bold**, match[2] is the content in __bold__
69+ bold += match [ 1 ] || match [ 2 ] ;
70+ }
71+
72+ content = content . map ( e => e . replace ( / ^ # # + / , '' ) ) ;
6673
67- remark . process ( others . join ( '\n' ) , ( err , file ) => {
74+ remark . process ( content . join ( '\n' ) , ( err , file ) => {
6875 if ( err ) {
6976 console . error ( 'Remark processing error:' , err ) ;
7077 return ;
7178 }
72- others = String ( file )
79+ content = String ( file )
7380 . replace ( '"' , "" )
7481 . replace ( "\\n\\n" , "\\n" ) ;
7582 } ) ;
7683
77- others . replace ( )
84+ content . replace ( )
7885
79- return [ title , others , h2 . join ( '\n' ) ] ;
86+ return [ title , content , h2 . join ( '\n' ) , bold ] ;
8087}
8188
8289/**
@@ -91,12 +98,13 @@ function updateContent(modified, removed) {
9198 let ops = [ ] ;
9299 modified . forEach ( ( filename ) => {
93100 ops . push ( { index : { _index : 'oiwiki' , _id : filename } } ) ;
94- let [ title , article , h2 ] = getContent ( filename , data ) ;
101+ let [ title , article , h2 , bold ] = getContent ( filename , data ) ;
95102 ops . push ( {
96103 title : title ,
97104 content : article ,
98105 url : '/' + filename . replace ( '/index.md' , '/' ) . replace ( '.md' , '/' ) ,
99106 h2 : h2 ,
107+ bold : bold ,
100108 standard_content : article ,
101109 } ) ;
102110 } ) ;
0 commit comments