forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
46 lines (40 loc) · 1007 Bytes
/
index.tsx
File metadata and controls
46 lines (40 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as React from 'react'
import GuideToc from '../GuideToc'
import Doc from '../Doc'
import { Wrapper } from './elements'
import { compile, getGithubBaseUrl } from '../../utils'
type State = {
content: string
}
type Props = {
currentPath: string
}
class Guide extends React.Component<Props, State> {
state = {
content: null,
}
componentDidMount() {
const pathArray = this.props.currentPath.split('/')
const name = pathArray.pop()
const type = pathArray.pop()
import('../../../guides/' + type + '/' + name + '.md').then((module) =>
this.setState({ content: module })
)
}
getGithubUrl() {
return getGithubBaseUrl() + this.props.currentPath + '.md'
}
render() {
if (!this.state.content) {
return null
}
const compiled = compile(this.state.content)
return (
<Wrapper>
<Doc url={this.getGithubUrl()}>{compiled.tree}</Doc>
<GuideToc toc={compiled.toc} />
</Wrapper>
)
}
}
export default Guide