2017-07-19 15:08:54 -04:00
|
|
|
let _cache = {};
|
|
|
|
|
|
|
|
export function applyInlineOneboxes(inline, ajax) {
|
2018-01-29 16:39:41 -05:00
|
|
|
Object.keys(inline).forEach(url => {
|
|
|
|
// cache a blank locally, so we never trigger a lookup
|
|
|
|
_cache[url] = {};
|
|
|
|
});
|
|
|
|
|
2017-07-19 15:08:54 -04:00
|
|
|
return ajax("/inline-onebox", {
|
2018-06-15 11:03:24 -04:00
|
|
|
data: { urls: Object.keys(inline) }
|
2017-07-19 15:08:54 -04:00
|
|
|
}).then(result => {
|
2018-06-15 11:03:24 -04:00
|
|
|
result["inline-oneboxes"].forEach(onebox => {
|
2017-07-19 15:08:54 -04:00
|
|
|
_cache[onebox.url] = onebox;
|
|
|
|
let links = inline[onebox.url] || [];
|
|
|
|
links.forEach(link => {
|
|
|
|
link.text(onebox.title);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-06-15 11:03:24 -04:00
|
|
|
}
|
2017-07-19 15:08:54 -04:00
|
|
|
|
|
|
|
export function cachedInlineOnebox(url) {
|
|
|
|
return _cache[url];
|
|
|
|
}
|