Skip to content

Commit e2863b2

Browse files
committed
feat: update tags
1 parent d76a0ad commit e2863b2

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const { execSync } = require('child_process')
66
const {
77
replaceForFrontMatter,
88
generateRandomId,
9-
getStrAfterPointed
9+
// getDocsConfig
1010
} = require('crd-utils')
1111
const { getDigitFromDir, timeFormat } = require('../utils')
1212

13+
// const docsConfig = getDocsConfig()
14+
1315
const constants = {
1416
DIRECTORY: 'directory',
1517
FILE: 'file',
@@ -57,12 +59,12 @@ function directoryTree({
5759
options,
5860
tagsArr = [],
5961
// [{ tagName: 'custom Tag 1', mapArticle: [{ path, title }]}]
60-
mapTagsWithArticle = []
62+
mapTagsWithArticle = [],
63+
routePath = ''
6164
}) {
62-
console.log('✅✅ path', path)
6365
const name = PATH.basename(path)
64-
console.log('✅✅ name', name)
6566
const item = { name }
67+
const routePropsCurrent = `${routePath}/${name}`.replace(/.md$/, '')
6668
if (!options.prerender) {
6769
item.path = path
6870
}
@@ -108,25 +110,23 @@ function directoryTree({
108110

109111
const yamlParse = contentMatch ? YAML.parse(contentMatch[1]) : {}
110112
const articleTags = yamlParse.tags
111-
const pathResult = yamlParse.abbrlink
113+
const abbrlink = yamlParse.abbrlink
112114
if (Array.isArray(articleTags)) {
113115
const cpArticleTags = Array.from(new Set(articleTags))
114-
115116
for (let i = 0; i < cpArticleTags.length; i++) {
116117
const articleTag = cpArticleTags[i]
117118
const articleTagIndex = tagsArr.indexOf(articleTag)
118119
if (articleTagIndex > -1) {
119120
mapTagsWithArticle[articleTagIndex]['mapArticle'].push({
120-
path: pathResult ? pathResult : name,
121+
path: abbrlink ? `/${abbrlink}` : routePropsCurrent,
121122
title: name
122123
})
123124
} else {
124125
tagsArr.push(cpArticleTags[i])
125126
mapTagsWithArticle.push({
126127
tagName: cpArticleTags[i],
127128
mapArticle: [{
128-
// todo: replace name
129-
path: pathResult ? pathResult : name,
129+
path: abbrlink ? `/${abbrlink}` : routePropsCurrent,
130130
title: name
131131
}]
132132
})
@@ -170,7 +170,8 @@ function directoryTree({
170170
path: PATH.join(path, child),
171171
options,
172172
tagsArr,
173-
mapTagsWithArticle
173+
mapTagsWithArticle,
174+
routePath: routePropsCurrent
174175
}),
175176
)
176177
.filter(e => !!e)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Tags = ({ name }) => {
1414
? mapTagsWithArticle.find(({ tagName }) => tagName === name)?.mapArticle.map(({ path, title }) => {
1515
return <Link
1616
className={styles['tags-text']}
17+
// todo
1718
to={ifProd ? `/${repo}/${path}` : `/${path}`}
1819
key={title}
1920
>

packages/crd-utils/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,12 @@ const generateRandomId = (n) => {
5656
return res
5757
}
5858

59-
// get route after pointed char from a string.
60-
// getStrAfterPointed('/Users/mac/Developer/project/create-react-doc/docs/测试/测试路由.md', 'create-react-doc/docs/') -> 测试/测试路由.md
61-
const getStrAfterPointed = (path, pointedStr) => {
62-
const startPosition = path.indexOf(pointedStr)
63-
if (startPosition === -1) return ''
64-
const endPosition = startPosition + pointedStr.length
65-
return path.slice(endPosition, path.length)
66-
}
67-
6859
module.exports = {
6960
resolveApp,
7061
resolveTool,
7162
getDocsConfig,
7263
replaceForFrontMatter,
7364
generateRandomId,
74-
getStrAfterPointed,
7565
// common paths
7666
docsGitIgnore: resolveApp('.gitignore'),
7767
docsBase: resolveApp(''),

0 commit comments

Comments
 (0)