-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
469 lines (432 loc) · 13.6 KB
/
build.js
File metadata and controls
469 lines (432 loc) · 13.6 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkMath from 'remark-math';
import remarkRehype from 'remark-rehype';
import rehypeKatex from 'rehype-katex';
import rehypeHighlight from 'rehype-highlight';
import rehypeStringify from 'rehype-stringify';
const CONTENT_DIR = './content/blog';
const OUTPUT_DIR = './blog';
// HTML template that matches index.html styling
function htmlTemplate({ title, content, isListing = false, description = '' }) {
const pageTitle = isListing ? 'Blog — Vidyoot Senthil' : `${title} — Vidyoot Senthil`;
const metaDescription = description || 'Blog posts by Vidyoot Senthil';
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${pageTitle}</title>
<meta name="description" content="${metaDescription}">
<link rel="icon" href="/public/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg: #faf8f5;
--text: #1f2937;
--text-muted: #6b7280;
--link: #c65d07;
--link-hover: #a04d06;
--border: #e5e2dd;
--code-bg: #f3f0eb;
}
[data-theme="dark"] {
--bg: #1a1815;
--text: #d4d0c8;
--text-muted: #9a958c;
--link: #e8a54b;
--link-hover: #f0b560;
--border: #2d2a24;
--code-bg: #252220;
}
body {
font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
background: var(--bg);
min-height: 100vh;
color: var(--text);
line-height: 1.5;
font-size: 14px;
letter-spacing: -0.01em;
transition: background 0.3s, color 0.3s;
}
a {
color: var(--link);
text-decoration: none;
}
a:hover {
color: var(--link-hover);
text-decoration: underline;
}
.container {
max-width: 900px;
margin: 0 auto;
padding: 40px 24px;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 48px;
padding-bottom: 16px;
border-bottom: 1px solid var(--border);
}
.nav-links {
display: flex;
gap: 24px;
}
.nav-links a {
color: var(--link);
}
.nav-right {
display: flex;
align-items: center;
gap: 16px;
}
.theme-toggle {
background: none;
border: none;
cursor: pointer;
color: var(--link);
padding: 4px;
display: flex;
align-items: center;
justify-content: center;
}
.theme-toggle:hover {
color: var(--link-hover);
}
.theme-toggle svg {
width: 20px;
height: 20px;
}
.sun-icon { display: none; }
.moon-icon { display: block; }
[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
h1 {
font-size: 24px;
font-weight: 600;
margin-bottom: 24px;
color: var(--text);
}
h2 {
font-size: 18px;
font-weight: 600;
margin-top: 32px;
margin-bottom: 16px;
color: var(--text);
}
h3 {
font-size: 16px;
font-weight: 600;
margin-top: 24px;
margin-bottom: 12px;
color: var(--text);
}
/* Blog listing styles */
.post {
margin-bottom: 24px;
padding-bottom: 24px;
border-bottom: 1px solid var(--border);
}
.post:last-child {
border-bottom: none;
}
.post-title {
color: var(--link);
font-weight: 500;
font-size: 16px;
}
.post-date {
color: var(--text-muted);
font-size: 13px;
margin-top: 4px;
}
.post-desc {
color: var(--text-muted);
font-size: 13px;
margin-top: 8px;
}
/* Blog post content styles */
.post-header {
margin-bottom: 32px;
}
.post-header h1 {
margin-bottom: 8px;
}
.post-meta {
color: var(--text-muted);
font-size: 13px;
}
.back-link {
display: inline-block;
margin-bottom: 24px;
font-size: 13px;
}
/* Prose styles for blog content */
.prose p {
margin-bottom: 16px;
line-height: 1.7;
}
.prose ul, .prose ol {
margin-bottom: 16px;
padding-left: 24px;
}
.prose li {
margin-bottom: 8px;
line-height: 1.7;
}
.prose blockquote {
border-left: 3px solid var(--link);
padding-left: 16px;
margin: 16px 0;
color: var(--text-muted);
font-style: italic;
}
.prose img {
max-width: 100%;
height: auto;
margin: 24px 0;
border-radius: 4px;
}
.prose code {
background: var(--code-bg);
padding: 2px 6px;
border-radius: 3px;
font-size: 13px;
}
.prose pre {
background: var(--code-bg);
padding: 16px;
border-radius: 6px;
overflow-x: auto;
margin: 16px 0;
}
.prose pre code {
background: none;
padding: 0;
font-size: 13px;
line-height: 1.5;
}
.prose strong {
font-weight: 600;
}
.prose hr {
border: none;
border-top: 1px solid var(--border);
margin: 32px 0;
}
/* KaTeX overrides */
.katex-display {
margin: 16px 0;
overflow-x: auto;
}
footer {
margin-top: 60px;
padding-top: 24px;
border-top: 1px solid var(--border);
}
.social-links {
display: flex;
gap: 20px;
}
.social-links a {
color: var(--link);
display: flex;
align-items: center;
}
.social-links a:hover {
color: var(--link-hover);
text-decoration: none;
}
.social-links svg {
width: 18px;
height: 18px;
}
@media (max-width: 600px) {
body { font-size: 13px; }
.container { padding: 24px 16px; }
nav { flex-direction: column; gap: 16px; align-items: flex-start; }
.social-links svg { width: 20px; height: 20px; }
}
</style>
</head>
<body>
<div class="container">
<nav>
<div class="nav-links">
<a href="/">home</a>
<a href="/blog">blog</a>
</div>
<div class="nav-right">
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
<svg class="moon-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
</svg>
<svg class="sun-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="5"/>
<line x1="12" y1="1" x2="12" y2="3"/>
<line x1="12" y1="21" x2="12" y2="23"/>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
<line x1="1" y1="12" x2="3" y2="12"/>
<line x1="21" y1="12" x2="23" y2="12"/>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
</svg>
</button>
</div>
</nav>
<main>
${content}
</main>
<footer>
<div class="social-links">
<a href="mailto:vidyoots@gmail.com" title="Email">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M22 6l-10 7L2 6"/></svg>
</a>
<a href="https://github.com/vid277" target="_blank" rel="noopener" title="GitHub">
<svg fill="currentColor" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>
</a>
<a href="https://x.com/vidyoots" target="_blank" rel="noopener" title="X">
<svg fill="currentColor" viewBox="0 0 24 24"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
</a>
<a href="https://linkedin.com/in/vidyootsenthil" target="_blank" rel="noopener" title="LinkedIn">
<svg fill="currentColor" viewBox="0 0 24 24"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>
</a>
</div>
</footer>
</div>
<script>
function toggleTheme() {
const html = document.documentElement;
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
}
// Load saved theme or default to dark
const savedTheme = localStorage.getItem('theme') || 'dark';
if (savedTheme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
</script>
</body>
</html>`;
}
// Process markdown to HTML using unified pipeline
async function processMarkdown(content) {
const result = await unified()
.use(remarkParse)
.use(remarkMath)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeKatex)
.use(rehypeHighlight)
.use(rehypeStringify, { allowDangerousHtml: true })
.process(content);
return String(result);
}
// Read and parse a markdown file
async function readPost(filePath) {
const fileContent = fs.readFileSync(filePath, 'utf-8');
const { data, content } = matter(fileContent);
const htmlContent = await processMarkdown(content);
return {
...data,
content: htmlContent,
slug: data.slug || path.basename(filePath, '.md'),
};
}
// Get all posts sorted by date (newest first)
async function getAllPosts() {
const files = fs.readdirSync(CONTENT_DIR).filter(f => f.endsWith('.md'));
const posts = await Promise.all(
files.map(f => readPost(path.join(CONTENT_DIR, f)))
);
return posts.sort((a, b) => new Date(b.date) - new Date(a.date));
}
// Format date for display
function formatDate(dateStr) {
const date = new Date(dateStr);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
}
// Generate the blog listing page
function generateListingPage(posts) {
const postsHtml = posts.map(post => `
<div class="post">
<a href="/blog/${post.slug}" class="post-title">${post.title}</a>
<div class="post-date">${formatDate(post.date)}</div>
<p class="post-desc">${post.summary}</p>
</div>`).join('\n');
const content = `
<h1>Blog</h1>
${postsHtml}`;
return htmlTemplate({
title: 'Blog',
content,
isListing: true,
description: 'Blog posts by Vidyoot Senthil on software engineering, AI, and more.'
});
}
// Generate an individual post page
function generatePostPage(post) {
const content = `
<a href="/blog" class="back-link">← Back to all posts</a>
<article>
<header class="post-header">
<h1>${post.title}</h1>
<div class="post-meta">${formatDate(post.date)}</div>
</header>
<div class="prose">
${post.content}
</div>
</article>`;
return htmlTemplate({
title: post.title,
content,
description: post.summary
});
}
// Main build function
async function build() {
console.log('Building blog...\n');
// Ensure output directory exists
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
}
// Get all posts
const posts = await getAllPosts();
console.log(`Found ${posts.length} posts:\n`);
// Generate listing page
const listingHtml = generateListingPage(posts);
fs.writeFileSync(path.join(OUTPUT_DIR, 'index.html'), listingHtml);
console.log(' ✓ blog/index.html');
// Generate individual post pages
for (const post of posts) {
const postDir = path.join(OUTPUT_DIR, post.slug);
if (!fs.existsSync(postDir)) {
fs.mkdirSync(postDir, { recursive: true });
}
const postHtml = generatePostPage(post);
fs.writeFileSync(path.join(postDir, 'index.html'), postHtml);
console.log(` ✓ blog/${post.slug}/index.html`);
}
console.log('\nBuild complete!');
}
build().catch(console.error);