-
Notifications
You must be signed in to change notification settings - Fork 7
/
feed.html
97 lines (73 loc) · 3.07 KB
/
feed.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<a href="http://www.startupstorm.org"><h3 class="display-4 text-center">StartupStorm</h3></a>
<h4 class="display-5 text-center">RSS FEED AGGREGATOR</h4>
<p id="feed"></p>
<script>
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
// parse student blogs
var text;
httpGetAsync('https://cdn.rawgit.com/startupstorm/student-blogs/eca2270b/blogs.opml', function(response) {
text = response;
var parser, xmlDoc;
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
var url;
var url_list = [];
var num_urls = (xmlDoc).getElementsByTagName("body").length;
// parse URLs of blogs
for (i = 0; i < num_urls; i++) {
url = (xmlDoc).getElementsByTagName("body")[i].getElementsByTagName("outline")[0].getAttribute("xmlUrl");
url_list.push(url);
}
// for each blog URL
for (i = 0; i < url_list.length; i++){
httpGetAsync(url_list[i], function(response) {
// console.log(response);
parser = new DOMParser();
xmlDoc = parser.parseFromString(response,"text/xml");
var blog_title = Array.prototype.slice.call((xmlDoc).getElementsByTagName("title"))[0].innerHTML;
var num_posts = (xmlDoc).getElementsByTagName("channel").length;
post_list = [];
var post = " ";
console.log(blog_title);
// parse posts from blog
while (post) {
var post = (xmlDoc).getElementsByTagName("item");
try {
post_list.push(post);
console.log(post);
(xmlDoc).removeChild(post);
} catch (e) {
post = null;
}
}
//convert post_list to an array from HTML collection
post_list = Array.prototype.slice.call(post_list)[0];
// render posts to page
for (i = 0; i < post_list.length; i++){
var current_post = post_list[i];
var post_title = current_post.getElementsByTagName("title")[0].childNodes[0].textContent;
var post_link = current_post.getElementsByTagName("link")[0].childNodes[0].textContent;
var post_description = current_post.getElementsByTagName("description")[0].childNodes[0].textContent;
document.getElementById('feed').insertAdjacentHTML('beforeend', '<center><div class="card text-center" style="max-width: 50rem;"><h5 class="card-header">'+blog_title+'</h5><div class="card-body"><h4 class="card-title">'+'<a href="' + post_link + '">'+ post_title + '</a>'+'</h4><p class="card-text">'+post_description+'</p>'+'<a class="btn btn-primary" href="' + post_link + '">Read Post</a>'+'</div></div></center>')
}
});
}
});
</script>
</body>
</html>