File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -50,14 +50,15 @@ export default function CopyPageButton() {
5050 const handleCopyMarkdown = async ( ) => {
5151 const markdownUrl = new URL ( "index.md" , window . location . href ) . toString ( ) ;
5252 try {
53- const response = await fetch ( markdownUrl ) ;
54-
55- if ( ! response . ok ) {
56- throw new Error ( `Received ${ response . status } on ${ response . url } ` ) ;
57- }
53+ const clipboardItem = new ClipboardItem ( {
54+ [ "text/plain" ] : fetch ( markdownUrl )
55+ . then ( ( r ) => r . text ( ) )
56+ . catch ( ( e ) => {
57+ throw new Error ( `Received ${ e . message } for ${ markdownUrl } ` ) ;
58+ } ) ,
59+ } ) ;
5860
59- const markdown = await response . text ( ) ;
60- await navigator . clipboard . writeText ( markdown ) ;
61+ await navigator . clipboard . write ( [ clipboardItem ] ) ;
6162 track ( "clicked copy page button" , {
6263 value : "copy markdown" ,
6364 } ) ;
You can’t perform that action at this time.
0 commit comments