Skip to content

Commit 0044719

Browse files
authored
docs: add source code link in nav bar (#199)
1 parent 8ffa054 commit 0044719

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

docs/src/gatsby-theme-apollo-docs/components/page-content.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
2-
import { useRef, useState } from 'react';
2+
import React, { useRef, useState } from 'react';
33
import SectionNav from './section-nav';
44
import styled from '@emotion/styled';
55
import useMount from 'react-use/lib/useMount';
@@ -179,8 +179,9 @@ export default function PageContent(props) {
179179
);
180180
});
181181

182-
const githubUrl = props.githubUrl.replace("tree/", "blob/")
182+
const githubUrl = props.githubUrl.replace("tree/", "blob/")
183183
.replace("/content/", "/docs/content/")
184+
const sourceUrl = /.+?(?=tree)/.exec(props.githubUrl)
184185

185186
const editLink = githubUrl && (
186187
<AsideLink href={githubUrl}>
@@ -210,6 +211,9 @@ export default function PageContent(props) {
210211
/>
211212
)}
212213
{editLink}
214+
<AsideLink href={sourceUrl}>
215+
<IconGithub /> Source code
216+
</AsideLink>
213217
</Aside>
214218
</Wrapper>
215219
);
@@ -218,11 +222,12 @@ export default function PageContent(props) {
218222
PageContent.propTypes = {
219223
children: PropTypes.node.isRequired,
220224
pathname: PropTypes.string.isRequired,
221-
githubUrl: PropTypes.string,
225+
githubUrl: PropTypes.string.isRequired,
222226
pages: PropTypes.array.isRequired,
223227
hash: PropTypes.string.isRequired,
224228
title: PropTypes.string.isRequired,
225-
graphManagerUrl: PropTypes.string.isRequired,
229+
graphManagerUrl: PropTypes.string,
226230
headings: PropTypes.array.isRequired,
227231
spectrumUrl: PropTypes.string
228232
};
233+

0 commit comments

Comments
 (0)