File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -50,14 +50,16 @@ 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+ . then ( ( t ) => new Blob ( [ t ] , { type : "text/plain" } ) )
57+ . catch ( ( e ) => {
58+ throw new Error ( `Received ${ e . message } for ${ markdownUrl } ` ) ;
59+ } ) ,
60+ } ) ;
5861
59- const markdown = await response . text ( ) ;
60- await navigator . clipboard . writeText ( markdown ) ;
62+ await navigator . clipboard . write ( [ clipboardItem ] ) ;
6163 track ( "clicked copy page button" , {
6264 value : "copy markdown" ,
6365 } ) ;
You can’t perform that action at this time.
0 commit comments