-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog-detail.html
More file actions
264 lines (235 loc) · 9.86 KB
/
Copy pathblog-detail.html
File metadata and controls
264 lines (235 loc) · 9.86 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog Detail</title>
<link rel="icon" type="image/png" href="assets/images/indexbg/pixelboyhead.png">
<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;
}
.blog-content p {
margin-bottom: 1rem;
}
.blog-content ul,
.blog-content ol {
margin-left: 2rem;
margin-bottom: 1rem;
}
.blog-content ul li,
.blog-content ol li {
margin-bottom: 0.5rem;
}
.blog-content h1 {
font-size: 1.6rem;
margin-bottom: 1rem;
}
.blog-content h2 {
font-size: 1.3rem;
margin-bottom: 1rem;
}
.blog-content h3 {
font-size: 1.1rem;
margin-bottom: 1rem;
}
.blog-content h4 {
font-size: 0.9rem;
margin-bottom: 1rem;
}
.blog-content h5 {
font-size: 0.7rem;
margin-bottom: 1rem;
}
.blog-content h6 {
font-size: 0.5rem;
margin-bottom: 1rem;
}
.blog-content code {
font-family: 'Proggy', monospace;
background-color: #333;
color: #f8f8f2;
padding: 0.2em 0.4em;
border-radius: 3px;
}
.blog-content pre {
font-family: 'Proggy', monospace;
background-color: #2e2e2e;
color: #f8f8f2;
padding: 1em;
border-radius: 3px;
overflow-x: auto;
}
.blog-content pre code {
display: block;
white-space: pre-wrap;
word-wrap: break-word;
}
</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-detail-container"></main>
<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>
const blogDetailContainer = document.getElementById('blog-detail-container');
const urlParams = new URLSearchParams(window.location.search);
const postId = urlParams.get('id');
function fetchPostDetail(id) {
fetch(`https://dev.to/api/articles/${id}`)
.then(response => response.json())
.then(post => {
blogDetailContainer.innerHTML = `
<div class="boxxy p-4 mx-4 relative">
<!-- Dev.to external link icon -->
<a href="${post.url}" target="_blank" rel="noopener noreferrer" class="absolute top-4 right-4 hover:opacity-75 transition-opacity duration-200" title="View original post on Dev.to">
<img src="assets/images/logo/dev_logo.png" alt="Dev.to" class="w-12 h-12 img boxxy">
</a>
<img src="${post.cover_image}" alt="Banner Image" class="img w-8/12 h-auto mb-4 mx-auto block">
<h1 class="text-lg md:text-xl lg:text-2xl font-bold text-center pr-12">${post.title}</h1>
<p class="text-gray-400 mt-2 text-sm text-center"><small>Posted on ${new Date(post.published_at).toDateString()}</small></p>
<div class="blog-content mt-4 textfont text-[12px]">
${post.body_html}
</div>
</div>
`;
addResponsiveClasses();
addResponsiveCodeClasses();
})
.catch(error => console.error('Error fetching blog post detail:', error));
}
function addResponsiveCodeClasses() {
const blogContent = document.querySelector('.blog-content');
const codes = blogContent.querySelectorAll('code');
const pres = blogContent.querySelectorAll('pre');
codes.forEach(code => {
code.classList.add('text-[16px]', 'md:text-[20px]', 'lg:text-[25px]', 'codefont');
});
pres.forEach(pre => {
pre.classList.add('text-[16px]', 'md:text-[20px]', 'lg:text-[25px]', 'codefont');
});
}
function addResponsiveClasses() {
const blogContent = document.querySelector('.blog-content');
const headings = blogContent.querySelectorAll('h1, h2, h3, h4, h5, h6');
headings.forEach(heading => {
switch (heading.tagName.toLowerCase()) {
case 'h1':
heading.classList.add('text-lg', 'md:text-xl', 'lg:text-2xl', 'headingfont');
break;
case 'h2':
heading.classList.add('text-lg', 'md:text-xl', 'lg:text-2xl', 'headingfont');
break;
case 'h3':
heading.classList.add('text-md', 'md:text-lg', 'lg:text-xl', 'headingfont');
break;
case 'h4':
heading.classList.add('text-sm', 'md:text-md', 'lg:text-lg', 'headingfont');
break;
case 'h5':
heading.classList.add('text-xs', 'md:text-sm', 'lg:text-md', 'headingfont');
break;
case 'h6':
heading.classList.add('text-xs', 'md:text-xs', 'lg:text-sm', 'headingfont');
break;
}
});
}
if (postId) {
fetchPostDetail(postId);
} else {
blogDetailContainer.innerHTML = '<p class="text-center">Post not found.</p>';
}
document.getElementById('menu-toggle').addEventListener('click', () => {
const mobileMenu = document.getElementById('mobile-menu');
mobileMenu.classList.toggle('hidden');
});
</script>
</body>
</html>