diff --git a/index.js b/index.js index c431780..9f9a460 100644 --- a/index.js +++ b/index.js @@ -14,11 +14,17 @@ app.get('/api/feed',function(req,res){ res.status(400); res.send('You need to specify a feed URL'); } - + var opts = {}; - + if (req.query.size){ + opts.size = req.query.size; + } + if (req.query.theme){ + opts.theme = req.query.theme; + } + var req = request.get(feedUrl); - convert(req,{},function(er,data){ + convert(req,opts,function(er,data){ if (er){ res.status(500); res.send('error fetching or parsing feed'); @@ -26,7 +32,7 @@ app.get('/api/feed',function(req,res){ res.status(200); res.send(data); }); - + }); app.listen(process.env.PORT || 8000,function(){ diff --git a/lib/convert.js b/lib/convert.js index 59ddb5e..bd52236 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -10,16 +10,16 @@ module.exports = function(stream,opts,callback){ var callback = callback; var opts = opts; if (typeof opts == 'function'){ - callback = opts; - opts = {}; + callback = opts; + opts = {}; } - + // convert s from atom feed to a full html page for rendering breakDown(stream,function(er,data){ if (er) { return callback(er); } - callback(null,buildUp(data)); + callback(null,buildUp(data,opts)); }); } @@ -40,7 +40,7 @@ function breakDown(stream,callback){ feedparser.on('error', cbOnce); stream.pipe(feedparser) - + feedparser.items = []; feedparser.on('readable', function () { // This is where the action is! @@ -54,64 +54,67 @@ function breakDown(stream,callback){ }); - + feedparser.on('end',function(er){cbOnce(null,feedparser)}); } // hydrate the json to html -function buildUp(jsonObj){ - +function buildUp(jsonObj,opts){ + + // assign opts to the obj + jsonObj.opts = opts||{}; + // add some links to the item for avatar et cetera jsonObj.items.forEach(function(item){ - + // get date item.stringDate = isoDateToEnglish(item.date); - + item.content = getH(item,'atom:content'); - + // get enclosures item.enclosures = []; - + if (item["activity:object"] && item["activity:object"].link){ item["activity:object"].link.forEach(function(link){ if (!link['@']){return;} // avoid keyerror var rel = link['@'].rel; - var href = link['@'].href; + var href = link['@'].href; if (rel == 'enclosure'){ item.enclosures.push(href); - } + } }); } - + // get author info - + item.author = {}; var _author = item.meta['atom:author']; if ( item['activity:object'] && item['activity:object'].author){ _author = item['activity:object'].author; } - + // item.author.name = _author.name.# or empty string item.author.name = getH(_author,'name'); item.author.uri = getH(_author,'uri'); item.author.fullName = getH(_author,'email'); item.author.displayName = getH(_author,'poco:displayname'); - + var authorLinks = _author.link || []; authorLinks.forEach(function(link){ if (!link['@']){return;} // avoid keyerror var rel = link['@'].rel; - var href = link['@'].href; + var href = link['@'].href; if (rel == 'avatar'){ item.author.avatar = href; }else if(rel == 'alternate'){ item.author.alternate = href; } }); - + }); - + return template(jsonObj); } @@ -127,10 +130,10 @@ function isoDateToEnglish(d){ if (typeof d == 'object'){ d = d.toISOString(); } - + var dt = d.split(/[t\-]/ig); var months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; - + return months[Number(dt[1])-1] +' '+dt[2]+ ', '+dt[0]; -} \ No newline at end of file +} diff --git a/lib/template.ejs b/lib/template.ejs index 93ec647..e548af2 100644 --- a/lib/template.ejs +++ b/lib/template.ejs @@ -2,7 +2,20 @@
+ + <% if (opts.theme && opts.theme.toLowerCase() == 'light'){ %> + + <% } else { %> + <% } %> + + <% if (opts.size){ %> + + <% } %>