-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.js
73 lines (64 loc) · 2.08 KB
/
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
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
const blogPosts = [
{
"id": 1,
"title": "Boost your github knowledge",
"date": "March 19, 2024",
"image": "images/blog1.jpg",
"author": "Mahafuj Ahamed",
"authorImage": "images/mahafuj12.jpeg"
},
{
"id": 2,
"title": "Do you know Web Tecnologies",
"date": "April 5, 2024",
"image": "images/blogweb.jpg",
"author": "sumaiya",
"authorImage": "images/sumaya.jpg"
},
{
"id": 2,
"title": "Programmers Guidline",
"date": "April 5, 2024",
"image": "images/blog/blog-4.jpg",
"author": "Jane Doe",
"authorImage": "images/blog/steve.jpeg"
},
{
"id": 2,
"title": "Programmers Guidline",
"date": "April 5, 2024",
"image": "images/programmerweb.jpg",
"author": "Mr. Amit Chakraborty",
"authorImage": "images/amit.jpeg"
},
{
"id": 3,
"title": "Building a Better Tomorrow",
"date": "April 12, 2024",
"image": "images/blog/blog-4.jpg",
"author": "John Smith",
"authorImage": "images/authors/john.jpg"
}
];
function loadBlogPosts() {
const blogCardContainer = document.getElementById('blog-post-container');
blogPosts.forEach(post => {
const blogCard = document.getElementById('blog-post-template').cloneNode(true);
blogCard.classList.remove('hidden');
blogCard.querySelector('#post-title').textContent = post.title;
blogCard.querySelector('#post-image').src = post.image;
blogCard.querySelector('#post-author').textContent = post.author || "";
const date = new Date(post.date);
const formattedDate = date.toLocaleDateString();
blogCard.querySelector('#post-date').textContent = formattedDate;
const authorImage = document.createElement('img');
authorImage.classList.add('h-10', 'w-10', 'rounded-full', 'object-cover', 'mr-2');
authorImage.src = post.authorImage;
const authorInfo = blogCard.querySelector('.author-info');
if (authorInfo) {
authorInfo.insertBefore(authorImage, authorInfo.firstChild);
}
blogCardContainer.appendChild(blogCard);
});
}
window.addEventListener('DOMContentLoaded', loadBlogPosts);