From 09a09eb65da0648ce9ff073e9e6bab518b1dd4b4 Mon Sep 17 00:00:00 2001 From: fenwick67 Date: Mon, 1 May 2017 23:08:23 -0500 Subject: [PATCH] embed images / vids from local TL --- lib/convert.js | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index ddeaa24..4dcbeb2 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -75,7 +75,6 @@ function buildUp(jsonObj,opts){ // assign opts to the obj jsonObj.opts = opts||{}; - console.log(opts); // iterate through the items jsonObj.items = jsonObj.items.filter(function(item){ @@ -94,29 +93,40 @@ function buildUp(jsonObj,opts){ // get enclosures item.enclosures = []; - if (item["activity:object"] && item["activity:object"].link){ - - var links = item["activity:object"].link; + function findEnclosure(link){ + if (!link['@']){return;} // avoid keyerror + 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'){ links = [links]; }else if (!isArray(links)){ - links = [];// not an object or array. + links = []; } + links.forEach(findEnclosure); + } - links.forEach(function (link){ - if (!link['@']){return;} // avoid keyerror - var rel = link['@'].rel; - var href = link['@'].href; - if (rel == 'enclosure'){ - item.enclosures.push({ - url:href, - type:link['@'].type||'' - }); - } - }); + // find them in activity:object + if (item["activity:object"] && item["activity:object"].link){ + var enclosureLinks = item["activity:object"].link; + if (!isArray(enclosureLinks) && typeof enclosureLinks == 'object'){ + enclosureLinks = [enclosureLinks]; + }else if (!isArray(enclosureLinks)){ + enclosureLinks = [];// not an object or array. + } + enclosureLinks.forEach(findEnclosure); + } - } // get author info @@ -136,7 +146,7 @@ function buildUp(jsonObj,opts){ if (!isArray(authorLinks) && typeof authorLinks == 'object'){ authorLinks = [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