@@ -44,15 +44,6 @@ function safeReadDirSync(path) {
4444// collect unique tags from all articles.
4545const tagsArr = [ ]
4646
47- // The global arr cache has side effects, to follow up optimizing.
48- // [{
49- // tagName: 'customTag1', // tag type name
50- // mapArticle: [{
51- // path, // click tag to jump route such as /tags/customTag1
52- // title // the name of article
53- // }]
54- // }]
55- const mapTagsWithArticle = [ ]
5647/** build directory Tree, fork from https://github.com/mihneadb/node-directory-tree
5748 * path: path for file
5849 * options: {
@@ -62,11 +53,19 @@ const mapTagsWithArticle = []
6253 * prerender: Boolean. Used for prerender.
6354 * generate: Boolean. Used for generating info in front-matter.
6455 * }
56+ * mapTagsWithArticle: [{
57+ * tagName: 'customTag1', // tag type name
58+ * mapArticle: [{
59+ * path, // click tag to jump route such as /tags/customTag1
60+ * title // the name of article
61+ * }]
62+ * }]
6563 */
6664function directoryTree ( {
6765 path,
6866 options,
69- routePath = ''
67+ routePath = '' ,
68+ mapTagsWithArticle
7069} ) {
7170 const name = PATH . basename ( path , '.md' )
7271 const item = { name }
@@ -116,7 +115,7 @@ function directoryTree({
116115
117116 const yamlParse = contentMatch ? YAML . parse ( contentMatch [ 1 ] ) : { }
118117 const { tags : articleTags , abbrlink } = yamlParse
119- if ( Array . isArray ( articleTags ) ) {
118+ if ( Array . isArray ( articleTags ) && Array . isArray ( mapTagsWithArticle ) ) {
120119 const cpArticleTags = Array . from ( new Set ( articleTags ) )
121120 for ( let i = 0 ; i < cpArticleTags . length ; i ++ ) {
122121 const articleTag = cpArticleTags [ i ]
@@ -176,7 +175,8 @@ function directoryTree({
176175 directoryTree ( {
177176 path : PATH . join ( path , child ) ,
178177 options,
179- routePath : routePropsCurrent
178+ routePath : routePropsCurrent ,
179+ mapTagsWithArticle
180180 } ) ,
181181 )
182182 . filter ( e => ! ! e )
@@ -191,6 +191,5 @@ function directoryTree({
191191}
192192
193193module . exports = {
194- directoryTree,
195- mapTagsWithArticle
194+ directoryTree
196195}
0 commit comments