Skip to content

Commit 1365d64

Browse files
authored
Add "View on GitHub" option to copy page dropdown (#58)
1 parent 4fc437b commit 1365d64

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/components/CopyPageButton.astro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const { entry, slug } = Astro.locals.starlightRoute || {}
66
const pageTitle = entry?.data?.title || 'Documentation'
77
const pageMarkdown = entry?.body || ''
88
const pageUrl = Astro.url.href
9+
10+
// Construct GitHub URL for this page
11+
const githubBaseUrl = 'https://github.com/superfly/sprites-docs/blob/main/src/content/docs/'
12+
const filePath = slug ? `${slug}.mdx` : 'index.mdx'
13+
const githubUrl = `${githubBaseUrl}${filePath}`
914
---
1015

1116
<div class="copy-page-button-wrapper">
@@ -14,6 +19,7 @@ const pageUrl = Astro.url.href
1419
pageMarkdown={pageMarkdown}
1520
pageUrl={pageUrl}
1621
pageTitle={pageTitle}
22+
githubUrl={githubUrl}
1723
/>
1824
</div>
1925

src/components/react/CopyPageButton.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ArrowUpRight, Check, Copy, Ellipsis } from 'lucide-react';
1+
import { ArrowUpRight, Check, Copy, Ellipsis, Github } from 'lucide-react';
22
import * as React from 'react';
33
import { Button } from '@/components/ui/button';
44
import {
@@ -17,6 +17,7 @@ interface CopyPageButtonProps {
1717
pageMarkdown: string;
1818
pageUrl: string;
1919
pageTitle: string;
20+
githubUrl: string;
2021
}
2122

2223
// ChatGPT logo
@@ -86,6 +87,7 @@ export function CopyPageButton({
8687
pageMarkdown,
8788
pageUrl,
8889
pageTitle,
90+
githubUrl,
8991
}: CopyPageButtonProps) {
9092
const [copied, setCopied] = React.useState(false);
9193

@@ -239,6 +241,25 @@ export function CopyPageButton({
239241
Open raw markdown in new tab
240242
</span>
241243
</DropdownMenuItem>
244+
<DropdownMenuItem
245+
onClick={() => window.open(githubUrl, '_blank')}
246+
className="flex flex-col items-start gap-0.5 py-2"
247+
>
248+
<div className="flex items-center gap-2">
249+
<Github className="size-4" aria-hidden="true" />
250+
<span className="font-medium">
251+
View on GitHub
252+
<VisuallyHidden> (opens in new tab)</VisuallyHidden>
253+
</span>
254+
<ArrowUpRight className="size-3 opacity-50" aria-hidden="true" />
255+
</div>
256+
<span
257+
className="text-xs text-muted-foreground pl-6"
258+
aria-hidden="true"
259+
>
260+
View source on GitHub
261+
</span>
262+
</DropdownMenuItem>
242263
</DropdownMenuContent>
243264
</DropdownMenu>
244265
</ButtonGroup>

0 commit comments

Comments
 (0)