Skip to content

Commit 2663510

Browse files
committed
feat: generate tagname with mapArticle
1 parent 9a70701 commit 2663510

File tree

7 files changed

+56
-38
lines changed

7 files changed

+56
-38
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ const getDirTree = (cmd) => {
88
extensions: /\.md/,
99
prerender: true,
1010
}
11+
// collect unique tags from all articles.
1112
const tagsArr = []
13+
const mapTagsWithArticle = []
1214
const dirTree = dirs.map(path => DirectoryTree({
1315
path,
1416
options: otherProps,
15-
tagsArr
17+
tagsArr,
18+
mapTagsWithArticle
1619
}))
1720

1821
return {
1922
dirTree,
2023
// duplicate total tags from document.
21-
tagsArr: Array.from(new Set(tagsArr))
24+
// tagsArr: ['custom Tag 1', 'custom Tag 2']
25+
tagsArr,
26+
// map tags with path. [{ tagName: 'custom Tag 1', mapArticle: [{ path, name }]}]
27+
mapTagsWithArticle
2228
}
2329
}
2430

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ function safeReadDirSync(path) {
5151
function directoryTree({
5252
path,
5353
options,
54-
tagsArr = []
54+
tagsArr = [],
55+
// [{ tagName: 'custom Tag 1', mapArticle: [{ path, title }]}]
56+
mapTagsWithArticle = []
5557
}) {
5658
const name = PATH.basename(path)
5759
const item = { name }
@@ -99,9 +101,31 @@ function directoryTree({
99101
}
100102

101103
const yamlParse = contentMatch ? YAML.parse(contentMatch[1]) : {}
104+
const articleTags = yamlParse.tags
105+
const pathResult = yamlParse.abbrlink
106+
if (Array.isArray(articleTags)) {
107+
const cpArticleTags = Array.from(new Set(articleTags))
102108

103-
if (Array.isArray(yamlParse.tags)) {
104-
tagsArr.push(...yamlParse.tags)
109+
for (let i = 0; i < cpArticleTags.length; i++) {
110+
const articleTag = cpArticleTags[i]
111+
const articleTagIndex = tagsArr.indexOf(articleTag)
112+
if (articleTagIndex > -1) {
113+
mapTagsWithArticle[articleTagIndex]['mapArticle'].push({
114+
path: pathResult ? pathResult : name,
115+
title: name
116+
})
117+
} else {
118+
tagsArr.push(cpArticleTags[i])
119+
mapTagsWithArticle.push({
120+
tagName: cpArticleTags[i],
121+
mapArticle: [{
122+
// todo: replace name
123+
path: pathResult ? pathResult : name,
124+
title: name
125+
}]
126+
})
127+
}
128+
}
105129
}
106130

107131
item.mdconf = yamlParse
@@ -139,7 +163,8 @@ function directoryTree({
139163
directoryTree({
140164
path: PATH.join(path, child),
141165
options,
142-
tagsArr
166+
tagsArr,
167+
mapTagsWithArticle
143168
}),
144169
)
145170
.filter(e => !!e)

packages/crd-scripts/src/conf/webpack.config.dev.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const paths = require('./path')
1212

1313
module.exports = function (cmd) {
1414
const docsConfig = getDocsConfig()
15-
const { tagsArr } = getDirTree(cmd)
15+
const { tagsArr, mapTagsWithArticle } = getDirTree(cmd)
16+
17+
console.log('✅✅ tagsArr', tagsArr)
18+
console.log('✅✅ mapTagsWithArticle', JSON.stringify(mapTagsWithArticle))
1619

1720
config.mode = 'development'
1821
config.devtool = 'eval-source-map'

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ const Tags = ({}) => {
99
<div className={styles.tags}>
1010
<div className={styles['tags-title']}>tags</div>
1111
<div className={styles['tags-content']}>
12-
<a className={styles['tags-text']}>Annual Summary</a>
13-
<a className={styles['tags-text']}>css</a>
14-
<a className={styles['tags-text']}>ES7</a>
15-
<a className={styles['tags-text']}>hooks</a>
16-
<a className={styles['tags-text']}>JavaScript</a>
17-
<a className={styles['tags-text']}>Mvvm</a>
18-
<a className={styles['tags-text']}>Node.js</a>
19-
<a className={styles['tags-text']}>Promise</a>
20-
<a className={styles['tags-text']}>Python</a>
21-
<a className={styles['tags-text']}>React</a>
22-
<a className={styles['tags-text']}>Redux</a>
23-
<a className={styles['tags-text']}>SEO</a>
24-
<a className={styles['tags-text']}>Schedule</a>
25-
<a className={styles['tags-text']}>TypeScript</a>
26-
<a className={styles['tags-text']}>alfred workflow</a>
27-
<a className={styles['tags-text']}>blog</a>
12+
{
13+
tagsArr.map(tag => {
14+
return <a className={styles['tags-text']}>{tag}</a>
15+
})
16+
}
2817
</div>
2918
</div>
3019
)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
font-family: Palatino, Garamond, Times, Georgia, serif;
1212
font-size: 24px;
1313
font-weight: 400;
14-
margin: initial;
1514
text-align: center;
16-
overflow-wrap: break-word;
17-
word-wrap: break-word;
1815
}
1916

2017
&-content {
2118
width: 100%;
19+
margin-top: 20px;
2220
}
2321

2422
&-text {
2523
color: #6f6f6f;
2624
padding: 10px;
25+
display: inline-flex;
2726
}
2827
}

packages/crd-seed/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Switch, Route } from 'react-router-dom'
22
import BasicLayout from './layout'
33
import NoMatch from './component/NoMatch'
4-
import Tags from './component/Tags'
54
import './index.less'
65

76
// run in the Web/Router.js
@@ -12,10 +11,6 @@ const ThemeSeed = (props) => {
1211
path="/404"
1312
render={routeProps => <NoMatch {...routeProps} {...props} />}
1413
/>
15-
<Route
16-
path="/tags"
17-
render={routeProps => <Tags {...routeProps} {...props} />}
18-
/>
1914
<Route
2015
path="/"
2116
render={(routeProps) => {

packages/crd-seed/layout/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Icon from '../component/Icon'
77
import Affix from '../component/Affix'
88
import Header from '../component/Header'
99
import Footer from '../component/Footer'
10+
import Tags from '../component/Tags'
1011
import languageMap from '../language'
1112
import { isMobile, ifAddPrefix } from '../utils'
1213
import { getOpenSubMenuKeys } from './utils'
@@ -256,6 +257,12 @@ function BasicLayout({
256257
/>
257258
)
258259
})}
260+
<Route
261+
key='/tags'
262+
exact
263+
path={ifAddPrefix ? `/${repo}/tags` : '/tags'}
264+
render={() => <Tags />}
265+
/>
259266
<Redirect to={ifAddPrefix ? `/${repo}/404` : `/404`} />
260267
</Switch>
261268
{renderPageFooter()}
@@ -265,13 +272,7 @@ function BasicLayout({
265272

266273
return (
267274
<div className={styles.wrapper}>
268-
<Header
269-
logo={logo}
270-
// href={ifAddPrefix ? `/${repo}` : `/`}
271-
// location={location}
272-
// indexProps={indexProps}
273-
// menuSource={menuSource}
274-
/>
275+
<Header logo={logo} />
275276
<div
276277
className={cx(styles.wrapperContent, {
277278
[styles.wrapperMobile]: isMobile,

0 commit comments

Comments
 (0)