Skip to content

Commit dcac184

Browse files
committed
extract a couple globals
1 parent e0cf738 commit dcac184

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

bin/download.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {JSDOM} from "jsdom";
55
import {toNotebook} from "../src/lib/notebook.js";
66
import {serialize} from "../src/lib/serialize.js";
77

8+
const UI_ORIGIN = "https://observablehq.com";
9+
const API_ORIGIN = "https://api.observablehq.com";
10+
811
if (process.argv[1] === import.meta.filename) run();
912

1013
export default async function run(args?: string[]) {
@@ -29,16 +32,16 @@ export default async function run(args?: string[]) {
2932
return;
3033
}
3134

32-
const document = new JSDOM().window.document;
35+
const {window} = new JSDOM();
3336
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);
3740
}
3841
const response = await fetch(url);
3942
if (!response.ok) throw new Error(`unable to fetch: ${url}`);
4043
const {title, nodes} = await response.json();
4144
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}));
4346
}
4447
}

0 commit comments

Comments
 (0)