-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall-blogs.html
More file actions
341 lines (312 loc) · 12.4 KB
/
all-blogs.html
File metadata and controls
341 lines (312 loc) · 12.4 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>All Blog Posts</title>
<link rel="stylesheet" href="style.css">
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$']],
displayMath: [['$$', '$$']]
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<style>
body {
overflow-y: auto;
}
.all-blogs-container {
max-width: 900px;
margin: 100px auto 40px auto;
padding: 30px;
background-color: var(--section-bg);
border-radius: 8px;
color: var(--text-color);
}
.all-blogs-container h1 {
font-size: 2.8em;
margin-bottom: 30px;
text-align: center;
}
.blog-list-item {
background-color: var(--bg-color);
border: 1px solid var(--slider-track-bg);
padding: 20px 25px;
border-radius: 8px;
margin-bottom: 20px;
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.blog-list-item:hover {
transform: translateY(-5px);
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
}
.blog-list-item h3 {
margin-top: 0;
margin-bottom: 8px;
}
.blog-list-item h3 a {
text-decoration: none;
color: var(--text-color);
font-size: 1.6em;
}
.blog-list-item h3 a:hover {
color: #00ffff;
}
.blog-list-item .post-meta {
font-size: 0.85em;
opacity: 0.8;
margin-bottom: 10px;
}
.blog-list-item .post-excerpt {
font-size: 0.95em;
line-height: 1.6;
}
.post-tags {
margin: 10px 0;
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.tag {
background-color: var(--slider-track-bg);
color: var(--text-color);
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8em;
transition: background-color 0.2s ease;
}
.tag:hover {
background-color: var(--slider-thumb-bg);
}
.loading {
text-align: center;
padding: 20px;
font-size: 1.2em;
color: var(--text-color);
opacity: 0.8;
}
.error-message {
background-color: rgba(255, 0, 0, 0.1);
border: 1px solid rgba(255, 0, 0, 0.2);
padding: 20px;
border-radius: 8px;
margin: 20px 0;
color: var(--text-color);
}
.error-message p {
margin: 5px 0;
}
</style>
</head>
<body id="home">
<header>
<a href="index.html#home" class="site-title-link"><div class="site-title">Ematth.dev</div></a>
<nav>
<ul>
<li><a href="index.html#about">About Me</a></li>
<li><a href="index.html#projects">Projects</a></li>
<li><a href="index.html#blog">Blog</a></li>
<li><a href="index.html#resume">Resume/CV</a></li>
</ul>
</nav>
<div id="themeToggle" title="Toggle light/dark mode">☀️</div>
</header>
<div class="all-blogs-container">
<h1>All Blog Posts</h1>
<div id="allBlogsList">
<!-- Blog posts will be dynamically loaded here -->
</div>
</div>
<script>
const themeToggleButton = document.getElementById('themeToggle');
let isLightMode = localStorage.getItem('theme') === 'light';
function applyTheme(isLight) {
document.body.classList.toggle('light-mode', isLight);
themeToggleButton.textContent = isLight ? '☀️' : '🌙';
localStorage.setItem('theme', isLight ? 'light' : 'dark');
}
themeToggleButton.addEventListener('click', () => {
isLightMode = !isLightMode;
applyTheme(isLightMode);
});
applyTheme(isLightMode); // Apply initial theme
async function fetchBlogSlugs() {
try {
console.log('Fetching blog manifest...');
const response = await fetch('blogs/manifest.json');
if (!response.ok) {
throw new Error(`Failed to fetch blog manifest: ${response.statusText}`);
}
const slugs = await response.json();
console.log('Fetched slugs:', slugs);
if (!Array.isArray(slugs)) {
throw new Error('Blog manifest is not a valid array');
}
return slugs;
} catch (error) {
console.error('Error fetching blog manifest:', error);
document.getElementById('allBlogsList').innerHTML = `
<div class="error-message">
<p>Failed to load blog posts. Please try refreshing the page.</p>
<p>Error: ${error.message}</p>
</div>
`;
return [];
}
}
async function fetchBlogData(slug) {
try {
console.log(`Fetching blog data for ${slug}...`);
// Try both possible paths for blog content
const paths = [
`blogs/${slug}/index.md`,
`content/note/${slug}/index.md`
];
let response = null;
let markdown = null;
// Try each path until we find the content
for (const path of paths) {
try {
console.log(`Trying path: ${path}`);
response = await fetch(path);
if (response.ok) {
markdown = await response.text();
console.log(`Successfully loaded content from ${path}`);
break;
}
} catch (e) {
console.warn(`Failed to fetch from ${path}:`, e);
}
}
if (!markdown) {
throw new Error(`Could not find blog content for ${slug}`);
}
const frontmatterMatch = markdown.match(/^---[\s\S]*?---/);
console.log('Frontmatter match:', frontmatterMatch ? 'Found' : 'Not found');
let content = markdown;
let title = slug.replace(/-/g, ' ').split(' ').map(word =>
word.charAt(0).toUpperCase() + word.slice(1)
).join(' ');
let date = 'N/A';
let tags = [];
if (frontmatterMatch) {
const frontmatterText = frontmatterMatch[0];
content = markdown.substring(frontmatterText.length).trim();
// Extract title
const titleMatch = frontmatterText.match(/^title:\s*(.*)$/m);
if (titleMatch && titleMatch[1]) {
title = titleMatch[1].trim().replace(/^["']|["']$/g, '');
console.log('Extracted title:', title);
}
// Extract date
const dateMatch = frontmatterText.match(/^date:\s*(.*)$/m);
if (dateMatch && dateMatch[1]) {
date = dateMatch[1].trim().replace(/^["']|["']$/g, '');
console.log('Extracted date:', date);
}
// Extract tags
const tagsMatch = frontmatterText.match(/^tags:\s*([\s\S]*?)(?:\n\w|$)/m);
if (tagsMatch && tagsMatch[1]) {
tags = tagsMatch[1]
.split('\n')
.map(tag => tag.trim().replace(/^-\s*|["']/g, ''))
.filter(tag => tag);
console.log('Extracted tags:', tags);
}
}
// Generate excerpt
let excerpt = content.split('\n\n')[0];
if (excerpt.startsWith('#')) {
const lines = content.split('\n');
let firstParaIndex = lines.findIndex(line =>
line.trim() !== '' && !line.startsWith('#')
);
excerpt = lines.slice(firstParaIndex).join('\n').split('\n\n')[0] || '';
}
excerpt = excerpt.replace(/^[#\s*]+/gm, '');
if (excerpt.length > 200) {
excerpt = excerpt.substring(0, 200) + '...';
}
if (!excerpt) {
excerpt = "Continue reading...";
}
console.log('Generated excerpt:', excerpt.substring(0, 50) + '...');
return {
slug,
title,
date,
excerpt,
tags,
formattedDate: new Date(date).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
};
} catch (error) {
console.error(`Error processing ${slug}:`, error);
return null;
}
}
document.addEventListener('DOMContentLoaded', async () => {
console.log('DOM Content Loaded - Starting blog load process');
const allBlogsListContainer = document.getElementById('allBlogsList');
if (!allBlogsListContainer) {
console.error('Could not find allBlogsList container');
return;
}
// Show loading state
allBlogsListContainer.innerHTML = '<div class="loading">Loading blog posts...</div>';
const slugs = await fetchBlogSlugs();
console.log('Fetched slugs:', slugs);
if (slugs.length === 0) {
allBlogsListContainer.innerHTML = '<p>No blog posts yet... check back soon!</p>';
return;
}
const allPostsData = [];
for (const slug of slugs) {
console.log(`Processing blog: ${slug}`);
const postData = await fetchBlogData(slug);
if (postData) {
console.log(`Successfully processed blog: ${slug}`);
allPostsData.push(postData);
} else {
console.warn(`Failed to process blog: ${slug}`);
}
}
console.log('All posts data:', allPostsData);
// Sort by date, most recent first
allPostsData.sort((a, b) => new Date(b.date) - new Date(a.date));
if (allPostsData.length === 0) {
allBlogsListContainer.innerHTML = '<p>No blog posts available.</p>';
return;
}
let listHTML = '';
for (const post of allPostsData) {
const tagsHTML = post.tags.length > 0
? `<div class="post-tags">${post.tags.map(tag =>
`<span class="tag">${tag}</span>`
).join('')}</div>`
: '';
listHTML += `
<div class="blog-list-item">
<h3><a href="blog-post.html?post=${post.slug}">${post.title}</a></h3>
<p class="post-meta">Published on: ${post.formattedDate}</p>
${tagsHTML}
<p class="post-excerpt">${post.excerpt}</p>
</div>
`;
}
allBlogsListContainer.innerHTML = listHTML;
// Re-render math with MathJax
if (window.MathJax) {
MathJax.typesetPromise([allBlogsListContainer]).catch((err) => console.log(err.message));
}
console.log('Blog list rendering complete');
});
</script>
</body>
</html>