@@ -57,9 +57,10 @@ function getContent(filename, data) {
5757
5858 const h1reg = / ^ # .+ $ / gm,
5959 h2reg = / ^ # # .+ $ / gm,
60- authorreg = / a u t h o r : [ ^ \n ] * / gm;
60+ authorreg = / a u t h o r : [ ^ \n ] * / gm,
61+ boldreg = / \* \* ( .* ?) \* \* | _ _ ( .* ?) _ _ / g;
6162 const lines = file . split ( "\n" ) . filter ( ( e ) => ! e . match ( authorreg ) ) ;
62- let others = lines . filter ( ( e ) => ! e . match ( h1reg ) && ! e . match ( h2reg ) ) ;
63+ let content = lines . filter ( ( e ) => ! e . match ( h1reg ) && ! e . match ( h2reg ) ) ;
6364 let title =
6465 lines [ 0 ] && lines [ 0 ] . match ( h1reg ) ? lines [ 0 ] . replace ( "# " , "" ) : "" ;
6566 traversalArticle ( data [ "nav" ] , ( key , value ) => {
@@ -68,20 +69,26 @@ function getContent(filename, data) {
6869 const h2 = lines
6970 . filter ( ( e ) => e . match ( h2reg ) )
7071 . map ( ( e ) => e . replace ( / ^ # # / , "" ) ) ;
72+ let bold = "" ;
73+ let match ;
74+ while ( ( match = boldreg . exec ( file ) ) !== null ) {
75+ // match[1] is the content in **bold**, match[2] is the content in __bold__
76+ bold += match [ 1 ] || match [ 2 ] ;
77+ }
7178
72- others = others . map ( ( e ) => e . replace ( / ^ # # + / , "" ) ) ;
79+ content = content . map ( ( e ) => e . replace ( / ^ # # + / , "" ) ) ;
7380
74- remark . process ( others . join ( "\n" ) , ( err , file ) => {
81+ remark . process ( content . join ( "\n" ) , ( err , file ) => {
7582 if ( err ) {
7683 console . error ( "Remark processing error:" , err ) ;
7784 return ;
7885 }
79- others = String ( file ) . replace ( '"' , "" ) . replace ( "\\n\\n" , "\\n" ) ;
86+ content = String ( file ) . replace ( '"' , "" ) . replace ( "\\n\\n" , "\\n" ) ;
8087 } ) ;
8188
82- others . replace ( ) ;
89+ content . replace ( ) ;
8390
84- return [ title , others , h2 . join ( "\n" ) ] ;
91+ return [ title , content , h2 . join ( "\n" ) , bold ] ;
8592}
8693
8794/**
@@ -96,12 +103,13 @@ function updateContent(modified, removed) {
96103 let ops = [ ] ;
97104 modified . forEach ( ( filename ) => {
98105 ops . push ( { index : { _index : "oiwiki" , _id : filename } } ) ;
99- let [ title , article , h2 ] = getContent ( filename , data ) ;
106+ let [ title , article , h2 , bold ] = getContent ( filename , data ) ;
100107 ops . push ( {
101108 title : title ,
102109 content : article ,
103110 url : "/" + filename . replace ( "/index.md" , "/" ) . replace ( ".md" , "/" ) ,
104111 h2 : h2 ,
112+ bold : bold ,
105113 standard_content : article ,
106114 } ) ;
107115 } ) ;
0 commit comments