Skip to content

Commit 4ed58ff

Browse files
Marcos BergamoMarcos Bergamo
authored andcommitted
feat(beta): add edit on github for docs
1 parent 810cb70 commit 4ed58ff

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

beta/src/components/Layout/Page.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ import sidebarLearn from '../../sidebarLearn.json';
1818
import sidebarReference from '../../sidebarReference.json';
1919
import type {TocItem} from 'components/MDX/TocContext';
2020
import type {RouteItem} from 'components/Layout/getRouteMeta';
21+
import {ExternalLink} from 'components/ExternalLink';
22+
import {siteConfig} from 'siteConfig';
2123

2224
import(/* webpackPrefetch: true */ '../MDX/CodeBlock/CodeBlock');
2325

26+
function getGithubEditUrl(path: string): string {
27+
return `${siteConfig.editUrl}/../content${path}.md`;
28+
}
29+
2430
interface PageProps {
2531
children: React.ReactNode;
2632
toc: Array<TocItem>;
@@ -76,6 +82,26 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) {
7682
nextRoute={nextRoute}
7783
prevRoute={prevRoute}
7884
/>
85+
<div className="flex justify-center lg:justify-start px-4 md:px-5">
86+
<ExternalLink
87+
href={getGithubEditUrl(cleanedPath)}
88+
className="flex flex-row border-b border-transparent hover:border-gray-10">
89+
<svg
90+
xmlns="http://www.w3.org/2000/svg"
91+
fill="none"
92+
viewBox="0 0 24 24"
93+
strokeWidth={1.5}
94+
stroke="currentColor"
95+
className="w-6 h-6 mr-2">
96+
<path
97+
strokeLinecap="round"
98+
strokeLinejoin="round"
99+
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10"
100+
/>
101+
</svg>
102+
Edit on Github
103+
</ExternalLink>
104+
</div>
79105
</div>
80106
</div>
81107
</article>

beta/src/siteConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
export const siteConfig = {
6-
editUrl: 'https://github.com/reactjs/reactjs.org/edit/beta/src/pages',
6+
editUrl: 'https://github.com/reactjs/reactjs.org/edit/main/beta/src/pages',
77
copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc. All Rights Reserved.`,
88
repoUrl: 'https://github.com/facebook/react',
99
twitterUrl: 'https://twitter.com/reactjs',

0 commit comments

Comments
 (0)