forked from yuhui-zh15/Minimal-Academic-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
321 lines (269 loc) · 9.09 KB
/
scripts.js
File metadata and controls
321 lines (269 loc) · 9.09 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
// Global variables
let allPublications = [];
const HIGHLIGHT_AUTHOR = 'Jiaxiong Tang';
// Initialize the page
document.addEventListener('DOMContentLoaded', function() {
refreshStaticImage('profile-image');
loadLastUpdated();
// Load publications data
loadPublications();
// Initialize animation delays for sections
const sections = document.querySelectorAll('section');
sections.forEach((section, index) => {
section.style.animationDelay = `${index * 0.1}s`;
});
});
function refreshStaticImage(imageId) {
const image = document.getElementById(imageId);
if (!image) {
return;
}
const src = image.getAttribute('src');
if (!src) {
return;
}
const separator = src.includes('?') ? '&' : '?';
image.src = `${src}${separator}v=${Date.now()}`;
}
function loadLastUpdated() {
const lastUpdatedElement = document.getElementById('last-updated');
if (!lastUpdatedElement) {
return;
}
const repo = lastUpdatedElement.dataset.githubRepo;
if (!repo) {
return;
}
const apiUrl = `https://api.github.com/repos/${repo}/commits?per_page=1`;
fetch(apiUrl, {
cache: 'no-store',
headers: {
Accept: 'application/vnd.github+json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`GitHub API request failed: ${response.status}`);
}
return response.json();
})
.then(commits => {
if (!Array.isArray(commits) || commits.length === 0) {
throw new Error('No commits returned from GitHub API.');
}
const latestCommit = commits[0];
const commitDate = latestCommit.commit && latestCommit.commit.committer
? latestCommit.commit.committer.date
: null;
if (!commitDate) {
throw new Error('Latest commit did not include a committer date.');
}
const formattedDate = formatMonthYear(commitDate);
lastUpdatedElement.textContent = formattedDate;
lastUpdatedElement.dateTime = new Date(commitDate).toISOString();
lastUpdatedElement.title = `Latest commit: ${formatLongDate(commitDate)}`;
})
.catch(error => {
console.warn('Unable to update last updated footer from GitHub:', error);
const fallbackLabel = lastUpdatedElement.dataset.fallbackLabel;
if (fallbackLabel) {
lastUpdatedElement.textContent = fallbackLabel;
}
});
}
function formatMonthYear(dateString) {
return new Intl.DateTimeFormat('en-US', {
month: 'long',
year: 'numeric',
timeZone: 'UTC'
}).format(new Date(dateString));
}
function formatLongDate(dateString) {
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
timeZone: 'UTC'
}).format(new Date(dateString));
}
// Load publications from JSON file
function loadPublications() {
fetch('publications.json', { cache: 'no-store' })
.then(response => {
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.status}`);
}
return response.json();
})
.then(data => {
if (!data || !Array.isArray(data.publications)) {
throw new Error('Invalid publications.json format: expected a publications array.');
}
console.log("Publications loaded successfully:", data);
allPublications = data.publications;
renderPublications();
})
.catch(error => {
console.error('Error loading publications:', error);
displayFallbackPublications(error);
});
}
// Fallback if JSON loading fails
function displayFallbackPublications(error) {
const container = document.getElementById('publications-container');
const message = error && error.message ? error.message : 'Unknown error';
container.textContent = `Error loading publications: ${message}`;
}
// Render all publications
function renderPublications() {
const publicationsContainer = document.getElementById('publications-container');
publicationsContainer.innerHTML = '';
if (allPublications.length === 0) {
publicationsContainer.textContent = 'No publications to display.';
return;
}
allPublications.forEach(publication => {
const pubElement = createPublicationElement(publication, {
showThumbnail: true
});
publicationsContainer.appendChild(pubElement);
});
}
// Create HTML element for a publication
function createPublicationElement(publication, options = {}) {
const { showThumbnail = true } = options;
const pubItem = document.createElement('div');
pubItem.className = 'publication-item';
// Create content container
const content = document.createElement('div');
content.className = 'pub-content';
// Add title
const title = document.createElement('div');
title.className = 'pub-title';
title.textContent = publication.title;
content.appendChild(title);
// Add authors with highlight
const authors = document.createElement('div');
authors.className = 'pub-authors';
// Format authors with highlighting
let authorsHTML = '';
publication.authors.forEach((author, index) => {
authorsHTML += formatAuthor(author);
if (index < publication.authors.length - 1) {
authorsHTML += ', ';
}
});
authors.innerHTML = authorsHTML;
content.appendChild(authors);
// Add venue with award if present
const venueContainer = document.createElement('div');
venueContainer.className = 'pub-venue-container';
const venue = document.createElement('div');
venue.className = 'pub-venue';
venue.textContent = publication.venue;
venueContainer.appendChild(venue);
// Add award if it exists
if (publication.award && publication.award.length > 0) {
const award = document.createElement('div');
award.className = 'pub-award';
award.textContent = publication.award;
venueContainer.appendChild(award);
}
content.appendChild(venueContainer);
// Add links and publication date if they exist
if (publication.links || publication.published) {
const metaRow = document.createElement('div');
metaRow.className = 'pub-meta-row';
const links = document.createElement('div');
links.className = 'pub-links';
if (publication.links && publication.links.pdf) {
const pdfLink = document.createElement('a');
pdfLink.href = publication.links.pdf;
pdfLink.textContent = '[PDF]';
pdfLink.target = '_blank';
pdfLink.rel = 'noopener noreferrer';
links.appendChild(pdfLink);
}
if (publication.links && publication.links.code) {
const codeLink = document.createElement('a');
codeLink.href = publication.links.code;
codeLink.textContent = '[Code]';
codeLink.target = '_blank';
codeLink.rel = 'noopener noreferrer';
links.appendChild(codeLink);
}
if (publication.links && publication.links.project) {
const projectLink = document.createElement('a');
projectLink.href = publication.links.project;
projectLink.textContent = '[Project Page]';
projectLink.target = '_blank';
projectLink.rel = 'noopener noreferrer';
links.appendChild(projectLink);
}
metaRow.appendChild(links);
if (publication.published) {
const published = document.createElement('div');
published.className = 'pub-published';
published.textContent = publication.published;
metaRow.appendChild(published);
}
content.appendChild(metaRow);
}
// Assemble the publication item
if (showThumbnail && publication.thumbnail) {
const thumbnail = createThumbnailElement(publication);
pubItem.appendChild(thumbnail);
}
pubItem.appendChild(content);
return pubItem;
}
function createThumbnailElement(publication) {
const thumbnail = document.createElement('div');
thumbnail.className = 'pub-thumbnail';
thumbnail.onclick = () => openModal(publication.thumbnail);
const thumbnailImg = document.createElement('img');
thumbnailImg.src = publication.thumbnail;
thumbnailImg.alt = `${publication.title} thumbnail`;
thumbnail.appendChild(thumbnailImg);
return thumbnail;
}
function formatAuthor(author) {
const escapedAuthor = escapeHtml(author);
const authorWithMarker = escapedAuthor.replace(/\u2020/g, '<sup class="author-marker">†</sup>');
if (author.includes(HIGHLIGHT_AUTHOR)) {
return `<span class="highlight-name">${authorWithMarker}</span>`;
}
return authorWithMarker;
}
function escapeHtml(text) {
return text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
// Modal functionality for viewing original images
function openModal(imageSrc) {
const modal = document.getElementById('imageModal');
const modalImg = document.getElementById('modalImage');
modal.style.display = "block";
setTimeout(() => {
modal.classList.add('show');
}, 10);
modalImg.src = imageSrc;
}
function closeModal() {
const modal = document.getElementById('imageModal');
modal.classList.remove('show');
setTimeout(() => {
modal.style.display = "none";
}, 300);
}
// Close modal when clicking outside the image
window.onclick = function(event) {
const modal = document.getElementById('imageModal');
if (event.target == modal) {
closeModal();
}
}