ea2dafcd9cb878276fe727913542f5b126d34b6c
[mevemon] / www / js / google-feed.js
1 google.load("feeds", "1");
2
3 function nl2p(text) {
4   text = escape(text);
5   if(text.indexOf('%0D%0A') > -1) {
6     re_nlchar = /%0D%0A/g;
7   } else if (
8     text.indexOf('%0A') > -1) {
9       re_nlchar = /%0A/g ;
10   } else if (
11     text.indexOf('%0D') > -1) {
12     re_nlchar = /%0D/g ;
13   } else { return unescape(text); }
14   return unescape( text.replace(re_nlchar,'</p><p>') );
15 }
16
17 function first_paragraph(ptext) {
18
19   pindex = ptext.indexOf("\n\n");
20   if ( pindex < 100 ) {
21     pindex = ptext.indexOf("\n\n", pindex + 1);
22   }
23
24   paragraph = ptext.slice(0, pindex);
25
26   return paragraph;
27
28 }
29
30 function initialize() {
31   var feed = new google.feeds.Feed("https://garage.maemo.org/export/rss_sfnews.php?group_id=1544");
32   feed.setNumEntries(4);
33   feed.load(function(result) {
34
35   var container = document.getElementById("garage_feed");
36
37   if (!result.error) {
38     for (var i = 0; i < result.feed.entries.length; i++) {
39       var entry = result.feed.entries[i];
40       var div = document.createElement("div");
41       final_content = nl2p(first_paragraph(entry.content));
42       final_content = final_content + " <a href=\"" + entry.link + "\">(Read more)</a>";
43       div.innerHTML = "<p><h3><a href=\"" + entry.link + "\">" + entry.title + "</a></h3></p><p><b>Posted by " + entry.author + " on " + entry.publishedDate  + "</b></p><p></p><p>" + final_content + "</p>";
44       container.appendChild(div);
45     }
46   } else { container.innerHTML = "<p><h3>Error loading news feed.</h3></p>"; }
47   });
48 }
49
50 google.setOnLoadCallback(initialize);