Skip to content

Commit 7a43357

Browse files
committed
added edit this page button
1 parent 84f29eb commit 7a43357

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/components/EditThis.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {useRouter} from 'next/router';
2+
import {ExternalLink} from './ExternalLink';
3+
import {IconGitHub} from './Icon/IconGitHub';
4+
5+
const githubBranch = 'main';
6+
const baseGithubLink = `https://github.com/reactjs/react.dev/edit/${githubBranch}/`;
7+
8+
export const EditThis = () => {
9+
const {asPath} = useRouter();
10+
const cleanedPath = asPath.split(/[\?\#]/)[0];
11+
return (
12+
<div className="flex text-link dark:text-link-dark group justify-start align-middle">
13+
<IconGitHub />
14+
<ExternalLink href={`${baseGithubLink}src/content/${cleanedPath}.md`}>
15+
<span className="text-lg group-hover:underline">
16+
Edit this page on Github
17+
</span>
18+
</ExternalLink>
19+
</div>
20+
);
21+
};

src/components/Layout/Page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {HomeContent} from './HomeContent';
2121
import {TopNav} from './TopNav';
2222
import cn from 'classnames';
2323
import Head from 'next/head';
24+
import {EditThis} from 'components/EditThis';
2425

2526
import(/* webpackPrefetch: true */ '../MDX/CodeBlock/CodeBlock');
2627

@@ -88,6 +89,7 @@ export function Page({
8889
</LanguagesContext.Provider>
8990
</TocContext.Provider>
9091
</div>
92+
{!isBlogIndex && <EditThis />}
9193
{!isBlogIndex && (
9294
<DocsPageFooter
9395
route={route}

0 commit comments

Comments
 (0)