forked from ayushHardeniya/ayushhardeniya.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
240 lines (203 loc) · 9.21 KB
/
Copy pathscript.js
File metadata and controls
240 lines (203 loc) · 9.21 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
// Mobile Menu Functionality
document.addEventListener('DOMContentLoaded', function() {
const mobileMenuToggle = document.getElementById('mobile-menu');
const mobileMenuOverlay = document.getElementById('mobile-menu-overlay');
const mobileClose = document.getElementById('mobile-close');
const mobileNavLinks = document.querySelectorAll('.mobile-nav-link, .mobile-nav-sublink');
// Open mobile menu
mobileMenuToggle.addEventListener('click', function() {
mobileMenuOverlay.classList.add('active');
document.body.style.overflow = 'hidden'; // Prevent scrolling
});
// Close mobile menu
function closeMobileMenu() {
mobileMenuOverlay.classList.remove('active');
document.body.style.overflow = 'auto'; // Re-enable scrolling
}
// Close menu when clicking close button
mobileClose.addEventListener('click', closeMobileMenu);
// Close menu when clicking on overlay background
mobileMenuOverlay.addEventListener('click', function(e) {
if (e.target === mobileMenuOverlay) {
closeMobileMenu();
}
});
// Close menu when clicking on nav links
mobileNavLinks.forEach(link => {
link.addEventListener('click', function() {
// Small delay to allow navigation to complete
setTimeout(closeMobileMenu, 100);
});
});
// Close menu on escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && mobileMenuOverlay.classList.contains('active')) {
closeMobileMenu();
}
});
// Handle window resize
window.addEventListener('resize', function() {
if (window.innerWidth > 768 && mobileMenuOverlay.classList.contains('active')) {
closeMobileMenu();
}
});
});
class LifeNotesManager {
constructor() {
this.posts = [];
this.currentIndex = 0;
this.container = document.getElementById('lifenotes-container');
this.loading = document.getElementById('lifenotes-loading');
this.prevBtn = document.getElementById('lifenotes-prev');
this.nextBtn = document.getElementById('lifenotes-next');
this.info = document.getElementById('lifenotes-info');
this.init();
}
async init() {
await this.fetchPosts();
this.setupEventListeners();
}
async fetchPosts() {
try {
const response = await fetch("https://medium-blog-backend-three.vercel.app/medium-feed");
this.posts = await response.json();
if (!Array.isArray(this.posts) || this.posts.length === 0) {
throw new Error("No posts found");
}
this.loading.style.display = "none";
this.renderCurrentPost();
this.updateNavigation();
} catch (error) {
this.loading.innerHTML = "Error loading posts. Please try again later.";
console.error("Error fetching Medium blogs:", error);
}
}
renderCurrentPost() {
if (this.posts.length === 0) return;
const post = this.posts[this.currentIndex];
const title = post.title || "Untitled Post";
const link = post.link || "#";
const pubDate = this.formatDate(post.pubDate || post.published);
const excerpt = this.extractExcerpt(post.content || post.description || "");
const thumbnail = this.extractImage(post.content || post.description || "");
this.container.innerHTML = `
<div class="blog-card">
${thumbnail ? `<img src="${thumbnail}" alt="${title}" class="blog-image" onerror="this.style.display='none'">` : ''}
<h4 class="blog-title">${title}</h4>
<div class="blog-meta">
<span class="blog-date">${pubDate}</span>
</div>
<p class="blog-excerpt">${excerpt}</p>
<a href="${link}" target="_blank" class="read-more">Read on Medium</a>
</div>
`;
}
extractExcerpt(content) {
if (!content) return "Click to read this fascinating life story and discover insights about personal growth, experiences, and reflections.";
// Remove HTML tags and get first 150 characters
const text = content.replace(/<[^>]*>/g, '').trim();
return text.length > 150 ? text.substring(0, 150) + '...' : text;
}
extractImage(content) {
if (!content) return null;
// Try to extract image from content
const imgMatch = content.match(/<img[^>]+src="([^">]+)"/i);
return imgMatch ? imgMatch[1] : null;
}
formatDate(dateString) {
if (!dateString) return "Date not available";
try {
const date = new Date(dateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
} catch {
return "Date not available";
}
}
setupEventListeners() {
this.prevBtn.addEventListener('click', () => this.goToPrevious());
this.nextBtn.addEventListener('click', () => this.goToNext());
// Add keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft') this.goToPrevious();
if (e.key === 'ArrowRight') this.goToNext();
});
}
goToPrevious() {
if (this.currentIndex > 0) {
this.currentIndex--;
this.renderCurrentPost();
this.updateNavigation();
this.addTransitionEffect();
}
}
goToNext() {
if (this.currentIndex < this.posts.length - 1) {
this.currentIndex++;
this.renderCurrentPost();
this.updateNavigation();
this.addTransitionEffect();
}
}
addTransitionEffect() {
const card = this.container.querySelector('.blog-card');
if (card) {
card.style.opacity = '0';
card.style.transform = 'translateY(10px)';
setTimeout(() => {
card.style.transition = 'all 0.3s ease';
card.style.opacity = '1';
card.style.transform = 'translateY(0)';
}, 50);
}
}
updateNavigation() {
this.prevBtn.disabled = this.currentIndex === 0;
this.nextBtn.disabled = this.currentIndex === this.posts.length - 1;
this.info.textContent = `${this.currentIndex + 1} / ${this.posts.length}`;
}
}
// Subscription functions
function subscribeToLifeNotes() {
// Redirect to Medium subscription page
window.open('https://medium.com/@ayushhardeniya/subscribe', '_blank');
}
function subscribeToCodeNotes() {
window.open('https://blog.ayushhardeniya.site/newsletter', '_blank');
}
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
new LifeNotesManager();
});
//form - formspree based forwarding
document.getElementById('contactForm').addEventListener('submit', function(e) {
// Add loading state
const submitBtn = document.querySelector('.submit-btn');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
// Reset after 3 seconds if form doesn't redirect
setTimeout(() => {
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}, 3000);
});
// Simple form validation
const form = document.getElementById('contactForm');
const inputs = form.querySelectorAll('input[required], textarea[required]');
inputs.forEach(input => {
input.addEventListener('blur', function() {
if (!this.value.trim()) {
this.style.borderColor = '#e74c3c';
} else {
this.style.borderColor = '#27ae60';
}
});
});