|
1 | 1 | let s:save_cpo = &cpo |
2 | 2 | set cpo&vim |
3 | 3 |
|
| 4 | +function! s:attr(node, name) |
| 5 | + let n = a:node.childNode(a:name) |
| 6 | + if empty(n) |
| 7 | + return "" |
| 8 | + endif |
| 9 | + return n.value() |
| 10 | +endfunction |
| 11 | + |
4 | 12 | function! webapi#feed#parseURL(url) |
5 | | - let dom = webapi#xml#parse(webapi#http#get(a:url).content) |
| 13 | + let dom = webapi#xml#parseURL(a:url) |
6 | 14 | let items = [] |
7 | 15 | if dom.name == 'rss' |
8 | 16 | let channel = dom.childNode('channel') |
9 | 17 | for item in channel.childNodes('item') |
10 | 18 | call add(items, { |
11 | | - \ "title": item.childNode('title').value(), |
12 | | - \ "link": item.childNode('link').value(), |
13 | | - \ "content": item.childNode('description').value(), |
14 | | - \ "id": item.childNode('guid').value(), |
15 | | - \ "date": item.childNode('pubDate').value(), |
| 19 | + \ "title": s:attr(item, 'title'), |
| 20 | + \ "link": s:attr(item, 'link'), |
| 21 | + \ "content": s:attr(item, 'description'), |
| 22 | + \ "id": s:attr(item, 'guid'), |
| 23 | + \ "date": s:attr(item, 'pubDate'), |
16 | 24 | \}) |
17 | 25 | endfor |
18 | 26 | elseif dom.name == 'rdf:RDF' |
19 | 27 | for item in dom.childNodes('item') |
20 | 28 | call add(items, { |
21 | | - \ "title": item.childNode('title').value(), |
22 | | - \ "link": item.childNode('link').value(), |
23 | | - \ "content": item.childNode('description').value(), |
24 | | - \ "id": item.childNode('link').value(), |
25 | | - \ "date": item.childNode('dc:date').value(), |
| 29 | + \ "title": s:attr(item, 'title'), |
| 30 | + \ "link": s:attr(item, 'link'), |
| 31 | + \ "content": : s:attr(item, 'description'), |
| 32 | + \ "id": s:attr(item, 'guid'), |
| 33 | + \ "date": s:attr(item, 'dc:date'), |
26 | 34 | \}) |
27 | 35 | endfor |
28 | 36 | elseif dom.name == 'feed' |
29 | 37 | for item in dom.childNodes('entry') |
30 | 38 | call add(items, { |
31 | | - \ "title": item.childNode('title').value(), |
| 39 | + \ "title": s:attr(item, 'title'), |
32 | 40 | \ "link": item.childNode('link').attr['href'], |
33 | | - \ "content": item.childNode('content').value(), |
34 | | - \ "id": item.childNode('id').value(), |
35 | | - \ "date": item.childNode('updated').value(), |
| 41 | + \ "content": s:attr(item, 'content'), |
| 42 | + \ "id": s:attr(item, 'id'), |
| 43 | + \ "date": s:attr(item, 'update'), |
36 | 44 | \}) |
37 | 45 | endfor |
38 | 46 | endif |
|
0 commit comments