-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
188 lines (164 loc) · 5.96 KB
/
app.js
File metadata and controls
188 lines (164 loc) · 5.96 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
import { escapeHtml, normalize, loadProjects, loadExperience, createChatController, wireChatUI } from "./chat-core.js";
import { initTheme } from "./theme.js";
const $ = (sel) => document.querySelector(sel);
const $$ = (sel) => Array.from(document.querySelectorAll(sel));
initTheme();
const projectsGrid = $("#projectsGrid");
const projectFilter = $("#projectFilter");
const tagBar = $("#tagBar");
let projects = [];
let activeTags = new Set();
function renderTagBar() {
const counts = new Map();
for (const p of projects) {
for (const t of (p.tags || [])) counts.set(t, (counts.get(t) ?? 0) + 1);
}
const top = Array.from(counts.entries())
.sort((a, b) => b[1] - a[1])
.slice(0, 10)
.map(([t]) => t);
tagBar.innerHTML = top
.map((t) => {
const pressed = activeTags.has(t);
return `<button class="tag" type="button" data-tag="${escapeHtml(t)}" aria-pressed="${pressed ? "true" : "false"}">${escapeHtml(t)}</button>`;
})
.join("");
for (const btn of $$("#tagBar .tag")) {
btn.addEventListener("click", () => {
const t = btn.getAttribute("data-tag");
if (!t) return;
if (activeTags.has(t)) activeTags.delete(t);
else activeTags.add(t);
renderTagBar();
renderProjects();
});
}
}
function projectMatchesFilters(p) {
const q = normalize(projectFilter.value);
if (activeTags.size > 0) {
const hasAll = Array.from(activeTags).every((t) => (p.tags || []).includes(t));
if (!hasAll) return false;
}
if (!q) return true;
const blob = normalize(
[
p.title,
p.type,
p.year,
(p.role || []).join(" "),
p.team,
p.problem,
(p.skills || []).join(" "),
(p.tags || []).join(" "),
(p.constraints || []).join(" "),
(p.process || []).join(" "),
(p.impact || []).join(" ")
].join(" ")
);
return blob.includes(q);
}
function renderExperience(data) {
const ol = $("#experienceTimeline");
const resumeLink = $("#resumeDownloadLink");
if (!ol) return;
const entries = Array.isArray(data?.entries) ? data.entries : [];
if (entries.length === 0) {
ol.innerHTML = `<li class="timeline-item"><div class="timeline-content"><p class="muted">No experience entries.</p></div></li>`;
return;
}
ol.innerHTML = entries
.map(
(e) => `
<li class="timeline-item">
<div class="timeline-rail" aria-hidden="true"><div class="timeline-dot"></div></div>
<div class="timeline-content">
<div class="timeline-header">
<img class="timeline-logo" src="${escapeHtml(e.logoSrc)}" alt="${escapeHtml(e.logoAlt)}" />
<div class="timeline-title">
<div class="timeline-role"><strong>${escapeHtml(e.roleTitle)}</strong> — ${escapeHtml(e.company)}</div>
<div class="timeline-company">${escapeHtml(e.datesAndLocation)}</div>
</div>
</div>
<ul class="timeline-bullets">
${(e.bullets || []).map((b) => `<li>${escapeHtml(b)}</li>`).join("")}
</ul>
</div>
</li>`
)
.join("");
if (resumeLink && data?.resumeDownloadHref) {
resumeLink.setAttribute("href", data.resumeDownloadHref);
if (data.resumeDownloadLabel) resumeLink.textContent = data.resumeDownloadLabel;
}
}
function renderProjects() {
const list = projects
.slice()
.sort((a, b) => (b.year || 0) - (a.year || 0))
.filter(projectMatchesFilters);
if (list.length === 0) {
projectsGrid.innerHTML = `<div class="card pad" style="grid-column: 1 / -1;">
<strong>No matches.</strong>
<div style="margin-top:6px;">Try removing a tag filter or searching for “security”, “enterprise”, or “workflows”.</div>
</div>`;
return;
}
projectsGrid.innerHTML = list
.map((p) => {
const tags = (p.tags || []).slice(0, 4).map((t) => `<span class="tag" aria-hidden="true">${escapeHtml(t)}</span>`).join("");
const roles = (p.role || []).slice(0, 2).join(" · ");
const impact = (p.impact && p.impact[0]) ? `Impact: ${escapeHtml(p.impact[0])}` : "Impact: —";
return `
<article class="project" role="button" tabindex="0" data-project-id="${escapeHtml(p.id)}" aria-label="Open ${escapeHtml(p.title)}">
<h3>${escapeHtml(p.title)}</h3>
<div class="meta">
<span class="pill">${escapeHtml(p.type)} • ${escapeHtml(String(p.year))}</span>
<span class="pill">${escapeHtml(roles || "—")}</span>
</div>
<div class="summary">${escapeHtml(p.problem || "")}</div>
<div class="summary" style="margin-top:8px;">${impact}</div>
<div class="tags">${tags}</div>
</article>
`;
})
.join("");
for (const card of $$("#projectsGrid .project")) {
const open = () => {
const id = card.getAttribute("data-project-id");
if (!id) return;
window.location.href = `./project.html?id=${encodeURIComponent(id)}`;
};
card.addEventListener("click", open);
card.addEventListener("keydown", (e) => {
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
open();
}
});
}
}
async function main() {
$("#year").textContent = String(new Date().getFullYear());
try {
const experienceData = await loadExperience();
renderExperience(experienceData);
} catch (err) {
const ol = $("#experienceTimeline");
if (ol) {
ol.innerHTML = `<li class="timeline-item"><div class="timeline-content"><p><strong>Couldn’t load experience.</strong> ${escapeHtml(err?.message || String(err))}</p></div></li>`;
}
}
projects = await loadProjects();
renderTagBar();
renderProjects();
projectFilter.addEventListener("input", renderProjects);
const controller = createChatController({ projects });
wireChatUI({ controller });
}
main().catch((err) => {
projectsGrid.innerHTML = `<div class="card pad" style="grid-column: 1 / -1;">
<strong>Couldn’t load portfolio data.</strong>
<div style="margin-top:6px;">${escapeHtml(err?.message || String(err))}</div>
</div>`;
});