Skip to content

Commit ef67aa2

Browse files
committed
fix: duplication tags temp
1 parent aa94a8e commit ef67aa2

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

packages/crd-scripts/src/conf/getPrerenderRoutes.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const DirectoryTree = require('./node-directory-tree')
1+
const {
2+
directoryTree,
3+
mapTagsWithArticle
4+
} = require('./node-directory-tree')
25

36
const getDirTree = (cmd) => {
47
const dir = cmd.markdownPaths
@@ -8,13 +11,12 @@ const getDirTree = (cmd) => {
811
extensions: /\.md/,
912
prerender: true,
1013
}
11-
const mapTagsWithArticle = []
12-
const dirTree = dirs.map(path => DirectoryTree({
14+
console.log('mapTagsWithArticle before', mapTagsWithArticle)
15+
const dirTree = dirs.map(path => directoryTree({
1316
path,
1417
options: otherProps,
15-
mapTagsWithArticle
1618
}))
17-
19+
console.log('mapTagsWithArticle after', mapTagsWithArticle)
1820
return {
1921
dirTree,
2022
// map tags with path. [{ tagName: 'custom Tag 1', mapArticle: [{ path, name }]}]

packages/crd-scripts/src/conf/node-directory-tree.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ function safeReadDirSync(path) {
4141
return dirData
4242
}
4343

44+
// collect unique tags from all articles.
45+
const tagsArr = []
46+
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 = []
4456
/** build directory Tree, fork from https://github.com/mihneadb/node-directory-tree
4557
* path: path for file
4658
* options: {
@@ -50,19 +62,10 @@ function safeReadDirSync(path) {
5062
* prerender: Boolean. Used for prerender.
5163
* generate: Boolean. Used for generating info in front-matter.
5264
* }
53-
* tagsArr: collect unique tags from all articles.
54-
* mapTagsWithArticle: [{
55-
* tagName: 'customTag1', // tag type name
56-
* mapArticle: [{
57-
* path, // click tag to jump route such as /tags/customTag1
58-
* title // the name of article
59-
* }]}]
6065
*/
6166
function directoryTree({
6267
path,
6368
options,
64-
tagsArr = [],
65-
mapTagsWithArticle = [],
6669
routePath = ''
6770
}) {
6871
const name = PATH.basename(path, '.md')
@@ -132,6 +135,8 @@ function directoryTree({
132135
title: name
133136
}]
134137
})
138+
139+
console.log('mapTagsWithArticle222', mapTagsWithArticle)
135140
}
136141
}
137142
}
@@ -171,8 +176,6 @@ function directoryTree({
171176
directoryTree({
172177
path: PATH.join(path, child),
173178
options,
174-
tagsArr,
175-
mapTagsWithArticle,
176179
routePath: routePropsCurrent
177180
}),
178181
)
@@ -187,4 +190,7 @@ function directoryTree({
187190
return item
188191
}
189192

190-
module.exports = directoryTree
193+
module.exports = {
194+
directoryTree,
195+
mapTagsWithArticle
196+
}

packages/crd-scripts/src/conf/rawTreeReplaceLoader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// A variation of https://github.com/react-doc/node-directory-tree-md/blob/master/lib/directory-tree-md.js
2-
const DirectoryTree = require('./node-directory-tree')
2+
const { directoryTree } = require('./node-directory-tree')
33
const PATH = require('path')
44
const { ifInGitIgnore } = require('../utils/index')
55

@@ -58,7 +58,7 @@ module.exports = function (source) {
5858
// if (this.cacheable) this.cacheable()
5959
if (directoryTrees && (!include || include.test(this.resourcePath))) {
6060
const dirs = Array.isArray(dir) ? dir : [dir]
61-
const dirTree = dirs.map(path => DirectoryTree({
61+
const dirTree = dirs.map(path => directoryTree({
6262
path,
6363
options: otherProps,
6464
}))

packages/crd-scripts/src/generate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22
const { docsConfig } = require('crd-utils')
3-
const DirectoryTree = require('./conf/node-directory-tree')
3+
const { directoryTree } = require('./conf/node-directory-tree')
44

55
module.exports = function generate(program) {
66
if (!fs.existsSync(docsConfig)) {
@@ -15,7 +15,7 @@ module.exports = function generate(program) {
1515
extensions: /\.md/,
1616
generate: true
1717
}
18-
dirs.map(path => DirectoryTree({
18+
dirs.map(path => directoryTree({
1919
path,
2020
options: otherProps,
2121
}))

packages/crd-scripts/src/utils/initCache.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const write = require('write')
22
const path = require('path')
33
const { cacheDirPath, getDocsConfig } = require('crd-utils')
4-
const DirectoryTree = require('../conf/node-directory-tree')
4+
const { directoryTree } = require('../conf/node-directory-tree')
55

66
module.exports = function (program, cb) {
77
const treeData = program.markdownPaths.map((markdownPath) => {
8-
return DirectoryTree({
8+
return directoryTree({
99
path: markdownPath,
1010
options: {
1111
mdconf: true, // Markdown config for exsiting file.

packages/crd-seed/component/Tags/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const Tags = () => {
1212
const routeMatch = useMatch(path) || {}
1313
const { name } = routeMatch.params || {}
1414

15+
console.log('mapTagsWithArticle', mapTagsWithArticle)
1516
return (
1617
<div className={styles.tags}>
1718
<div className={styles['tags-title']}>{name || 'Tags'}</div>

0 commit comments

Comments
 (0)