-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.html
More file actions
192 lines (172 loc) · 8.05 KB
/
Copy pathblog.html
File metadata and controls
192 lines (172 loc) · 8.05 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BLOGS</title>
<link rel="icon" type="image/png" href="assets/images/indexbg/pixelboyhead.png">
<meta name="description" content="Blog posts by Tanish Vashisth — dev notes, tutorials, and thoughts on software.">
<link href="https://unpkg.com/nes.css@2.3.0/css/nes.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="assets/css/global.css">
<style>
body {
background-color: black;
background-repeat: repeat;
background-position: top center;
background-attachment: scroll;
background-size: 30% auto;
color: white;
margin: 0;
padding: 0;
min-height: 100vh;
width: 100%;
position: relative;
display: flex;
flex-direction: column;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
.img {
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
image-rendering: pixelated;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 100;
justify-content: center;
align-items: center;
}
.modal-content {
background-color: white;
border-radius: 8px;
padding: 20px;
max-width: 90%;
max-height: 90%;
overflow-y: auto;
}
</style>
</head>
<body>
<header class="w-full">
<nav class="navbar boxxy">
<div class="navbar-desktop items-center justify-between w-full">
<div class="flex items-center space-x-4">
<a class="nav-item" href="blog.html">Blog</a>
<a class="nav-item" href="project.html">Projects</a>
</div>
<a href="/index.html" class="flex items-center justify-center">
<img src="assets/images/indexbg/logo.png" alt="logo" class="h-8 img">
</a>
<div class="flex items-center space-x-4">
<a class="nav-item" href="about.html">About</a>
<a class="nav-item" href="contact.html">Contact</a>
</div>
</div>
<!-- Hamburger menu -->
<div class="md:hidden flex items-center justify-between w-full">
<a href="/index.html" class="flex items-center justify-start">
<img src="assets/images/indexbg/logo.png" alt="logo" class="h-8 img">
</a>
<button id="menu-toggle" class="flex items-center justify-end">
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 6h16M4 12h16m-7 6h7"></path>
</svg>
</button>
</div>
<div id="mobile-menu" class="hidden absolute top-0 right-0 bg-black w-full mt-14 z-50 text-right">
<a class="block py-2 px-4 text-white" href="index.html">Home</a>
<a class="block py-2 px-4 text-white" href="project.html">Projects</a>
<a class="block py-2 px-4 text-white" href="blog.html">Blog</a>
<a class="block py-2 px-4 text-white" href="about.html">About</a>
<a class="block py-2 px-4 text-white" href="contact.html">Contact</a>
</div>
</nav>
</header>
<main class="py-6 mt-14 w-full px-4 sm:px-16 space-y-8 flex-grow" id="blog-container">
<!-- Blog posts will be inserted here -->
</main>
<!-- Pagination Controls -->
<div id="pagination" class="flex items-center justify-evenly md:justify-center my-6">
<button id="prev-page" class="px-2 py-1 bg-gray-700 text-white boxxy h-[30px] text-[12px] md:text-[16px]"
disabled>Previous</button>
<span id="page-info" class="mx-4 text-white align-center md:mx-10 text-[16px]">1</span>
<button id="next-page"
class="px-2 py-1 bg-gray-700 text-white boxxy h-[30px] text-[12px] md:text-[16px]">Next</button>
</div>
<footer class="flex flex-col md:flex-row items-center justify-center bg-gray-950 bg-opacity-50 py-6 w-full mt-10 gap-2 z-50">
<p class="text-white max-[320px]:text-[8px] text-[10px] lg:text-[16px]">Copyright © 2024 --</p>
<a href="mailto:tanishvashisth@gmail.com"
class="text-white max-[320px]:text-[8px] text-[10px] lg:text-[16px] underline">tanishvashisth@gmail.com</a>
</footer>
<script>
let currentPage = 1;
const postsPerPage = 5;
const blogContainer = document.getElementById('blog-container');
const pageInfo = document.getElementById('page-info');
const prevPageButton = document.getElementById('prev-page');
const nextPageButton = document.getElementById('next-page');
function fetchPosts(page = 1) {
fetch(`https://dev.to/api/articles?username=bogusdeck&page=${page}&per_page=${postsPerPage + 1}`)
.then(response => response.json())
.then(data => {
blogContainer.innerHTML = ''; // Clear current posts
if (!data || data.length === 0) {
blogContainer.innerHTML = '<div class="boxxy p-8 mx-4 text-center"><p class="headingfont text-gray-400 text-sm">No posts yet. Check back soon!</p></div>';
document.getElementById('pagination').style.display = 'none';
return;
}
const visiblePosts = data.slice(0, postsPerPage);
const hasNextPage = data.length > postsPerPage;
document.getElementById('pagination').style.display = '';
visiblePosts.forEach(post => {
const blogPost = document.createElement('div');
blogPost.className = 'boxxy mb-6 p-4 mx-4';
blogPost.innerHTML = `
<h2 class="text-xl font-semibold title"><a href="blog-detail.html?id=${post.id}" class="text-blue-500 hover:underline">${post.title}</a></h2>
<p class="text-white-700 mt-2 headingfont">${post.description}</p>
<p class="text-gray-400 mt-2 text-sm"><small>Posted on ${new Date(post.published_at).toDateString()}</small></p>
`;
blogContainer.appendChild(blogPost);
});
pageInfo.textContent = `${currentPage}`;
updatePaginationControls(hasNextPage);
})
.catch(error => console.error('Error fetching blog posts:', error));
}
function updatePaginationControls(hasNextPage) {
prevPageButton.disabled = currentPage <= 1;
nextPageButton.disabled = !hasNextPage;
}
prevPageButton.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
fetchPosts(currentPage);
}
});
nextPageButton.addEventListener('click', () => {
currentPage++;
fetchPosts(currentPage);
});
// Initial fetch
fetchPosts();
document.getElementById('menu-toggle').addEventListener('click', function () {
const menu = document.getElementById('mobile-menu');
menu.classList.toggle('hidden');
});
</script>
</body>
</html>