Permalink
Browse files

Capture meta data such as title/subtitle/links etc. Entries are now i…

…n "items".
  • Loading branch information...
1 parent b9c5135 commit b2da1cbcbf968e49f1fadf6c7d03b144c579e84d @eschnou committed Feb 19, 2011
Showing with 31 additions and 5 deletions.
  1. +31 −5 lib/ostatus/atom.js
View
@@ -24,6 +24,7 @@
var Sys = require('sys'),
Url = require('url'),
+ Util = require('util'),
Http = require('./http.js'),
Xml = require('o3-xml');
Path = require('path'),
@@ -50,17 +51,28 @@ function parseFeed(url, callback) {
try {
var doc = Xml.parseFromString(body);
var childNodes = doc.documentElement.childNodes;
- var entries = [];
+ var feed = {};
+ feed.items = [];
+ feed.links = [];
+ feed.url = url;
+ var items = [];
for (var i=0; i<childNodes.length; i++) {
var name = childNodes[i].nodeName;
if (name == "entry") {
var entry = _readEntry(childNodes[i]);
- if (entry != null) {
- entries.push(entry);
- }
+ if (entry) feed.items.push(entry);
+ } else if (name == "link") {
+ var link = _readLink(childNodes[i]);
+ if (link) feed.links.push(link);
+ } else if (name == "title") {
+ feed.title = childNodes[i].nodeValue;
+ } else if (name == "subtitle") {
+ feed.subtitle = childNodes[i].nodeValue;
+ } else if (name == "updated") {
+ feed.updated = childNodes[i].nodeValue;
}
}
- callback(null, entries);
+ callback(null, feed);
} catch (exception) {
callback(exception);
}
@@ -74,6 +86,11 @@ var _elements = {
"updated": _parseUpdated
};
+function _readLink(node) {
+ var link = _readAttributes(node, ["href", "rel", "type"]);
+ return link;
+}
+
function _readEntry(node) {
var childNodes = node.childNodes;
var entry = {};
@@ -86,6 +103,15 @@ function _readEntry(node) {
return entry;
}
+function _readAttributes(node, attributes) {
+ var result = {};
+ for(i= 0; i<attributes.length; i++) {
+ var name = attributes[i];
+ if (attribute = node.attributes.getNamedItem(name)) result[name] = attribute.value;
+ }
+ return result;
+}
+
function _parseTitle(node, entry) {
if (node != null) {
entry["title"] = node.nodeValue;

0 comments on commit b2da1cb

Please sign in to comment.