Skip to content

Commit 1627a8f

Browse files
committed
docs: update site
1 parent 4798700 commit 1627a8f

File tree

11 files changed

+811
-93
lines changed

11 files changed

+811
-93
lines changed

scripts/gulpfile.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,26 @@ function dist (done) {
5050

5151
function copyHtml () {
5252
const rl = readline.createInterface({
53-
input: fs.createReadStream(path.join(cwd, 'site/demo.js')),
53+
input: fs.createReadStream(path.join(cwd, 'site/demoRoutes.js')),
5454
})
5555

5656
rl.on('line', (line) => {
57-
const name = line.split('antd/')[1].split('/')[0]
58-
console.log('create path:', name)
59-
const toPaths = [
60-
`site-dist/components/${name}`,
61-
`site-dist/components/${name}-cn`,
62-
`site-dist/iframe/${name}`,
63-
`site-dist/iframe/${name}-cn`,
64-
]
65-
toPaths.forEach(toPath => {
66-
rimraf.sync(path.join(cwd, toPath))
67-
mkdirp(path.join(cwd, toPath), function () {
68-
fs.writeFileSync(path.join(cwd, `${toPath}/index.html`), fs.readFileSync(path.join(cwd, 'site-dist/index.html')))
57+
if (line.indexOf('path:') > -1) {
58+
const name = line.split("'")[1].split("'")[0]
59+
console.log('create path:', name)
60+
const toPaths = [
61+
`site-dist/components/${name}`,
62+
// `site-dist/components/${name}-cn`,
63+
`site-dist/iframe/${name}`,
64+
// `site-dist/iframe/${name}-cn`,
65+
]
66+
toPaths.forEach(toPath => {
67+
rimraf.sync(path.join(cwd, toPath))
68+
mkdirp(path.join(cwd, toPath), function () {
69+
fs.writeFileSync(path.join(cwd, `${toPath}/index.html`), fs.readFileSync(path.join(cwd, 'site-dist/index.html')))
70+
})
6971
})
70-
})
72+
}
7173
})
7274
const source = [
7375
'docs/vue/*.md',

site/components/api.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import { isZhCN } from '../util'
99
export default {
1010
name: 'api',
11+
inject: {
12+
demoContext: { default: {}},
13+
},
1114
data () {
12-
const { name } = this.$route.params
1315
return {
14-
isZhCN: isZhCN(name),
16+
isZhCN: isZhCN(this.demoContext.name),
1517
}
1618
},
1719
}

site/components/demoBox.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ export default {
4848
inject: {
4949
_store: { default: {}},
5050
iframeDemo: { default: {}},
51+
demoContext: { default: {}},
5152
},
5253
data () {
53-
const { name = '' } = this.$route.params
54+
const { name = '' } = this.demoContext
5455
const { html, script, style, us, cn, sourceCode } = this.jsfiddle
5556
// let sourceCode = `<template>${html}</template>\n`
5657
// sourceCode = script ? sourceCode + '\<script>' + script + '<\/script>' : sourceCode

site/components/iframe.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
<script>
2-
import * as AllDemo from '../demo'
2+
// import * as AllDemo from '../demo'
33
44
export default {
55
props: {
66
name: String,
7+
hash: String,
78
},
8-
render () {
9-
const name = this.name
10-
const titleMap = {}
11-
for (const [title] of Object.entries(AllDemo)) {
12-
const key = `${title.replace(/(\B[A-Z])/g, '-$1').toLowerCase()}`
13-
titleMap[key] = title
9+
provide () {
10+
return {
11+
demoContext: this,
1412
}
15-
const Demo = AllDemo[titleMap[name.replace(/-cn\/?$/, '')]]
16-
const hash = this.$route.hash.replace('#', '')
13+
},
14+
render () {
15+
// const name = this.name
16+
// const titleMap = {}
17+
// for (const [title] of Object.entries(AllDemo)) {
18+
// const key = `${title.replace(/(\B[A-Z])/g, '-$1').toLowerCase()}`
19+
// titleMap[key] = title
20+
// }
21+
// const Demo = AllDemo[titleMap[name.replace(/-cn\/?$/, '')]]
22+
// const hash = this.$route.hash.replace('#', '')
1723
return (
1824
<div id='iframe-page'>
19-
<Demo iframeName={hash} />
25+
<router-view></router-view>
2026
</div>
2127
)
2228
},

site/components/layout.vue

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
2-
import * as AllDemo from '../demo'
2+
import Vue from 'vue'
3+
import AllDemo from '../demo'
34
import Header from './header'
45
import zhCN from 'antd/locale-provider/zh_CN'
56
import enUS from 'antd/locale-provider/default'
@@ -19,6 +20,8 @@ const docsList = [
1920
export default {
2021
props: {
2122
name: String,
23+
showDemo: Boolean,
24+
showApi: Boolean,
2225
},
2326
data () {
2427
this.store = create({
@@ -29,6 +32,11 @@ export default {
2932
currentSubMenu: [],
3033
}
3134
},
35+
provide () {
36+
return {
37+
demoContext: this,
38+
}
39+
},
3240
beforeDestroy () {
3341
if (this.unsubscribe) {
3442
this.unsubscribe()
@@ -117,6 +125,7 @@ export default {
117125
document.title = titleStr
118126
},
119127
},
128+
120129
render () {
121130
const name = this.name
122131
const isCN = isZhCN(name)
@@ -136,11 +145,18 @@ export default {
136145
const type = d.type || 'Other'
137146
const key = `${title.replace(/(\B[A-Z])/g, '-$1').toLowerCase()}`
138147
titleMap[key] = title
148+
AllDemo[title].key = key
139149
menuConfig[type] = menuConfig[type] || []
140150
menuConfig[type].push(d)
141151
}
142152
const reName = name.replace(/-cn\/?$/, '')
143-
const Demo = AllDemo[titleMap[reName]]
153+
// const Demo = new Vue({
154+
// template: '<demo-component/>',
155+
// components: {
156+
// 'demo-component': () => import(`../../components/${AllDemo[titleMap[reName]].key}/demo/index.vue`),
157+
// },
158+
// })
159+
// AllDemo[titleMap[reName]]
144160
const MenuGroup = []
145161
for (const [type, menus] of Object.entries(menuConfig)) {
146162
const MenuItems = []
@@ -167,7 +183,7 @@ export default {
167183
if (!isCN) {
168184
locale = enUS
169185
}
170-
this.resetDocumentTitle(Demo, reName, isCN)
186+
this.resetDocumentTitle(AllDemo[titleMap[reName]], reName, isCN)
171187
return (
172188
<div class='page-wrapper'>
173189
<Header searchData={searchData} name={name}/>
@@ -192,17 +208,18 @@ export default {
192208
<div class='toc-affix' style='width: 110px;'>
193209
{this.getSubMenu(isCN)}
194210
</div>
195-
{Demo ? <Provider store={this.store}>
196-
<Demo key={isCN ? 'cn' : 'en'}/>
211+
{this.showDemo ? <Provider store={this.store} key={isCN ? 'cn' : 'en'}>
212+
<router-view></router-view>
197213
</Provider> : ''}
198-
<div class='markdown api-container' ref='doc'>
214+
{this.showApi ? <div class='markdown api-container' ref='doc'>
199215
<router-view></router-view>
200-
</div>
216+
</div> : ''}
201217
</div>
202218
</a-col>
203219
</a-row>
204220
</div>
205221
</a-locale-provider>
222+
{ name.indexOf('back-top') === -1 ? <a-back-top /> : null }
206223
</div>
207224
)
208225
},

site/components/md.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ export default {
3232
cn: String,
3333
us: String,
3434
},
35+
inject: {
36+
demoContext: { default: {}},
37+
},
3538
data () {
36-
const { name } = this.$route.params
3739
let text = ''
3840
const { cn, us } = this
3941
if (this.$slots.default && this.$slots.default[0] && this.$slots.default[0].text) {
4042
text = this.$slots.default[0].text
4143
} else {
42-
text = isZhCN(name) ? cn : us
44+
text = isZhCN(this.demoContext.name) ? cn : us
4345
}
4446
text = text || ''
4547
text = text.split('\n').map(t => t.trim()).join('\n')

0 commit comments

Comments
 (0)