-
Notifications
You must be signed in to change notification settings - Fork 3
/
rss.js
69 lines (58 loc) · 1.2 KB
/
rss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function feed(data,format){
if(format == "atom" || !format)
return atom_feed(data);
}
function tag(key, value){
return '<'+key+'>\n'+value+'\n</'+key+'>\n'
}
function a_tag(name, data){
var ignore = ["innerHTML"];
var ret = ""
ret += '<'+name+ ' '
forEach( data.keys,
function(key){
if(ignore.indexOf(key) >= 0)
ret += key + '="' + data[key] +'" ';
}
)
ret += '>' + data.innerHTML + '</' + name + '>\n';
return ret;
}
function atom_feed(data){
var feed = ""
var props = ['title','subtitle','id','updated']
feed += atom_head();
props.forEach(
function(key){
var value;
if(value = data[key]) {
feed += tag(key,value)
}
}
)
var links
if(links = data.links){
forEach(links,
function(link){
feed += a_tag('link',link);
}
)
}
var entries;
if(entries = data.entries){
forEach(entries,
function(entrie){
feed += entrie.to_atom();
}
)
}
feed += atom_close()
return feed;
}
function atom_head(){
return '<?xml version="1.0" encoding="utf-8"?>\n'+
'<feed xmlns="http://www.w3.org/2005/Atom">\n'
}
function atom_close(){
return '</feed>\n'
}