@@ -51,7 +51,9 @@ function safeReadDirSync(path) {
5151function directoryTree ( {
5252 path,
5353 options,
54- tagsArr = [ ]
54+ tagsArr = [ ] ,
55+ // [{ tagName: 'custom Tag 1', mapArticle: [{ path, title }] }]
56+ mapTagsWithArticle = [ ]
5557} ) {
5658 const name = PATH . basename ( path )
5759 const item = { name }
@@ -99,9 +101,31 @@ function directoryTree({
99101 }
100102
101103 const yamlParse = contentMatch ? YAML . parse ( contentMatch [ 1 ] ) : { }
104+ const articleTags = yamlParse . tags
105+ const pathResult = yamlParse . abbrlink
106+ if ( Array . isArray ( articleTags ) ) {
107+ const cpArticleTags = Array . from ( new Set ( articleTags ) )
102108
103- if ( Array . isArray ( yamlParse . tags ) ) {
104- tagsArr . push ( ...yamlParse . tags )
109+ for ( let i = 0 ; i < cpArticleTags . length ; i ++ ) {
110+ const articleTag = cpArticleTags [ i ]
111+ const articleTagIndex = tagsArr . indexOf ( articleTag )
112+ if ( articleTagIndex > - 1 ) {
113+ mapTagsWithArticle [ articleTagIndex ] [ 'mapArticle' ] . push ( {
114+ path : pathResult ? pathResult : name ,
115+ title : name
116+ } )
117+ } else {
118+ tagsArr . push ( cpArticleTags [ i ] )
119+ mapTagsWithArticle . push ( {
120+ tagName : cpArticleTags [ i ] ,
121+ mapArticle : [ {
122+ // todo: replace name
123+ path : pathResult ? pathResult : name ,
124+ title : name
125+ } ]
126+ } )
127+ }
128+ }
105129 }
106130
107131 item . mdconf = yamlParse
@@ -139,7 +163,8 @@ function directoryTree({
139163 directoryTree ( {
140164 path : PATH . join ( path , child ) ,
141165 options,
142- tagsArr
166+ tagsArr,
167+ mapTagsWithArticle
143168 } ) ,
144169 )
145170 . filter ( e => ! ! e )
0 commit comments