-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
114 lines (105 loc) · 4.09 KB
/
index.html
File metadata and controls
114 lines (105 loc) · 4.09 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Problem Solving Blogs</title>
<link rel="stylesheet" href="css/index-style.css" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css"
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&family=Alegreya+Sans&family=Barlow:ital,wght@1,600&family=Berkshire+Swash&family=Dosis&family=Exo+2:wght@300&family=Josefin+Sans&family=Kanit&family=Lato&family=Poppins:wght@300&family=Roboto+Condensed:wght@300&family=Rubik&family=Staatliches&family=Ubuntu&family=Varela+Round&display=swap"
rel="stylesheet"
/>
</head>
<body>
<nav>
<div>
<div style="display: flex; align-items: center; padding-left: 1.5rem">
<i style="font-size: 3rem" class="fa-brands fa-python"></i>
<h2 style="font-family: outfit; font-weight: 700; padding-left: 1rem">
DSA In Python Blogs
</h2>
</div>
<hr style="height: 1px; background: rgba(0, 0, 0, 0.2)" />
</div>
<a href="bookmarked.html">View Bookmarked Blogs</a>
</nav>
<div class="container"></div>
<footer style="padding: 1rem; display: flex; justify-content: center">
Made with ❤️ By
<a style="margin-left: 0.3rem" href="contributors.html">Contributors</a>
</footer>
<script>
(async () => {
const response = await fetch("blogsList.json");
const BlogList = await response.json();
const bookmarkedBlogs =
JSON.parse(localStorage.getItem("bookmarkedBlogs")) || [];
function isBookmarked(id) {
return bookmarkedBlogs.includes(id);
}
function toggleBookmark(blogId) {
const index = bookmarkedBlogs.indexOf(blogId);
if (index !== -1) {
bookmarkedBlogs.splice(index, 1);
} else {
bookmarkedBlogs.push(blogId);
}
localStorage.setItem(
"bookmarkedBlogs",
JSON.stringify(bookmarkedBlogs)
);
renderBlogs();
}
function updateBookmarkIcon(element, isBookmarked) {
element.classList.toggle("fa-solid", isBookmarked);
element.classList.toggle("fa-regular", !isBookmarked);
}
function renderBlogs() {
const container = document.querySelector(".container");
container.innerHTML = "";
BlogList.forEach((blog) => {
const blogElement = document.createElement("div");
blogElement.className = "container-item";
blogElement.innerHTML = `
<div class="img-wrapper">
<img onclick='window.open("blog.html?blogid=${
blog.id
}","_self")' src="${blog.image}" alt="">
</div>
<h3 onclick='window.open("blog.html?blogid=${
blog.id
}","_self")'>${blog.title}</h3>
<p>${blog.description}</p>
<div>
<button onclick='window.open("blog.html?blogid=${
blog.id
}","_self")'>
<h3>Read more</h3>
<i style="color: gray" class="fa-solid fa-angles-right"></i>
</button>
<button class="bookmark-btn" onclick="toggleBookmark(${blog.id})">
<i class="${
isBookmarked(blog.id) ? "fa-solid" : "fa-regular"
} fa-bookmark"></i>
</button>
</div>
`;
container.appendChild(blogElement);
const bookmarkIcon = blogElement.querySelector(".bookmark-btn i");
bookmarkIcon.onclick = () => {
toggleBookmark(blog.id);
updateBookmarkIcon(bookmarkIcon, isBookmarked(blog.id));
};
});
}
renderBlogs();
})();
</script>
</body>
</html>