-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
150 lines (131 loc) · 3.65 KB
/
main.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
$(document).ready(function() {
if ($('#about').length) {
$('#nav-about').addClass('active');
}
if ($('#people').length) {
$('#nav-people').addClass('active');
}
if ($('#projects').length) {
$('#nav-projects').addClass('active');
}
if ($('#publications').length) {
$('#nav-publications').addClass('active');
}
if ($('#alumni').length) {
$('#nav-alumni').addClass('active');
}
if ($('#courses').length) {
$('#nav-courses').addClass('active');
}
// Rudimentary hack at DBLP search
if (window.location.pathname === "/publications") {
loadPubs();
}
});
function loadPubsError() {
$("#publications").html("Error loading publications! Leave a note with <a href='mailto:[email protected]'>[email protected]</a>.");
}
function loadPubs() {
$("#publications").html("<p>Loading publications...</p>");
// CONFIGURE these
var maxResultsCount = 200;
$.ajax({
type: 'GET',
dataType: 'jsonp',
callback: 'callback',
url: 'https://dblp.org/search/publ/api',
data: {
// Can find these on dblp.org/search
q: ':author:Barzan_Mozafari:|:author:Michael_J._Cafarella:|:author:H._V._Jagadish:|:author:Danai_Koutra:',
format: 'jsonp',
h: maxResultsCount
}, success: function (data) {
if (data && 'result' in data && 'hits' in data.result && 'hit' in data.result.hits) {
var pubsByYear = sortPubsByYear(data.result.hits.hit);
renderPubs(pubsByYear);
} else {
loadPubsError();
}
}, error: function () {
loadPubsError();
}
});
}
function sortPubsByYear(hits) {
var pubsByYear = {}
for (var hit of hits) {
var year = hit.info.year;
var url = hit.info.url;
var title = hit.info.title;
if (hit.info.authors.author.constructor === Array) {
var authors = hit.info.authors.author.map((a) => a.text).join(', ');
} else {
var authors = hit.info.authors.author.text;
}
// Replace all "0001" disambiguations for authors
authors = authors.replace(/ [0-9]+/g, '');
var venue = hit.info.venue;
if (Array.isArray(venue)) {
venue = venue.join(', ');
}
if (!venue.endsWith('.')) {
venue += '.';
}
if (!(year in pubsByYear)) {
pubsByYear[year] = [];
}
pubsByYear[year].push({
url: url,
title: title,
authors: authors,
venue: venue
});
}
return pubsByYear;
}
function getPubHTML(pub) {
htmlString = '<li><strong>';
if ("url" in pub) {
htmlString += '<a href=' + pub.url + '>' + pub.title + '</a>';
} else {
htmlString += pub.title;
}
htmlString += '</strong> ';
htmlString += pub.authors + '. ';
htmlString += '<em>' + pub.venue + '</em></li>'
return htmlString;
}
function getAffiliatedPubHTML(el) {
console.log($(el).data('title'));
pub = {
title: $(el).data('title'),
url: $(el).data('url'),
authors: $(el).data('authors'),
venue: $(el).data('venue')
}
if (!pub.venue.endsWith('.')) {
pub.venue += '.';
}
return getPubHTML(pub);
}
function renderPubs(pubsByYear) {
$('#publications').html('');
// get years in sorted order
var years = Object.keys(pubsByYear);
years.sort().reverse();
for (var year of years) {
// sort by year, add h2
$('#publications').append('<h2>' + year + '</h2>');
var pubsList = pubsByYear[year];
var htmlString = '<ul>';
for (var pub of pubsList) {
// add individual publication per year
htmlString += getPubHTML(pub);
}
$('.affiliated-pub[data-year="' + year + '"]').each(function () {
htmlString += getAffiliatedPubHTML(this);
});
htmlString += '</ul>';
$('#publications').append(htmlString);
}
}