Add special handling of author and link elements, and a fluffy bunny default tip

Mon, 31 Jan 2011 03:27:53 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 31 Jan 2011 03:27:53 +0100
changeset 6
4afd0e6206b2
parent 5
58d3cecc68b7

Add special handling of author and link elements, and a fluffy bunny

feeds.lua file | annotate | diff | comparison | revisions
--- a/feeds.lua	Mon Dec 06 04:39:22 2010 +0000
+++ b/feeds.lua	Mon Jan 31 03:27:53 2011 +0100
@@ -1,6 +1,8 @@
 local io, string = io, string;
 local error = error;
 local print = print;
+local t_insert = table.insert;
+local ipairs = ipairs;
 
 local http = require "socket.http";
 local st = require "stanza";
@@ -8,6 +10,15 @@
 
 local xmlns_atom = "http://www.w3.org/2005/Atom";
 
+--[[
+By popular request; a fluffy bunny:
+
+ (\ /)
+ (. .)
+c(")(")
+
+--]]
+
 module "feeds"
 
 local translate_entry = {};
@@ -15,6 +26,22 @@
 function translate_entry.atom(feed, stanza)
 	if stanza.name == "entry" then
 		feed[#feed+1] = stanza;
+	elseif stanza.name == "author" then
+		feed.author = {};
+		for i,a in ipairs(stanza) do
+			if a.name and a[1] then
+				feed.author[a.name] = a[1];
+			end
+		end
+	elseif stanza.name == "link" then
+		if not feed.links then feed.links = {}; end
+		if stanza.attr.href then
+			if stanza.attr.rel then
+				feed.links[stanza.attr.rel] = stanza.attr.href;
+			else
+				t_insert(feed.links, stanza.attr.href)
+			end
+		end
 	else
 		feed[stanza.name] = stanza:get_text();
 	end

mercurial