-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
320 lines (290 loc) · 9.96 KB
/
build.js
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
function markdown2html(file, id) {
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(file);
var html = writer.render(parsed);
var element = document.getElementById(id);
var div = document.createElement("div");
div.style = "text-align:justify";
div.innerHTML = html;
element.appendChild(div)
// alert(html) //< causes popup showing generated html
}
function make_students_callback(myjson) {
// console.log(JSON.stringify(myjson, null, 2)); //< show file on debug console
var people = myjson["current"];
// var imax = (news_showall==true) ? mynews.length : news_max_items;
var students_list = document.getElementById('students_list');
for (var i = 0; i < people.length; i++) {
var person = people[i];
// console.log(person);
var person_li = document.createElement('li');
person_li.innerHTML = "<a href='" + person["homepage"] + "'>" + person["name"] + "</a>" +
" – " + person["degree"] + " @ " + person["currently"]
if (!(person["coadvisors"] === undefined)){
person_li.innerHTML += " – co-advised with: " + person["coadvisors"];
}
students_list.appendChild(person_li);
}
}
function make_students() {
jQuery.getJSON("/people.json", make_students_callback)
.fail(function () { console.error("file not found / JSON syntax incorrect"); });
}
function make_alumni_callback(myjson) {
// console.log(JSON.stringify(myjson, null, 2)); //< show file on debug console
var people = myjson["alumni"];
// var imax = (news_showall==true) ? mynews.length : news_max_items;
var alumni_list = document.getElementById('alumni_list');
for (var i = 0; i < people.length; i++) {
var person = people[i];
var person_li = document.createElement('li');
person_li.innerHTML = "<a href='" + person["homepage"] + "'>" + person["name"] + "</a>" +
" – " + person["degree"] + " (" + person["time"] + ") " +
"co-advised with: " + person["coadvisors"] +
" – currently " + person["currently"];
alumni_list.appendChild(person_li);
}
}
function make_alumni() {
jQuery.getJSON("/people.json", make_alumni_callback)
.fail(function () { console.error("file not found / JSON syntax incorrect"); });
}
function make_footer() {
var text = document.createElement('span');
var dt = new Date();
text.innerHTML = "Copyright " + dt.getFullYear() + " – Andrea Tagliasacchi";
document.getElementById("footer").appendChild(text);
}
//Check if file exists
function IfUrlExists(url, callback) {
var http = new XMLHttpRequest();
http.open('HEAD', url, true);
http.onreadystatechange = function (event) {
if (http.status != 404) {
callback();
}
};
http.send();
}
function make_pub(entry) {
// Ensure this author is required (specify somewhere `var filter_for_author = "Tagliasacchi"`)
// console.log( entry["author"] + pAuthor + entry["author"].indexOf(pAuthor) );
// if( entry["author"].indexOf(filter_for_author) == -1 )
// return;
var pub = document.createElement('div');
pub.setAttribute('id', entry['key']);
pub.className = 'publication';
document.getElementById('pubs_list').appendChild(pub);
var pub_content = document.createElement('div');
pub_content.className = 'publication_content';
pub.appendChild(pub_content);
var pub_info = document.createElement('div');
pub_info.className = 'publication_information';
if (entry["icon"] != undefined && entry["icon"].endsWith(".mov")) {
var video = document.createElement('video');
video.className = 'publication_image';
video.setAttribute('loop', '');
video.setAttribute('preload', '');
video.setAttribute('muted', '');
var source = document.createElement('source');
source.setAttribute('src', entry["icon"]);
source.setAttribute('type', "video/mp4");
video.appendChild(source);
pub.addEventListener("mouseover", function () { video.play(); });
pub.addEventListener("mouseleave", function () { video.pause(); });
// --- alternative: strategies to autoplay
// video.setAttribute('playsinline', '');
// video.setAttribute('autoplay', '');
// video.addEventListener("canplaythrough", function () { this.play(); }, false);
pub_content.appendChild(video);
pub_content.appendChild(pub_info);
}
else {
var image = document.createElement('div');
image.className = 'publication_image';
var img = document.createElement('img');
icon = entry["icon"] == undefined ? "/images/placeholder.jpg" : entry["icon"];
img.setAttribute('src', icon)
img.setAttribute('height', '100%');
image.appendChild(img);
pub_content.appendChild(image);
pub_content.appendChild(pub_info);
}
// --- Title + Special
var title = document.createElement('div');
title.className = 'publication_title';
special = entry["special"];
if (special != undefined)
title.innerHTML = entry['title'] + ' — <reddish>' + special;
else
title.innerHTML = entry['title'];
pub_info.appendChild(title);
// Authors
var authors = document.createElement('div');
authors.className = 'publication_authors';
authors.innerHTML = entry["authors"].toString().replace(/,/g, ", ");
pub_info.appendChild(authors);
// Venue
if (entry["venue"] != undefined) {
var venue = document.createElement('div');
venue.className = 'publication_venue';
venue.innerHTML = entry["venue"];
pub_info.appendChild(venue);
}
// Links
var links = document.createElement('ul');
links.className = 'publication_links';
pub_info.appendChild(links);
{
// PDF
if (entry["pdf"] != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = entry["pdf"];
a.target = "New"
a.innerHTML = "pdf"
li.appendChild(a);
links.insertBefore(li, links.firstChild);
}
// arXiv
if (entry["arxiv"] != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = entry["arxiv"];
a.target = "New"
a.innerHTML = "arxiv"
li.appendChild(a);
links.appendChild(li);
}
// --- Bibtex
blacklist = ["key", "special", "source", "slides", "video", "datasets", "pdf", "homepage", "icon", "type", "media"];
var bibtex_text = "@" + entry['type'] + "{" + entry['key'];
for (var tag_name in entry) {
if (entry.hasOwnProperty(tag_name) && !blacklist.includes(tag_name)) {
value = entry[tag_name]
if (tag_name == "authors")
value = value.toString().replace(/,/g, " and ");
bibtex_text += ",\n " + tag_name + "={" + value + "}";
}
}
bibtex_text += "\n}";
bibtex_area = document.createElement('pre');
bibtex_area.className = 'publication_bibtex';
var bibtex_text_box = document.createElement('p');
bibtex_text_box.className = 'publication_text_box';
bibtex_text_box.innerText = bibtex_text;
bibtex_area.appendChild(bibtex_text_box);
pub.appendChild(bibtex_area);
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.onclick = (function (bibtex_area) {
var open = false;
return function () {
if (open) {
bibtex_area.style.maxHeight = "0em";
bibtex_area.style.overflowX = "hidden";
} else {
bibtex_area.style.maxHeight = "30em";
bibtex_area.style.overflowX = "auto";
}
open = !open;
};
})(bibtex_area);
a.target = "New";
a.innerHTML = "bibtex";
li.appendChild(a);
links.appendChild(li);
// Video
link = entry["video"];
if (link != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = link;
a.target = "New"
a.innerHTML = "youtube"
li.appendChild(a);
links.appendChild(li);
}
// Slides (PDF)
link = entry["slides"];
if (link != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = link;
a.target = "New"
a.innerHTML = "slides"
li.appendChild(a);
links.appendChild(li);
}
// Source Code
link = entry["source"];
if (link != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = link
a.target = "New"
a.innerHTML = "source"
li.appendChild(a);
links.appendChild(li);
}
// Datasets
link = entry["datasets"];
if (link != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = link
a.target = "New"
a.innerHTML = "dataset"
li.appendChild(a);
links.appendChild(li);
}
// Link to media coverage
link = entry["media"];
if (link != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = link;
a.target = "New"
a.innerHTML = "media coverage"
li.appendChild(a);
links.appendChild(li);
}
// Homepage
link = entry["homepage"];
if (link != undefined) {
li = document.createElement('li');
li.className = 'publication_link';
a = document.createElement('a');
a.href = link;
a.target = "New"
a.innerHTML = "homepage"
li.appendChild(a);
links.appendChild(li);
}
}
}
// --- TODO: replace the expansion area w/ copy/paste
// function copy_bibtex(bibtex) {
// navigator.clipboard.writeText(bibtex)
// .then(() => alert('Successfully copied Bibtex'));
// }
function make_pubs_callback(pubs) {
for (var i = 0; i < pubs.length; i++) {
if(pubs[i]['type'] != 'patent') {
make_pub(pubs[i])
}
}
}
function make_publications() {
//--- Download the bibfile
jQuery.get("/pubs.json", make_pubs_callback);
}