Skip to content

Commit 7701418

Browse files
justin808claude
andauthored
Add prominent Edit on GitHub buttons to doc pages (#49)
* Add prominent Edit on GitHub buttons to doc pages Two edit buttons for evaluation: 1. Breadcrumb row: small outlined "Edit" button right-aligned next to breadcrumbs 2. Title area: "Edit on GitHub" button floated right next to the H1 Hides the default bottom "Edit this page" link since it's now redundant. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix CI: use main branch instead of master for react_on_rails repo The react_on_rails repo uses main as its default branch, not master. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix build failure: guard useDoc() on category index pages useDoc() was called unconditionally in the DocBreadcrumbs wrapper, but category index pages don't have a DocProvider context. Wrap the call in a try/catch so the Edit button gracefully disappears on pages where doc metadata is unavailable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Simplify Edit button: remove big button, add GitHub logo to breadcrumb Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 41480e1 commit 7701418

5 files changed

Lines changed: 101 additions & 0 deletions

File tree

prototypes/docusaurus/src/css/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,8 @@ div[class*='announcementBar'] a {
174174
color: #ffffff !important;
175175
text-decoration: none;
176176
}
177+
178+
/* Hide the default bottom "Edit this page" link — replaced by prominent top buttons */
179+
.theme-doc-footer-edit-meta-row {
180+
display: none;
181+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import type {ReactNode} from 'react';
2+
import DocBreadcrumbs from '@theme-original/DocBreadcrumbs';
3+
import type DocBreadcrumbsType from '@theme/DocBreadcrumbs';
4+
import type {WrapperProps} from '@docusaurus/types';
5+
import {useDoc} from '@docusaurus/plugin-content-docs/client';
6+
7+
import styles from './styles.module.css';
8+
9+
type Props = WrapperProps<typeof DocBreadcrumbsType>;
10+
11+
function GitHubIcon(): ReactNode {
12+
return (
13+
<svg
14+
viewBox="0 0 16 16"
15+
width="14"
16+
height="14"
17+
fill="currentColor"
18+
aria-hidden="true">
19+
<path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z" />
20+
</svg>
21+
);
22+
}
23+
24+
function useDocSafe(): {editUrl: string | undefined} | null {
25+
try {
26+
const {metadata} = useDoc();
27+
return {editUrl: metadata.editUrl};
28+
} catch {
29+
// useDoc() throws on category index pages where DocProvider is absent
30+
return null;
31+
}
32+
}
33+
34+
export default function DocBreadcrumbsWrapper(props: Props): ReactNode {
35+
const doc = useDocSafe();
36+
const editUrl = doc?.editUrl;
37+
38+
return (
39+
<div className={styles.breadcrumbRow}>
40+
<DocBreadcrumbs {...props} />
41+
{editUrl && (
42+
<a
43+
href={editUrl}
44+
target="_blank"
45+
rel="noopener noreferrer"
46+
className={styles.editButton}
47+
title="Edit this page on GitHub">
48+
<GitHubIcon />
49+
<span>Edit</span>
50+
</a>
51+
)}
52+
</div>
53+
);
54+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.breadcrumbRow {
2+
display: flex;
3+
align-items: center;
4+
justify-content: space-between;
5+
gap: 1rem;
6+
}
7+
8+
.editButton {
9+
display: inline-flex;
10+
align-items: center;
11+
gap: 0.35rem;
12+
flex-shrink: 0;
13+
padding: 0.25rem 0.65rem;
14+
border: 1px solid var(--site-border);
15+
border-radius: 6px;
16+
background: var(--site-soft-surface);
17+
color: var(--ifm-color-content-secondary);
18+
font-size: 0.8rem;
19+
font-weight: 500;
20+
line-height: 1;
21+
text-decoration: none;
22+
transition: background 0.15s, color 0.15s, border-color 0.15s;
23+
white-space: nowrap;
24+
}
25+
26+
.editButton:hover {
27+
background: var(--ifm-color-primary);
28+
border-color: var(--ifm-color-primary);
29+
color: #ffffff;
30+
text-decoration: none;
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type {ReactNode} from 'react';
2+
import Content from '@theme-original/DocItem/Content';
3+
import type ContentType from '@theme/DocItem/Content';
4+
import type {WrapperProps} from '@docusaurus/types';
5+
6+
type Props = WrapperProps<typeof ContentType>;
7+
8+
export default function ContentWrapper(props: Props): ReactNode {
9+
return <Content {...props} />;
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Intentionally empty — big Edit on GitHub button removed */

0 commit comments

Comments
 (0)