Skip to content

Commit 0e651c9

Browse files
committed
feat: optimize cr
1 parent 5f31d24 commit 0e651c9

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@ const getDirTree = (cmd) => {
88
extensions: /\.md/,
99
prerender: true,
1010
}
11-
// collect unique tags from all articles.
12-
const tagsArr = []
1311
const mapTagsWithArticle = []
1412
const dirTree = dirs.map(path => DirectoryTree({
1513
path,
1614
options: otherProps,
17-
tagsArr,
1815
mapTagsWithArticle
1916
}))
2017

2118
return {
2219
dirTree,
23-
// duplicate total tags from document.
24-
// tagsArr: ['custom Tag 1', 'custom Tag 2']
25-
tagsArr,
2620
// map tags with path. [{ tagName: 'custom Tag 1', mapArticle: [{ path, name }]}]
2721
mapTagsWithArticle
2822
}
@@ -34,6 +28,7 @@ const getPrerenderRoutes = (dirTree) => {
3428
const dpCloneDirTree = JSON.parse(JSON.stringify(dirTree))
3529
const result = recursiveDirTree(dpCloneDirTree)
3630
result.push('/404')
31+
result.push('/tags')
3732
return result
3833
}
3934

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ const { execSync } = require('child_process')
66
const {
77
replaceForFrontMatter,
88
generateRandomId,
9-
// getDocsConfig
109
} = require('crd-utils')
1110
const { getDigitFromDir, timeFormat } = require('../utils')
1211

13-
// const docsConfig = getDocsConfig()
14-
1512
const constants = {
1613
DIRECTORY: 'directory',
1714
FILE: 'file',
@@ -53,18 +50,23 @@ function safeReadDirSync(path) {
5350
* prerender: Boolean. Used for prerender.
5451
* generate: Boolean. Used for generating info in front-matter.
5552
* }
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+
* }]}]
5660
*/
5761
function directoryTree({
5862
path,
5963
options,
6064
tagsArr = [],
61-
// [{ tagName: 'custom Tag 1', mapArticle: [{ path, title }]}]
6265
mapTagsWithArticle = [],
6366
routePath = ''
6467
}) {
6568
const name = PATH.basename(path, '.md')
6669
const item = { name }
67-
// const routePropsCurrent = `${routePath}/${name}`.replace(/.md$/, '')
6870
const routePropsCurrent = `${routePath}/${name}`
6971
if (!options.prerender) {
7072
item.path = path
@@ -110,8 +112,7 @@ function directoryTree({
110112
}
111113

112114
const yamlParse = contentMatch ? YAML.parse(contentMatch[1]) : {}
113-
const articleTags = yamlParse.tags
114-
const abbrlink = yamlParse.abbrlink
115+
const { tags: articleTags, abbrlink } = yamlParse
115116
if (Array.isArray(articleTags)) {
116117
const cpArticleTags = Array.from(new Set(articleTags))
117118
for (let i = 0; i < cpArticleTags.length; i++) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Link } from 'react-router-dom'
22
import { ifProd } from 'crd-client-utils'
33
import styles from './index.less'
44

5+
/**
6+
* name: the name of tag category.
7+
*/
58
const Tags = ({ name }) => {
69
const { user, repo } = DOCSCONFIG || {}
710

@@ -15,7 +18,7 @@ const Tags = ({ name }) => {
1518
return <Link
1619
className={styles['tags-text']}
1720
to={ifProd ? `/${repo}${path}` : `${path}`}
18-
key={title}
21+
key={path}
1922
>
2023
{title}
2124
</Link>

0 commit comments

Comments
 (0)