diff server.js @ 7:7ab6b48122af

Add support for content in Atom and improve published display.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 02 Nov 2011 09:35:46 -0700
parents 29becdd02dea
children 360186772aa3
line wrap: on
line diff
--- a/server.js
+++ b/server.js
@@ -149,7 +149,7 @@ cl.on('stanza', function(stanza) {
 });
 
 var parseAtom = function(atom, id, jid) {
-	var article = new Element('article', {'e:id': id, 'e:date': '2011-06-02T10:59:39Z'});
+	var article = new Element('article', {'e:id': id});
 
 	var avatar = article.c('aside').c('img')
 	article.up();
@@ -183,12 +183,24 @@ var parseAtom = function(atom, id, jid) 
 		footer.up();
 	}
 
-	var published = atom.getChild('published', ns.atom).getText();
-	if (published) {
-		if (author)
-			footer.t(', ');
-		footer.c('time', {datetime: published}).t((new Date).set8601(published).getRelative()).up();
-	}
+	var published = (function() {
+		try {
+			var elem = atom.getChild('published', ns.atom);
+			var iso8601 = elem.getText();
+			var d = (new Date).set8601(iso8601);
+			var relative = d.getRelative();
+
+			return {iso8601: iso8601, relative: relative};
+		} catch (e) {
+			var d = new Date;
+			return {iso8601: d.to8601(), relative: d.getRelative()};
+		}
+	})();
+
+	if (author)
+		footer.t(', ');
+	footer.c('time', {datetime: published.iso8601}).t(published.relative).up();
+	article.attrs['e:date'] = published.iso8601;
 
 	try {
 		var summary = atom.getChild('summary', ns.atom).getText();