-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (133 loc) · 4.47 KB
/
script.js
File metadata and controls
155 lines (133 loc) · 4.47 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
const byId = (id) => document.getElementById(id);
const safe = (value) => (value ?? "").toString().trim();
const statusClass = (status) => {
const normalized = safe(status).toLowerCase();
if (normalized === "live") return "status status-live";
return "status status-source";
};
const textToHtml = (text) => {
const element = document.createElement("span");
element.textContent = text;
return element.innerHTML;
};
function renderTags(container, tags) {
container.innerHTML = "";
tags.forEach((tag) => {
const span = document.createElement("span");
span.className = "tag";
span.textContent = tag;
container.appendChild(span);
});
}
function renderProjectCard(project) {
const stackBadges = (project.stack || [])
.slice(0, 8)
.map((tech) => `<span class="tag">${textToHtml(tech)}</span>`)
.join("");
const linkParts = [];
if (project.links?.live) {
linkParts.push(
`<a href="${project.links.live}" target="_blank" rel="noreferrer">Live Demo</a>`
);
}
if (project.links?.repo) {
linkParts.push(
`<a href="${project.links.repo}" target="_blank" rel="noreferrer">GitHub</a>`
);
}
if (project.links?.api) {
linkParts.push(
`<a href="${project.links.api}" target="_blank" rel="noreferrer">API</a>`
);
}
const buildItems = (project.build || [])
.map((item) => `<li>${textToHtml(item)}</li>`)
.join("");
const impactItems = (project.impact || [])
.map((item) => `<li>${textToHtml(item)}</li>`)
.join("");
return `
<article class="project-card">
<div class="project-top">
<h3>${textToHtml(project.name)}</h3>
<span class="${statusClass(project.status)}">${textToHtml(project.status)}</span>
</div>
<p>${textToHtml(project.problem)}</p>
<p class="card-note">${textToHtml(project.stabilityNote)}</p>
<section class="card-section">
<h4>Build</h4>
<ul class="card-list">${buildItems}</ul>
</section>
<section class="card-section">
<h4>Impact</h4>
<ul class="card-list">${impactItems}</ul>
</section>
<div class="stack">${stackBadges}</div>
<div class="card-links">${linkParts.join("")}</div>
</article>
`;
}
function renderExperience(experience) {
return experience
.map((job) => {
const points = (job.highlights || [])
.map((item) => `<li>${textToHtml(item)}</li>`)
.join("");
return `
<article class="experience-item">
<div class="exp-meta">
<strong>${textToHtml(job.company)} - ${textToHtml(job.title)}</strong>
<span>${textToHtml(job.period)}</span>
</div>
<ul class="card-list">${points}</ul>
</article>
`;
})
.join("");
}
function setupRevealAnimation() {
const items = document.querySelectorAll(".reveal");
const observer = new IntersectionObserver(
(entries, obs) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("reveal-visible");
obs.unobserve(entry.target);
}
});
},
{ threshold: 0.12 }
);
items.forEach((item) => observer.observe(item));
}
async function loadPortfolio() {
try {
const response = await fetch("./projects.json", { cache: "no-store" });
if (!response.ok) {
throw new Error("Could not load project data.");
}
const data = await response.json();
const owner = data.owner || {};
byId("hero-name").textContent = safe(owner.name) || "Matthew Robin";
byId("hero-role").textContent = safe(owner.role) || "Full-Stack Web Developer";
byId("hero-summary").textContent = safe(owner.summary);
byId("about-text").textContent = safe(owner.summary);
byId("hero-github").href = safe(owner.github);
byId("hero-email").href = `mailto:${safe(owner.email)}`;
byId("contact-github").href = safe(owner.github);
byId("contact-email").href = `mailto:${safe(owner.email)}`;
renderTags(byId("highlights"), data.technicalHighlights || []);
byId("project-grid").innerHTML = (data.projects || [])
.map(renderProjectCard)
.join("");
byId("experience-list").innerHTML = renderExperience(data.experience || []);
} catch (error) {
byId("project-grid").innerHTML =
'<p>Project data failed to load. Please refresh or check <code>projects.json</code>.</p>';
console.error(error);
} finally {
byId("year").textContent = new Date().getFullYear().toString();
setupRevealAnimation();
}
}
loadPortfolio();