@@ -5,6 +5,9 @@ import {JSDOM} from "jsdom";
5
5
import { toNotebook } from "../src/lib/notebook.js" ;
6
6
import { serialize } from "../src/lib/serialize.js" ;
7
7
8
+ const UI_ORIGIN = "https://observablehq.com" ;
9
+ const API_ORIGIN = "https://api.observablehq.com" ;
10
+
8
11
if ( process . argv [ 1 ] === import . meta. filename ) run ( ) ;
9
12
10
13
export default async function run ( args ?: string [ ] ) {
@@ -29,16 +32,16 @@ export default async function run(args?: string[]) {
29
32
return ;
30
33
}
31
34
32
- const document = new JSDOM ( ) . window . document ;
35
+ const { window } = new JSDOM ( ) ;
33
36
for ( const positional of positionals ) {
34
- let url = new URL ( positional , "https://observablehq.com" ) ;
35
- if ( url . origin === "https://observablehq.com" ) {
36
- url = new URL ( `/document${ url . pathname . replace ( / ^ \/ d \/ / , "/" ) } ` , "https://api.observablehq.com" ) ;
37
+ let url = new URL ( positional , UI_ORIGIN ) ;
38
+ if ( url . origin === UI_ORIGIN ) {
39
+ url = new URL ( `/document${ url . pathname . replace ( / ^ \/ d \/ / , "/" ) } ` , API_ORIGIN ) ;
37
40
}
38
41
const response = await fetch ( url ) ;
39
42
if ( ! response . ok ) throw new Error ( `unable to fetch: ${ url } ` ) ;
40
43
const { title , nodes } = await response . json ( ) ;
41
44
for ( const node of nodes ) if ( node . mode === "js ") node . mode = "ojs ";
42
- process . stdout . write ( serialize ( toNotebook ( { title, cells : nodes } ) , { document} ) ) ;
45
+ process . stdout . write ( serialize ( toNotebook ( { title, cells : nodes } ) , { document : window . document } ) ) ;
43
46
}
44
47
}
0 commit comments