-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
338 lines (316 loc) · 14.6 KB
/
Copy pathscript.js
File metadata and controls
338 lines (316 loc) · 14.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
(function () {
"use strict";
/* ----------------------------------------------------------- helpers */
function boldToHtml(text) {
if (!text || typeof text !== "string") return "";
return escapeHtml(text).replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
}
function escapeHtml(text) {
if (text == null) return "";
return String(text)
.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")
.replace(/"/g, """).replace(/'/g, "'");
}
function el(id) { return document.getElementById(id); }
function setText(id, text) { var n = el(id); if (n && text != null) n.textContent = text; }
function setHtml(id, html) { var n = el(id); if (n && html != null) n.innerHTML = html; }
function relAttrs(external) { return external ? ' target="_blank" rel="noopener"' : ""; }
/* ----------------------------------------------------------- nav */
function renderNav(data) {
var ul = el("nav-list");
if (ul && Array.isArray(data.nav)) {
ul.innerHTML = data.nav
.map(function (n) { return '<li><a href="' + escapeHtml(n.href) + '">' + escapeHtml(n.label) + "</a></li>"; })
.join("");
}
var logo = el("logo-text");
if (logo && data.site && data.site.logoText) logo.textContent = data.site.logoText;
}
/* ----------------------------------------------------------- hero */
function renderHero(data) {
var h = data.hero || {};
if (h.kicker) setHtml("hero-kicker", boldToHtml(h.kicker));
if (h.headline) setHtml("hero-headline", boldToHtml(h.headline));
if (h.subtitle) setHtml("hero-subtitle", boldToHtml(h.subtitle));
var photo = el("hero-photo");
if (photo) {
if (h.photo) { photo.src = h.photo; photo.alt = h.photoAlt || "Profile"; }
photo.onerror = function () { var w = photo.closest(".hero-photo-wrap"); if (w) w.style.display = "none"; };
}
var actions = el("hero-actions");
if (actions) {
var btns = "";
if (h.primaryCta) btns += linkBtn(h.primaryCta, "primary", true);
if (h.secondaryCta) btns += linkBtn(h.secondaryCta, "secondary", false);
actions.innerHTML = btns;
}
var status = el("hero-status");
if (status && h.statusPill) {
status.innerHTML = '<span class="pulse" aria-hidden="true"></span>' + escapeHtml(h.statusPill);
}
var stats = el("hero-stats");
if (stats && Array.isArray(h.stats)) {
stats.innerHTML = h.stats.map(function (s) {
return '<div><dt class="count" data-count="' + escapeHtml(s.value) + '">' +
escapeHtml(s.value) + "</dt><dd>" + escapeHtml(s.label) + "</dd></div>";
}).join("");
}
}
/* ----------------------------------------------------------- count-up numbers */
function animateCount(node) {
var full = node.getAttribute("data-count") || node.textContent;
var m = String(full).match(/^(\D*)(\d+(?:\.\d+)?)(.*)$/);
if (!m || window.matchMedia("(prefers-reduced-motion: reduce)").matches) { node.textContent = full; return; }
var prefix = m[1], target = parseFloat(m[2]), suffix = m[3];
var decimals = (m[2].split(".")[1] || "").length;
var start = null, dur = 1100;
function step(ts) {
if (start === null) start = ts;
var p = Math.min((ts - start) / dur, 1);
var eased = 1 - Math.pow(1 - p, 3); // easeOutCubic
var val = (target * eased).toFixed(decimals);
node.textContent = prefix + val + suffix;
if (p < 1) requestAnimationFrame(step);
else node.textContent = full;
}
requestAnimationFrame(step);
}
function linkBtn(cta, cls, arrow) {
return '<a class="btn ' + cls + '" href="' + escapeHtml(cta.href) + '"' + relAttrs(cta.external) + ">" +
escapeHtml(cta.label) + (arrow ? ' <span class="arrow" aria-hidden="true">→</span>' : "") + "</a>";
}
/* ----------------------------------------------------------- trust bar */
function renderTrust(data) {
var t = data.trustBar || {};
setText("trust-label", t.label);
var ul = el("trust-list");
if (ul && Array.isArray(t.items)) {
ul.innerHTML = t.items.map(function (item) {
var inner;
if (t.useLogos && item.logo) {
inner = '<img class="trust-logo" src="' + escapeHtml(item.logo) + '" alt="' + escapeHtml(item.name) + '" loading="lazy" />';
} else {
inner = escapeHtml(item.name);
}
if (item.url) inner = '<a href="' + escapeHtml(item.url) + '" target="_blank" rel="noopener">' + inner + "</a>";
return "<li>" + inner + "</li>";
}).join("");
}
}
/* ----------------------------------------------------------- services */
function renderServices(data) {
var s = data.services || {};
setText("services-eyebrow", s.eyebrow);
setText("services-title", s.title);
setText("services-subtitle", s.subtitle);
var grid = el("services-grid");
if (grid && Array.isArray(s.items)) {
grid.innerHTML = s.items.map(function (item, i) {
var pts = (item.points || []).map(function (p) { return "<li>" + escapeHtml(p) + "</li>"; }).join("");
return '<article class="service-card reveal">' +
'<span class="service-num" aria-hidden="true">' + (i + 1) + "</span>" +
"<h3>" + escapeHtml(item.title) + "</h3>" +
"<p>" + escapeHtml(item.description) + "</p>" +
"<ul>" + pts + "</ul></article>";
}).join("");
}
}
/* ----------------------------------------------------------- work */
function renderWork(data) {
var w = data.work || {};
setText("work-eyebrow", w.eyebrow);
setText("work-title", w.title);
setText("work-subtitle", w.subtitle);
var list = el("work-list");
if (list && Array.isArray(w.items)) {
list.innerHTML = w.items.map(function (item) {
var tech = (item.tech || []).map(function (x) { return "<span>" + escapeHtml(x) + "</span>"; }).join("");
var detail = "";
if (item.challenge) detail += '<p class="work-detail"><span class="lead">Challenge</span>' + escapeHtml(item.challenge) + "</p>";
if (item.approach) detail += '<p class="work-detail"><span class="lead">Approach</span>' + escapeHtml(item.approach) + "</p>";
if (item.outcome) detail += '<p class="work-detail"><span class="lead">Outcome</span><strong>' + escapeHtml(item.outcome) + "</strong></p>";
var link = item.link
? '<a class="work-link" href="' + escapeHtml(item.link) + '" target="_blank" rel="noopener">' +
escapeHtml(item.linkLabel || "Learn more") + ' <span class="arrow" aria-hidden="true">→</span></a>'
: "";
return '<article class="work-card reveal">' +
'<div class="work-metric">' +
'<span class="work-tag">' + escapeHtml(item.tag) + "</span>" +
'<div class="work-metric-value count" data-count="' + escapeHtml(item.metric) + '">' + escapeHtml(item.metric) + "</div>" +
'<p class="work-metric-label">' + escapeHtml(item.metricLabel) + "</p>" +
"</div>" +
'<div class="work-body"><h3>' + escapeHtml(item.title) + "</h3>" +
detail +
'<div class="work-tech">' + tech + "</div>" + link +
"</div></article>";
}).join("");
}
}
/* ----------------------------------------------------------- about */
function renderAbout(data) {
var a = data.about || {};
setText("about-eyebrow", a.eyebrow);
setText("about-title", a.title);
var p = el("about-paragraphs");
if (p && Array.isArray(a.paragraphs)) {
p.innerHTML = a.paragraphs.map(function (x) { return "<p>" + boldToHtml(x) + "</p>"; }).join("");
}
var creds = el("about-credentials");
if (creds && Array.isArray(a.credentials)) {
creds.innerHTML = a.credentials.map(function (c) { return "<li>" + escapeHtml(c) + "</li>"; }).join("");
}
var hl = el("about-highlights");
if (hl && Array.isArray(a.highlights)) {
hl.innerHTML = a.highlights.map(function (h) {
return '<li><span class="h-label">' + escapeHtml(h.label) + '</span><span class="h-value">' + escapeHtml(h.value) + "</span></li>";
}).join("");
}
var exp = el("about-experience");
if (exp && Array.isArray(a.experience)) {
exp.innerHTML = a.experience.map(function (e) {
return "<li><span class=\"exp-role\">" + escapeHtml(e.role) + "</span> " +
'<span class="exp-org">· ' + escapeHtml(e.org) + "</span>" +
'<span class="exp-period">' + escapeHtml(e.period) + "</span>" +
'<p class="exp-summary">' + escapeHtml(e.summary) + "</p></li>";
}).join("");
}
}
/* ----------------------------------------------------------- skills */
function renderSkills(data) {
var s = data.skills || {};
setText("skills-eyebrow", s.eyebrow);
setText("skills-title", s.title);
setText("skills-subtitle", s.subtitle);
var grid = el("skills-grid");
if (grid && Array.isArray(s.categories)) {
grid.innerHTML = s.categories.map(function (c) {
var tags = (c.items || []).map(function (x) { return "<span>" + escapeHtml(x) + "</span>"; }).join("");
return '<div class="skill-card"><h3>' + escapeHtml(c.title) + '</h3><div class="skill-tags">' + tags + "</div></div>";
}).join("");
}
}
/* ----------------------------------------------------------- writing */
function renderWriting(data) {
var w = data.writing || {};
setText("writing-eyebrow", w.eyebrow);
setText("writing-title", w.title);
setText("writing-subtitle", w.subtitle);
var body = el("writing-body");
if (!body) return;
if (Array.isArray(w.items) && w.items.length) {
body.innerHTML = '<div class="writing-grid">' + w.items.map(function (post) {
return '<a class="writing-card" href="' + escapeHtml(post.url) + '" target="_blank" rel="noopener">' +
"<h3>" + escapeHtml(post.title) + "</h3>" +
(post.summary ? "<p>" + escapeHtml(post.summary) + "</p>" : "") + "</a>";
}).join("") + "</div>";
} else {
body.innerHTML = '<div class="writing-empty"><p>I write about ERP, scaling, and engineering on Medium.</p>' +
'<a class="btn primary" href="' + escapeHtml(w.profileUrl) + '" target="_blank" rel="noopener">' +
escapeHtml(w.profileLabel || "Read on Medium") + ' <span class="arrow" aria-hidden="true">→</span></a></div>';
}
}
/* ----------------------------------------------------------- contact */
function renderContact(data) {
var c = data.contact || {};
setText("contact-eyebrow", c.eyebrow);
setText("contact-title", c.title);
setText("contact-subtitle", c.subtitle);
var actions = el("contact-actions");
if (actions) {
var btns = "";
if (c.primaryCta) btns += linkBtn(c.primaryCta, "primary", false);
if (c.secondaryCta) btns += linkBtn(c.secondaryCta, "secondary", false);
actions.innerHTML = btns;
}
var meta = el("contact-meta");
if (meta) {
var rows = [];
if (c.location) rows.push("<li>" + escapeHtml(c.location) + "</li>");
if (c.email) rows.push('<li><a href="mailto:' + escapeHtml(c.email) + '">' + escapeHtml(c.email) + "</a></li>");
if (c.phone) rows.push('<li><a href="tel:' + escapeHtml(c.phoneHref || c.phone) + '">' + escapeHtml(c.phone) + "</a></li>");
meta.innerHTML = rows.join("");
}
var links = el("contact-links");
if (links && Array.isArray(c.links)) {
links.innerHTML = c.links.map(function (l) {
return '<a href="' + escapeHtml(l.href) + '"' + relAttrs(l.external) + ">" + escapeHtml(l.label) + "</a>";
}).join("");
}
}
/* ----------------------------------------------------------- footer */
function renderFooter(data) {
var y = el("year"); if (y) y.textContent = new Date().getFullYear();
if (data.footer) { setText("footer-copy", data.footer.copy); setText("footer-secondary", data.footer.secondary); }
}
/* ----------------------------------------------------------- chrome: nav, scroll, reveal */
function wireChrome() {
var header = el("site-header");
var progress = el("scroll-progress");
var onScroll = function () {
if (header) header.classList.toggle("scrolled", window.scrollY > 8);
if (progress) {
var h = document.documentElement;
var max = h.scrollHeight - h.clientHeight;
progress.style.transform = "scaleX(" + (max > 0 ? window.scrollY / max : 0) + ")";
}
};
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
// count-up numbers when they scroll into view
var counts = document.querySelectorAll(".count");
if ("IntersectionObserver" in window) {
var co = new IntersectionObserver(function (entries) {
entries.forEach(function (en) { if (en.isIntersecting) { animateCount(en.target); co.unobserve(en.target); } });
}, { threshold: 0.6 });
counts.forEach(function (n) { co.observe(n); });
} else {
counts.forEach(animateCount);
}
var toggle = document.querySelector(".nav-toggle");
var list = el("nav-list");
if (toggle && list) {
toggle.addEventListener("click", function () {
var open = list.classList.toggle("open");
toggle.setAttribute("aria-expanded", String(open));
});
list.addEventListener("click", function (e) {
if (e.target.closest("a")) { list.classList.remove("open"); toggle.setAttribute("aria-expanded", "false"); }
});
}
if ("IntersectionObserver" in window && !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (en) { if (en.isIntersecting) { en.target.classList.add("in"); io.unobserve(en.target); } });
}, { threshold: 0.12 });
// observe after content renders
requestAnimationFrame(function () {
document.querySelectorAll(".reveal").forEach(function (n) { io.observe(n); });
});
} else {
document.querySelectorAll(".reveal").forEach(function (n) { n.classList.add("in"); });
}
}
/* ----------------------------------------------------------- boot */
function render(data) {
renderNav(data);
renderHero(data);
renderTrust(data);
renderServices(data);
renderWork(data);
renderAbout(data);
renderSkills(data);
renderWriting(data);
renderContact(data);
renderFooter(data);
wireChrome();
}
document.addEventListener("DOMContentLoaded", function () {
fetch("content.json", { cache: "no-cache" })
.then(function (r) { if (!r.ok) throw new Error("HTTP " + r.status); return r.json(); })
.then(render)
.catch(function (err) {
console.error("Failed to load content.json:", err);
// The static HTML hero remains visible as a graceful fallback.
wireChrome();
});
});
})();