File tree Expand file tree Collapse file tree 8 files changed +57
-17
lines changed Expand file tree Collapse file tree 8 files changed +57
-17
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,6 @@ inject: injectLogic/index.js
4242
4343# Use abbrlink
4444abbrlink : true
45+
46+ # show Tags in head
47+ tags : true
Original file line number Diff line number Diff line change @@ -3,7 +3,11 @@ const fs = require('fs')
33const PATH = require ( 'path' )
44const YAML = require ( 'yamljs' )
55const { execSync } = require ( 'child_process' )
6- const { replaceForFrontMatter, generateRandomId } = require ( 'crd-utils' )
6+ const {
7+ replaceForFrontMatter,
8+ generateRandomId,
9+ getStrAfterPointed
10+ } = require ( 'crd-utils' )
711const { getDigitFromDir, timeFormat } = require ( '../utils' )
812
913const constants = {
@@ -55,7 +59,9 @@ function directoryTree({
5559 // [{ tagName: 'custom Tag 1', mapArticle: [{ path, title }] }]
5660 mapTagsWithArticle = [ ]
5761} ) {
62+ console . log ( '✅✅ path' , path )
5863 const name = PATH . basename ( path )
64+ console . log ( '✅✅ name' , name )
5965 const item = { name }
6066 if ( ! options . prerender ) {
6167 item . path = path
Original file line number Diff line number Diff line change @@ -77,5 +77,6 @@ module.exports = function (source) {
7777 content = JSON . stringify ( content )
7878 . replace ( / \u2028 / g, '\\u2028' )
7979 . replace ( / \u2029 / g, '\\u2029' )
80+
8081 return `module.exports = ${ content } `
8182}
Original file line number Diff line number Diff line change @@ -12,11 +12,7 @@ const paths = require('./path')
1212
1313module . exports = function ( cmd ) {
1414 const docsConfig = getDocsConfig ( )
15- const { tagsArr, mapTagsWithArticle } = getDirTree ( cmd )
16-
17- console . log ( '✅✅ tagsArr' , tagsArr )
18- console . log ( '✅✅ mapTagsWithArticle' , JSON . stringify ( mapTagsWithArticle ) )
19-
15+ const { mapTagsWithArticle } = getDirTree ( cmd )
2016 config . mode = 'development'
2117 config . devtool = 'eval-source-map'
2218 config . entry = [
@@ -119,7 +115,7 @@ module.exports = function (cmd) {
119115 config . plugins = config . plugins . concat ( [
120116 new webpack . DefinePlugin ( {
121117 env : JSON . stringify ( 'dev' ) ,
122- tagsArr : JSON . stringify ( tagsArr )
118+ mapTagsWithArticle : JSON . stringify ( mapTagsWithArticle )
123119 } ) ,
124120 new webpack . HotModuleReplacementPlugin ( ) ,
125121 new HtmlWebpackPlugin ( {
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
1818
1919module . exports = function ( cmd ) {
2020 const docsConfig = getDocsConfig ( )
21- const { dirTree, tagsArr } = getDirTree ( cmd )
21+ const { dirTree, mapTagsWithArticle } = getDirTree ( cmd )
2222 const routes = getPrerenderRoutes ( dirTree )
2323
2424 config . mode = 'production'
@@ -124,7 +124,7 @@ module.exports = function (cmd) {
124124 config . plugins = config . plugins . concat ( [
125125 new webpack . DefinePlugin ( {
126126 env : JSON . stringify ( 'prod' ) ,
127- tagsArr : JSON . stringify ( tagsArr )
127+ mapTagsWithArticle : JSON . stringify ( mapTagsWithArticle )
128128 } ) ,
129129 new HtmlWebpackPlugin ( {
130130 inject : true ,
Original file line number Diff line number Diff line change 1+ import { Link } from 'react-router-dom'
2+ import { ifProd } from 'crd-client-utils'
13import styles from './index.less'
24
3- const Tags = ( { } ) => {
5+ const Tags = ( { name } ) => {
46 const { user, repo } = DOCSCONFIG || { }
57
6- console . log ( 'tagsArr' , tagsArr )
7-
88 return (
99 < div className = { styles . tags } >
10- < div className = { styles [ 'tags-title' ] } > tags </ div >
10+ < div className = { styles [ 'tags-title' ] } > { name || 'Tags' } </ div >
1111 < div className = { styles [ 'tags-content' ] } >
1212 {
13- tagsArr . map ( tag => {
14- return < a className = { styles [ 'tags-text' ] } > { tag } </ a >
15- } )
13+ name
14+ ? mapTagsWithArticle . find ( ( { tagName } ) => tagName === name ) ?. mapArticle . map ( ( { path, title } ) => {
15+ return < Link
16+ className = { styles [ 'tags-text' ] }
17+ to = { ifProd ? `/${ repo } /${ path } ` : `/${ path } ` }
18+ key = { title }
19+ >
20+ { title }
21+ </ Link >
22+ } )
23+ : mapTagsWithArticle . map ( ( { tagName } ) => {
24+ return < Link
25+ className = { styles [ 'tags-text' ] }
26+ to = { ifProd ? `/${ repo } /tags/${ tagName } ` : `/tags/${ tagName } ` }
27+ key = { tagName }
28+ >
29+ { tagName }
30+ </ Link >
31+ } )
1632 }
1733 </ div >
1834 </ div >
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ function BasicLayout({
213213 < >
214214 < nav
215215 className = { cx ( styles . menuWrapper , {
216- [ `${ styles [ "menuwrapper -inlineCollapsed" ] } ` ] : inlineCollapsed ,
216+ [ `${ styles [ 'menuWrapper -inlineCollapsed' ] } ` ] : inlineCollapsed ,
217217 } ) }
218218 >
219219 { renderMenu ( menuSource ) }
@@ -263,6 +263,14 @@ function BasicLayout({
263263 path = { ifAddPrefix ? `/${ repo } /tags` : '/tags' }
264264 render = { ( ) => < Tags /> }
265265 />
266+ < Route
267+ key = '/tags/:name'
268+ path = { ifAddPrefix ? `/${ repo } /tags/:name` : '/tags/:name' }
269+ render = { ( { match } ) => {
270+ const { name } = match . params
271+ return < Tags name = { name } />
272+ } }
273+ />
266274 < Redirect to = { ifAddPrefix ? `/${ repo } /404` : `/404` } />
267275 </ Switch >
268276 { renderPageFooter ( ) }
Original file line number Diff line number Diff line change @@ -56,12 +56,22 @@ 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+
5968module . exports = {
6069 resolveApp,
6170 resolveTool,
6271 getDocsConfig,
6372 replaceForFrontMatter,
6473 generateRandomId,
74+ getStrAfterPointed,
6575 // common paths
6676 docsGitIgnore : resolveApp ( '.gitignore' ) ,
6777 docsBase : resolveApp ( '' ) ,
You can’t perform that action at this time.
0 commit comments