Skip to content

Commit 0bd35cf

Browse files
committed
fix: duplication tags
1 parent ef67aa2 commit 0bd35cf

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

README-en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Create React Doc provides the official default theme [crd-seed](https://github.c
4545
* GitHub linkage.
4646
* Support using tags to customize aggregate article content.
4747

48-
[my blog](http://muyunyun.cn/blog) is based default theme to build。
48+
[my blog](http://muyunyun.cn/blog) is based [crd-seed](https://github.com/MuYunyun/create-react-doc/tree/main/packages/crd-seed) theme to build。
4949

5050
![](http://with.muyunyun.cn/ec330b8ac2175c828be41f446f9f9619.jpg)
5151
![](http://with.muyunyun.cn/2e7440e4256debda2d73a4e6392c7146.jpg-300)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ create-react-doc 提供了官方默认主题 [crd-seed](https://github.com/MuYun
4848
* 支持与 GitHub 文档编辑能力联动。
4949
* 支持配置展示标签以自定义聚合文章内容。
5050

51-
[笔者博客](http://muyunyun.cn/blog) 就是使用默认主题搭建的
51+
[笔者博客](http://muyunyun.cn/blog)使用的是 [crd-seed](https://github.com/MuYunyun/create-react-doc/tree/main/packages/crd-seed) 主题搭建的
5252

5353
![](http://with.muyunyun.cn/ec330b8ac2175c828be41f446f9f9619.jpg)
5454
![](http://with.muyunyun.cn/2e7440e4256debda2d73a4e6392c7146.jpg-300)

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

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

63
const getDirTree = (cmd) => {
74
const dir = cmd.markdownPaths
@@ -11,10 +8,11 @@ const getDirTree = (cmd) => {
118
extensions: /\.md/,
129
prerender: true,
1310
}
14-
console.log('mapTagsWithArticle before', mapTagsWithArticle)
11+
const mapTagsWithArticle = []
1512
const dirTree = dirs.map(path => directoryTree({
1613
path,
1714
options: otherProps,
15+
mapTagsWithArticle
1816
}))
1917
console.log('mapTagsWithArticle after', mapTagsWithArticle)
2018
return {

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ function safeReadDirSync(path) {
4444
// collect unique tags from all articles.
4545
const 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
*/
6664
function 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

193193
module.exports = {
194-
directoryTree,
195-
mapTagsWithArticle
194+
directoryTree
196195
}

0 commit comments

Comments
 (0)