@@ -11,38 +11,33 @@ import { getMarkdownContent } from "@/lib/get-markdown-content";
1111
1212const cache = new Map < string , string > ( ) ;
1313
14- // Helper function to normalize doc file paths to GitHub URL format
15- function normalizeDocPathForGithub ( path : string ) : string {
16- let normalized = path . startsWith ( "content/" ) ? path : `content/${ path } ` ;
17- if ( ! normalized . startsWith ( "content/docs/" ) ) {
18- normalized = normalized . replace ( / ^ c o n t e n t \/ / , "content/docs/" ) ;
19- }
20- return normalized ;
21- }
22-
2314export function LLMCopyButton ( {
2415 /**
25- * The page path for fetching the raw Markdown/MDX content
16+ * The page slugs for fetching the raw Markdown/MDX content
2617 */
27- pagePath ,
18+ slugs ,
2819} : {
29- pagePath : string ;
20+ slugs : string [ ] ;
3021} ) {
3122 const [ isLoading , setLoading ] = useState ( false ) ;
3223 const [ checked , onClick ] = useCopyButton ( async ( ) => {
3324 try {
3425 setLoading ( true ) ;
35- const cached = cache . get ( pagePath ) ;
36- const content = cached || ( await getMarkdownContent ( pagePath ) ) ;
26+ const cacheKey = slugs . join ( "/" ) ;
27+ const cached = cache . get ( cacheKey ) ;
28+ const content = cached || ( await getMarkdownContent ( slugs ) ) ;
3729
3830 if ( ! cached ) {
39- cache . set ( pagePath , content ) ;
31+ cache . set ( cacheKey , content ) ;
4032 }
4133
4234 await navigator . clipboard . writeText ( content ) ;
4335 } catch ( error ) {
4436 console . error ( "Failed to copy markdown to clipboard:" , error ) ;
45- window . alert ( "Failed to copy the markdown to your clipboard. Please copy it manually." ) ;
37+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
38+ window . alert (
39+ `Failed to copy the markdown to your clipboard: ${ errorMessage } \n\nPlease copy it manually.` ,
40+ ) ;
4641 throw error ;
4742 } finally {
4843 setLoading ( false ) ;
0 commit comments