Upload a notebook from the downloaded tgz file?

If we for any reason backed up a notebook by downloading it and removed the same from the observable platform is there a simple way to upload the js file back to create a new notebook later?

1 Like

This isn’t currently supported, no, sorry. The downloaded tarball contains the compiled code rather than the source code of the notebook.

1 Like

The following is related, but is not really “simple” and doesn’t quite do exactly what you want: There are some (unofficial, possibly discouraged, possibly no-longer-working) nodejs scripts in this thread which let you make API calls to api.observablehq.com to download and upload the “notebook JSON file” that the observablehq.com editor uses internally to store the source of notebooks – feel free to post in that thread if you try them out and have issues. (I haven’t looked at this stuff in many months, so it’s possible that my understanding is way out-of-date.)

This is close to what you’re asking for, however, as @mbostock said, the .tgz files contain only the “compiled” version of your notebook and not the original notebook JSON source. So if you only have the .tgz and not the JSON source, then even if the scripts above work, you’re still out of luck for now. In principle the compiled ES modules could be decompiled (I wrote some code which does that for the output of the old v1 version of the runtime here) but this wouldn’t be perfect and you would still lose some information (e.g. the pinned vs unpinned status of each cell).

Possibly also of interest: @asg017’s “Unofficial ObservableHQ Compiler” project can “run” the notebook JSON source files using the Observable runtime (see compile.notebook). Currently this acts more like an “interpreter” than a “compiler” since it has to re-parse the original source on each page refresh. I do hope to add some “source-to-source compilation” functionality there to output ES modules like the export button on observablehq.com does in the near-ish future (see this issue).

Thank you! This is very helpful.