Published
Edited
Sep 7, 2020
2 stars
Insert cell
Insert cell
// Requires the hexadecimal notebook ID as argument.
function sticky(id) {
const token = document.cookie.match(/(^|; )T=([^;]+)/)[2],
json = response => response.json(),
api = (route, options = {}) => fetch(`https://api.observablehq.com/${route}`, {
mode: 'cors',
credentials: 'include',
...options,
}),
post = (route, data) => api(route, {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({token, ...data}),
}),
republish = () => api(`document/${id}`)
.then(json)
.then(({version}) => post(`document/${id}/unpublish`)
.then(() => post(`document/${id}/publish`, {version}))
);
return api('documents/public')
.then(json)
.then(list => id === list[0].id || republish());
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more