Skip to content

Commit 72d1309

Browse files
author
Emily
authored
Merge pull request #770 from primer/edit-links
Add Edit on GitHub links to docs
2 parents 5ad3751 + 58221b7 commit 72d1309

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pages/_app.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ import React from 'react'
22
import App, {Container} from 'next/app'
33
import {MDXProvider} from '@mdx-js/tag'
44
import Head from 'next/head'
5-
import {BaseStyles, BorderBox, Box, Flex, theme} from '@primer/components'
5+
import Octicon, {Pencil} from '@githubprimer/octicons-react'
6+
import {BaseStyles, Link, Text, BorderBox, Box, Flex, theme} from '@primer/components'
67
import {PackageHeader} from '../docs/components'
78
import {Header, MarkdownHeading, JumpNav, SideNav} from '@primer/blueprints'
89
import {NavList} from '@primer/blueprints/next-components'
910
import getComponents from '../docs/markdown'
1011
import documents from '../searchIndex'
1112
import {config, requirePage, rootPage} from '../docs/utils'
1213
import {CONTENT_MAX_WIDTH} from '../docs/constants'
14+
import {repository} from '../package.json'
1315

1416
import '../src/index.scss'
1517

18+
const DocLink = props => <Link nounderline {...props} />
19+
const editLinkBase = `${repository}/edit/master/pages`
20+
1621
export default class MyApp extends App {
1722
static async getInitialProps({Component, ctx}) {
1823
let page = {}
@@ -30,6 +35,7 @@ export default class MyApp extends App {
3035
const {Component, page} = this.props
3136
const node = rootPage.first(node => node.path === pathname) || {}
3237
const {file, meta = {}} = node || {}
38+
const isIndex = file.includes('index')
3339
const components = getComponents(node)
3440

3541
const Hero = file ? requirePage(file).Hero : null
@@ -69,6 +75,17 @@ export default class MyApp extends App {
6975
<pre>{JSON.stringify(meta, null, 2)}</pre>
7076
</details>
7177
)}
78+
{pathname && (
79+
<Box color="gray.5" borderColor="gray.2" borderTop={1} my={6} pt={2}>
80+
<Text mr={2}>
81+
<Octicon icon={Pencil} />
82+
</Text>
83+
<DocLink muted href={`${editLinkBase}${pathname}${isIndex ? '/index' : ''}.md`}>
84+
Edit this page
85+
</DocLink>{' '}
86+
on GitHub
87+
</Box>
88+
)}
7289
</div>
7390
</Box>
7491
</Box>

0 commit comments

Comments
 (0)