Skip to content

Commit 8a4ff02

Browse files
feat(website): add edit on github links to guides and api docs as well
1 parent 8458b20 commit 8a4ff02

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

packages/overmind-website/src/components/Api/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22
import Doc from '../Doc'
33
import { Wrapper, List, Item, ListWrapper, TocList, TocItem } from './elements'
4-
import { compile } from '../../utils'
4+
import { compile, getGithubBaseUrl } from '../../utils'
55
import { TApi } from '../App'
66

77
type State = {
@@ -46,12 +46,15 @@ class Api extends React.Component<Props, State> {
4646
</TocList>
4747
)
4848
}
49+
getGithubUrl() {
50+
return getGithubBaseUrl() + this.props.currentPath + '.md'
51+
}
4952
render() {
5053
if (!this.state.content) {
5154
return (
5255
<Wrapper>
5356
<ListWrapper />
54-
<Doc />
57+
<Doc url={this.getGithubUrl()} />
5558
</Wrapper>
5659
)
5760
}
@@ -78,7 +81,7 @@ class Api extends React.Component<Props, State> {
7881
})}
7982
</List>
8083
</ListWrapper>
81-
<Doc>{compiled.tree}</Doc>
84+
<Doc url={this.getGithubUrl()}>{compiled.tree}</Doc>
8285
</Wrapper>
8386
)
8487
}

packages/overmind-website/src/components/Doc/elements.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import styled from '../../styled-components'
22

3+
export const Edit = styled.a`
4+
position: absolute;
5+
top: 85px;
6+
right: ${({ theme }) => theme.padding.large};
7+
`
8+
39
export const Content = styled.div`
10+
position: relative;
411
width: 700px;
512
min-height: 100vh;
613
margin: 0 auto;
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import * as React from 'react'
2-
import { Content } from './elements'
2+
import { Content, Edit } from './elements'
33

4-
const Doc: React.SFC = ({ children }) => <Content>{children}</Content>
4+
type Props = {
5+
url: string
6+
}
7+
8+
const Doc: React.SFC<Props> = ({ url, children }) => (
9+
<Content>
10+
<Edit href={url} target="_blank">
11+
edit on github
12+
</Edit>
13+
{children}
14+
</Content>
15+
)
516

617
export default Doc

packages/overmind-website/src/components/Guide/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import GuideToc from '../GuideToc'
33
import Doc from '../Doc'
44
import { Wrapper } from './elements'
5-
import { compile } from '../../utils'
5+
import { compile, getGithubBaseUrl } from '../../utils'
66

77
type State = {
88
content: string
@@ -24,6 +24,9 @@ class Guide extends React.Component<Props, State> {
2424
this.setState({ content: module })
2525
)
2626
}
27+
getGithubUrl() {
28+
return getGithubBaseUrl() + this.props.currentPath + '.md'
29+
}
2730
render() {
2831
if (!this.state.content) {
2932
return null
@@ -33,7 +36,7 @@ class Guide extends React.Component<Props, State> {
3336

3437
return (
3538
<Wrapper>
36-
<Doc>{compiled.tree}</Doc>
39+
<Doc url={this.getGithubUrl()}>{compiled.tree}</Doc>
3740
<GuideToc toc={compiled.toc} />
3841
</Wrapper>
3942
)

packages/overmind-website/src/utils.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ export const viewport = {
1010
},
1111
}
1212

13+
export const getBranch = () =>
14+
location.host.split('.')[0] === 'next' || location.hostname === 'localhost'
15+
? 'next'
16+
: 'master'
17+
18+
export const getGithubBaseUrl = () =>
19+
`https://github.com/cerebral/overmind/edit/${getBranch()}/packages/overmind-website/`
20+
1321
export const getTheme = () => localStorage.getItem('theme') || 'react'
1422

1523
export const getTypescript = () => localStorage.getItem('typescript') || false
@@ -115,14 +123,7 @@ class Example extends React.Component<{
115123
)
116124
}
117125

118-
const branch =
119-
location.host.split('.')[0] === 'next' ||
120-
location.hostname === 'localhost'
121-
? 'next'
122-
: 'master'
123-
const url = `https://github.com/cerebral/overmind/edit/${branch}/packages/overmind-website/examples/${
124-
this.props.name
125-
}.ts`
126+
const url = `${getGithubBaseUrl()}examples/${this.props.name}.ts`
126127
return (
127128
<div>
128129
{this.state.content.map((example, index) => (

0 commit comments

Comments
 (0)