How to share comparison of two Observable notebooks

And here’s a handy function to do just that:

function share(identifier, unlisted = true) {
  const [id, rev] = identifier.split('@', 2);
  return fetch(`https://api.observablehq.com/document/${id}/publish`, {
    method: 'POST',
    credentials: 'include',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      token: document.cookie.match(/\bT=([a-f0-9]{32})/)[1],
      version: +rev, unlisted, 
    })
  });
}

Just drop the code in the console, then copy the document ID + version from the URL (ideally while in the history view), and call the function like this:

share("62f151d62ae2dbf1@10")
share("62f151d62ae2dbf1@5")
share("62f151d62ae2dbf1@8")

Each shared revision will then be accessible.

3 Likes