-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatePosts.js
47 lines (38 loc) · 1.59 KB
/
updatePosts.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
window.updatePosts = async function updatePosts() {
let container = document.querySelector(".post-container");
container.innerHTML = `<h2>Loading Data!</h2>`;
let posts = await updatePostData();
let postSection = "";
posts.forEach((post) => {
let postEntry = `<div class="post-entry entry">
<h2 class="post-title name">${post.title}</h2>
<p class="post-author author">by ${post.author}</p>
<p class="post-published light-text">${post.published}</p>
<p class="post-content">${post.content}</p>
</div>`;
postSection += postEntry;
});
container.innerHTML = postSection;
};
async function updatePostData() {
let feedUrl = "https://miteprod.vercel.app/feed.xml";
let feedData = [];
let postIndex = 0;
await $.get(feedUrl, function (data) {
$(data)
.find("entry")
.each(function () {
let item = $(this);
let published = new Date(item.find("published").text())
feedData[postIndex] = {
"title": item.find("title").text(),
"author": item.find("author").text(),
"content": item.find("content").text(),
"published": published.getFullYear() + "/" + published.getMonth() + "/" + published.getDate()
};
postIndex++;
});
});
console.log(feedData);
return feedData;
}