embed images / vids from local TL

This commit is contained in:
fenwick67 2017-05-01 23:08:23 -05:00
parent 54dc7a5be0
commit 09a09eb65d
1 changed files with 28 additions and 18 deletions

View File

@ -75,7 +75,6 @@ function buildUp(jsonObj,opts){
// assign opts to the obj // assign opts to the obj
jsonObj.opts = opts||{}; jsonObj.opts = opts||{};
console.log(opts);
// iterate through the items // iterate through the items
jsonObj.items = jsonObj.items.filter(function(item){ jsonObj.items = jsonObj.items.filter(function(item){
@ -94,29 +93,40 @@ function buildUp(jsonObj,opts){
// get enclosures // get enclosures
item.enclosures = []; item.enclosures = [];
if (item["activity:object"] && item["activity:object"].link){ function findEnclosure(link){
if (!link['@']){return;} // avoid keyerror
var links = item["activity:object"].link; var rel = link['@'].rel;
var href = link['@'].href;
if (rel == 'enclosure'){
item.enclosures.push({
url:href,
type:link['@'].type||''
});
}
}
// find them in the item's links
if (item['atom:link']){
var links = item['atom:link'];
if (!isArray(links) && typeof links == 'object'){ if (!isArray(links) && typeof links == 'object'){
links = [links]; links = [links];
}else if (!isArray(links)){ }else if (!isArray(links)){
links = [];// not an object or array. links = [];
} }
links.forEach(findEnclosure);
}
links.forEach(function (link){ // find them in activity:object
if (!link['@']){return;} // avoid keyerror if (item["activity:object"] && item["activity:object"].link){
var rel = link['@'].rel; var enclosureLinks = item["activity:object"].link;
var href = link['@'].href; if (!isArray(enclosureLinks) && typeof enclosureLinks == 'object'){
if (rel == 'enclosure'){ enclosureLinks = [enclosureLinks];
item.enclosures.push({ }else if (!isArray(enclosureLinks)){
url:href, enclosureLinks = [];// not an object or array.
type:link['@'].type||'' }
}); enclosureLinks.forEach(findEnclosure);
} }
});
}
// get author info // get author info
@ -136,7 +146,7 @@ function buildUp(jsonObj,opts){
if (!isArray(authorLinks) && typeof authorLinks == 'object'){ if (!isArray(authorLinks) && typeof authorLinks == 'object'){
authorLinks = [authorLinks]; authorLinks = [authorLinks];
}else if ( !isArray(authorLinks) ){ }else if ( !isArray(authorLinks) ){
authorLinks = [];// not an object or string. WTF? authorLinks = [];// not an object or string.
} }
authorLinks.forEach(function(link){// todo: guard against authorLinks not being an array authorLinks.forEach(function(link){// todo: guard against authorLinks not being an array