-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.html
More file actions
242 lines (228 loc) · 10.2 KB
/
blog.html
File metadata and controls
242 lines (228 loc) · 10.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Blog - Adit Jain</title>
<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=Inter:wght@300;400;500;600;700&family=Sora:wght@600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/style.css" />
<script>
// MathJax configuration: support $...$ and $$...$$
window.MathJax = {
tex: {
inlineMath: [["$", "$"], ["\\(", "\\)"]],
displayMath: [["$$", "$$"], ["\\[", "\\]"]]
},
options: {
skipHtmlTags: ['script','noscript','style','textarea','pre','code']
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body class="blog-page">
<a class="skip-link" href="#main">Skip to content</a>
<div class='background' id="background" aria-hidden="true"></div>
<header class="site-header">
<div class="nav container">
<a class="brand" href="/index.html">Adit Jain</a>
<button id="menu-toggle" class="btn btn-ghost nav-toggle" aria-controls="primary-nav" aria-expanded="false" aria-label="Toggle navigation">☰</button>
<nav id="primary-nav" class="nav-links" aria-label="Primary">
<a href="/index.html#publications-section">Publications</a>
<a href="/index.html#blog-section">Blog</a>
<a href="/index.html#decks-section">Decks</a>
<a href="/index.html#contact">Contact</a>
<button id="theme-toggle" class="btn btn-ghost" aria-label="Toggle theme">🌙</button>
</nav>
</div>
</header>
<main id="main">
<div id="container" class="container">
<a class="back-link" id="back-link" href="/index.html">← Home</a>
<h2 id="blog-heading" class="section">Blog</h2>
<ul id="post-list" class="blog-list"></ul>
<article id="post-view" class="prose section" hidden>
<h1 id="post-title" class="post-title"></h1>
<div class="post-meta" id="post-date"></div>
<div id="post-content"></div>
</article>
</div>
</main>
<footer id='contact' class="site-footer">
<div class="container">
<div class='contact-group'>
<a aria-label="GitHub" href="https://github.com/aditj"><img width="28" height="28" src="/images/github.svg" alt="Github"></a>
<a aria-label="Email" href="mailto:aditjain1980@gmail.com"><img width="28" height="28" src="/images/mail.png" alt="Email"></a>
<a aria-label="LinkedIn" href="https://www.linkedin.com/in/adit-jain/"><img width="28" height="28" src="/images/linkedin.png" alt="LinkedIn"></a>
</div>
<div class="footer-note">Reach me</div>
</div>
</footer>
<script src="/script.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.2/dist/purify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script>
(function() {
function getSlug() {
var params = new URLSearchParams(window.location.search);
return params.get('slug');
}
function parseFrontMatter(md) {
if (!md.startsWith('---')) return { meta: {}, body: md };
var end = md.indexOf('\n---');
if (end === -1) return { meta: {}, body: md };
var fm = md.slice(3, end).trim();
var body = md.slice(end + 4).trim();
var meta = {};
fm.split(/\r?\n/).forEach(function(line){
var idx = line.indexOf(':');
if (idx === -1) return;
var key = line.slice(0, idx).trim();
var val = line.slice(idx+1).trim();
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
val = val.slice(1, -1);
}
meta[key] = val;
});
return { meta: meta, body: body };
}
function toDateString(d) {
try { return new Date(d).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }); }
catch (e) { return d || ''; }
}
function renderMarkdown(md) {
var html = marked.parse(md, { mangle: false, headerIds: true });
return DOMPurify.sanitize(html);
}
function showList() {
document.getElementById('post-view').hidden = true;
document.getElementById('post-list').hidden = false;
var heading = document.getElementById('blog-heading');
heading.hidden = false;
heading.textContent = 'Blog';
var back = document.getElementById('back-link');
if (back) { back.href = '/index.html'; back.textContent = '← Home'; }
}
function showPost() {
document.getElementById('post-list').hidden = true;
document.getElementById('post-view').hidden = false;
var heading = document.getElementById('blog-heading');
heading.hidden = true;
var back = document.getElementById('back-link');
if (back) { back.href = '/index.html'; back.textContent = '← Home'; }
}
function fetchPost(slug) {
return fetch('/posts/' + encodeURIComponent(slug) + '.md')
.then(function(r){ if(!r.ok) throw new Error('Not found'); return r.text(); })
.then(function(md){ return parseFrontMatter(md); });
}
function stripLeadingTitle(md, title) {
if (!md) return md;
var lines = md.replace(/^\s+/, '').split(/\r?\n/);
if (lines.length === 0) return md;
var first = lines[0].trim();
// Always drop a top-level Markdown H1 to avoid duplicate titles
if (/^#\s+/.test(first)) {
return lines.slice(1).join('\n').replace(/^\n+/, '');
}
return md;
}
function loadPost(slug) {
showPost();
fetchPost(slug).then(function(res){
var title = res.meta.title || slug;
document.title = title + ' - Adit Jain';
document.getElementById('post-title').textContent = title;
document.getElementById('post-date').textContent = toDateString(res.meta.date);
var body = stripLeadingTitle(res.body, title);
var contentEl = document.getElementById('post-content');
contentEl.innerHTML = renderMarkdown(body);
// Mermaid: transform code blocks and render diagrams
try {
if (window.mermaid) {
mermaid.initialize({ startOnLoad: false });
var blocks = contentEl.querySelectorAll('pre code.language-mermaid, code.language-mermaid');
blocks.forEach(function(code){
var pre = code.closest('pre');
var graph = code.textContent;
var div = document.createElement('div');
div.className = 'mermaid';
div.textContent = graph;
if (pre) {
pre.replaceWith(div);
} else {
code.replaceWith(div);
}
});
if (mermaid.run) {
mermaid.run({ querySelector: '#post-content .mermaid' });
} else if (mermaid.init) {
mermaid.init(undefined, contentEl.querySelectorAll('.mermaid'));
}
}
} catch (e) { console.error('Mermaid render failed', e); }
if (window.MathJax && window.MathJax.typesetPromise) {
window.MathJax.typesetPromise([contentEl]).catch(function(err){ console.error('MathJax typeset failed', err); });
}
}).catch(function(){
document.getElementById('post-title').textContent = 'Post not found';
document.getElementById('post-content').textContent = 'Could not load the requested post.';
});
}
function asArrayOfSlugs(data) {
if (!data) return [];
if (Array.isArray(data) && typeof data[0] === 'string') return data;
if (Array.isArray(data) && typeof data[0] === 'object') return data.map(function(p){ return p.slug; });
return [];
}
function loadList() {
showList();
var list = document.getElementById('post-list');
fetch('/data/posts.json')
.then(function(r){ return r.json(); })
.then(function(data){
var slugs = asArrayOfSlugs(data);
var loaders = slugs.map(function(slug){
return fetchPost(slug).then(function(res){ return { slug: slug, meta: res.meta, body: res.body }; })
.catch(function(){ return { slug: slug, meta: {}, body: '' }; });
});
return Promise.all(loaders);
})
.then(function(posts){
// Derive fields from front matter; fallback to slug
posts.sort(function(a,b){ return new Date(b.meta.date||0) - new Date(a.meta.date||0); });
posts.forEach(function(p){
var li = document.createElement('li');
var titleLink = document.createElement('a');
titleLink.href = '/blog.html?slug=' + encodeURIComponent(p.slug);
var titleEl = document.createElement('strong');
titleEl.textContent = p.meta.title || p.slug;
titleLink.appendChild(titleEl);
var meta = document.createElement('div');
meta.className = 'post-meta';
meta.textContent = toDateString(p.meta.date);
var excerpt = document.createElement('div');
excerpt.className = 'post-excerpt';
excerpt.textContent = p.meta.excerpt || (p.body.split(/\n\n/)[0] || '').replace(/[#*_>`]/g, '').slice(0, 180);
li.appendChild(titleLink);
if (meta.textContent) li.appendChild(meta);
if (excerpt.textContent) li.appendChild(excerpt);
list.appendChild(li);
});
})
.catch(function(){
var li = document.createElement('li');
li.textContent = 'No posts available yet.';
list.appendChild(li);
});
}
var slug = getSlug();
if (slug) { loadPost(slug); } else { loadList(); }
})();
</script>
</body>
<!-- End blog.html -->
</html>