Published unlisted
Edited
Aug 3, 2021
Insert cell
Insert cell
Insert cell
feeds = deploy("default", async (req, res) => {
res.header("Content-Type", "application/feed+json");
// A little caching prevents DoS risk:
if (req.url.slice(1) === 'recent') {
// Cache the recent firehose for 1 minute.
res.header('Cache-Control', 'public, max-age=60, s-maxage=60');
} else {
// Cache other feeds for 10 minutes.
res.header('Cache-Control', 'public, max-age=600, s-maxage=600');
}

// View in https://observablehq.com/@endpointservices/logs:
// console.log("feed_url: request", JSON.stringify(req));
var content = await notebook_feed(req.url.slice(1));
if (!content) {
return res.status(404).send("Try /recent or /@<name>");
}
return res.send(JSON.stringify(content, null, 2));
});
Insert cell
js = deploy("js", async (req, res) => {
res.header("Content-Type", "text/javascript");

// cache for 1 hour
res.header('Cache-Control', 'public, max-age=3600, s-maxage=3600');
return res.send(
`var thumbnail = document.getElementById('thumbnail'),
embed = document.getElementById('embed');
thumbnail.onclick = function () {
thumbnail.style.display = 'none';
embed.style.display = 'block';
embed.setAttribute('src', embed.dataset.src);
};`)

});
Insert cell
feed_item = (n) => ({
id: n.id,
date_published: n.publish_time,
date_modified: n.update_time,
title: n.title,
content_html: `<img id=thumbnail src="https://static.observableusercontent.com/thumbnail/${n.thumbnail}.jpg"></img><iframe id=embed width="100%" frameborder=0 style="height: 90vh; display: none;" data-src="https://observablehq.com/embed/@${n.owner.login}/${n.slug}?cell=*"></iframe><script src="https://endpointservice.web.app/notebooks/@jrus/feed/deploys/js"></script>`,
image: `https://static.observableusercontent.com/thumbnail/${n.thumbnail}.jpg`,
url: `https://observablehq.com/@${n.owner.login}/${n.slug}`,
author: {
name: n.creator.name || n.creator.login,
url: `https://observablehq.com/@${n.creator.login}`,
avatar: n.creator.avatar_url
}
})
Insert cell
fetch_json_pages = async function (list) {
}
Insert cell
fetch_notebooks = async function (source) {
// get most recent 60 notebooks.
var url = `https://api.observablehq.com/documents/${source}`;
var results = await Promise.all([
fetch(url + '?page=1'),
fetch(url + '?page=2'),
fetch(url + '?page=3'),
fetch(url + '?page=4'),
fetch(url + '?page=5'),
fetch(url + '?page=6'),
fetch(url + '?page=7'),
fetch(url + '?page=8'),
fetch(url + '?page=9'),
]);
return (await Promise.all(results.map(x => x.json())))
.map(x => x.results).flat().filter(x=>x);
};
Insert cell
notebook_feed = async function (source) {
var observable_favicon = "https://static.observablehq.com/favicon-512.0667824687f99c942a02e06e2db1a060911da0bf3606671676a255b1cf97b4fe.png";
if (source === 'recent') { // all public notebooks
source = 'public';
var notebooks = await fetch_notebooks(source);
return ({
version: "https://jsonfeed.org/version/1",
title: "Recent Notebooks / Observable",
description: "The firehose of all published notebooks at https://observablehq.com/",
home_page_url: "https://observablehq.com/recent",
feed_url: "https://endpointservice.web.app/notebooks/@jrus/feed/deployments/feeds/recent",
favicon: observable_favicon,
icon: observable_favicon,
items: notebooks.map(feed_item)
});
} else if (source[0] == '@') { // feed for one author or team
var login = source.slice(1);
var notebooks = await fetch_notebooks(source);
var authors = Object.fromEntries([
...notebooks.map((n) => [n.creator.login, n.creator]),
...notebooks.map((n) => [n.owner.login, n.owner]),
])
if (login in authors) {
var author = authors[login];
return ({
version: "https://jsonfeed.org/version/1",
title: `${author.name || login} / Observable`,
description: `${author.bio}`,
home_page_url: `http://observablehq.com/@${login}`,
feed_url: `https://endpointservice.web.app/notebooks/@jrus/feed/deployments/feeds/@${login}`,
favicon: author.avatar_url,
icon: author.avatar_url,
items: notebooks.map(feed_item)
});
} else {
return ({
version: "https://jsonfeed.org/version/1",
title: `${login} / Observable`,
home_page_url: `http://observablehq.com/@${login}`,
feed_url: `https://endpointservice.web.app/notebooks/@jrus/feed/deployments/feeds/@${login}`,
favicon: observable_favicon,
icon: observable_favicon,
items: notebooks.map(feed_item)
});
}
}
}
Insert cell
Insert cell
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