Published
Edited
Jun 16, 2021
Importers
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
datasetCard('5b7ffc618b4c4169d30727e0')
Insert cell
Insert cell
organizationCard('etalab')
Insert cell
Insert cell
reuseCard('geozones')
Insert cell
Insert cell
datasetCard = (id) => getDiv(id, 'dataset')
Insert cell
reuseCard = (id) => getDiv(id, 'reuse')
Insert cell
organizationCard = (id) => getDiv(id, 'organization')
Insert cell
getDiv = function(id, type){

let div = document.createElement('div')
oembed(id, type).then(oembed =>{
div.innerHTML = oembed.html
})
return div
}
Insert cell
// This is mostly legacy. It works tho 🤷‍♂️
oembed = {
const BASE_URL = 'https://www.data.gouv.fr'
const OEMBED_URL = `${BASE_URL}/api/1/oembed`;
const ATTRS = ['dataset', 'reuse']
const LANG = document.documentElement.lang;
/**
* `fetch` doesn't provide an error handling based on status code.
*/
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
const error = new Error(response.statusText);
error.response = response;
throw error;
}
}
/**
* Return a promisified JSON response from an API URL
* if status code is correct.
*/
function fetchOEmbed(url) {
return fetch(`${OEMBED_URL}?url=${encodeURIComponent(url)}`)
.then(checkStatus)
.then(response => response.json());
}
/**
* Transform a string to title case
*/
function toTitle(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
function createOEmbed(id, type){
return fetchOEmbed(`${BASE_URL}/${LANG}/${type}s/${id}/`)
}
return createOEmbed
}
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