-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.js
23 lines (20 loc) · 902 Bytes
/
blog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const blogHeadings = document.querySelectorAll('.blog-heading');
const blogDates = document.querySelectorAll('.blog-date');
const blogBriefs = document.querySelectorAll('.blog-brief');
const blogHyperlinks = document.querySelectorAll('.blog-hyperlink');
const blogImages = document.querySelectorAll('.blog-image');
const getHashnodeURL = (slug) => {
return `https://adityasaxena.hashnode.dev/${slug}/`
}
const updateUI = (posts) => {
posts.forEach((post, i) => {
blogHeadings[i].textContent = post.title;
blogDates[i].textContent = new Date(post.dateAdded).toDateString();
blogBriefs[i].textContent = post.brief;
blogHyperlinks[i].href = getHashnodeURL(post.slug);
blogImages[i].src = post.coverImage;
})
}
fetch('./blogData.json').then((res) => res.json()).then((data) => {
updateUI(data.posts.filter((post) => post.isActive).reverse());
});