File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { useState } from 'react' ;
4+ import { Clipboard , Check } from 'react-feather' ;
5+
6+ interface Props {
7+ /** Absolute path to the markdown version of this page (e.g. `/docs/page.md`) */
8+ markdownPath : string ;
9+ }
10+
11+ export function CopyForLLMButton ( { markdownPath} : Props ) {
12+ const [ copied , setCopied ] = useState ( false ) ;
13+
14+ async function handleClick ( ) {
15+ try {
16+ // Attempt to fetch the markdown content and copy it
17+ const response = await fetch ( markdownPath ) ;
18+ const text = await response . text ( ) ;
19+ await navigator . clipboard . writeText ( text ) ;
20+ } catch ( err ) {
21+ // Fallback: copy the markdown url itself
22+ await navigator . clipboard . writeText ( window . location . origin + markdownPath ) ;
23+ } finally {
24+ setCopied ( true ) ;
25+ setTimeout ( ( ) => setCopied ( false ) , 1200 ) ;
26+ }
27+ }
28+
29+ return (
30+ < button
31+ type = "button"
32+ onClick = { handleClick }
33+ title = "Copy page content for LLM"
34+ className = "mr-2 float-right flex items-center gap-1 border rounded px-2 py-1 text-xs hover:bg-[var(--gray-2)]"
35+ data-mdast = "ignore"
36+ >
37+ { copied ? (
38+ < Check size = { 14 } />
39+ ) : (
40+ < Clipboard size = { 14 } />
41+ ) }
42+ < span className = "whitespace-nowrap" > Copy for LLM</ span >
43+ </ button >
44+ ) ;
45+ }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {PlatformSdkDetail} from '../platformSdkDetail';
2323import { Sidebar } from '../sidebar' ;
2424import { SidebarTableOfContents } from '../sidebarTableOfContents' ;
2525import { ReaderDepthTracker } from '../track-reader-depth' ;
26+ import { CopyForLLMButton } from '../copyForLLMButton' ;
2627
2728type Props = {
2829 children : ReactNode ;
@@ -94,6 +95,7 @@ export function DocPage({
9495 >
9596 < Markdown className = "flex p-0 flex-wrap" width = { 24 } height = { 24 } />
9697 </ Link >
98+ < CopyForLLMButton markdownPath = { `/${ pathname } .md` } />
9799 </ div >
98100 < div >
99101 < hgroup >
You can’t perform that action at this time.
0 commit comments