-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
225 lines (193 loc) · 6.29 KB
/
Copy pathscript.js
File metadata and controls
225 lines (193 loc) · 6.29 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
// ===== Config you update monthly =====
const LAST_UPDATED = '2026-02-05'; // ISO date string
const DATA_URL = 'radiovoltaics-bibliography.json'; // CSL-JSON with `tags` merged in (see merge-tags.mjs)
// ===== Utilities =====
const $ = sel => document.querySelector(sel);
const norm = s => (s || '').toString().toLowerCase().trim();
const siteUrl = () => location.href.replace(location.hash,'').replace(location.search,'');
// Set dates/URL (guard elements in case some pages don't include them)
const _el = id => document.querySelector(id);
const _setText = (id, val) => { const el = _el(id); if (el) el.textContent = val; };
_setText('#lastUpdated', LAST_UPDATED);
_setText('#lastUpdatedCite', LAST_UPDATED);
_setText('#siteUrl', siteUrl());
// ===== Data loading & normalization =====
// Format author names as "Initials Surname" and apply "et al." for >3 authors
function initialsFrom(given) {
if (!given) return '';
// remove periods, split on whitespace, take first letter of each part
const parts = String(given).replace(/\./g, '').split(/\s+/).filter(Boolean);
return parts.map(p => (p[0] || '').toUpperCase() + '.').join(' ');
}
function formatAuthorObj(a) {
const family = a?.family || '';
const given = a?.given || '';
const initials = initialsFrom(given);
return (initials ? `${initials} ${family}` : family).trim();
}
function formatAuthors(list) {
if (!Array.isArray(list)) return '';
const formatted = list.map(formatAuthorObj).filter(Boolean);
if (formatted.length > 3) return `${formatted[0]} et al.`;
return formatted.join('; ');
}
async function loadData() {
const res = await fetch(DATA_URL, { cache: 'no-store' });
const data = await res.json(); // CSL-JSON array
return data.map(e => ({
id: e.id || '',
type: (e.type || '').toLowerCase(),
title: e.title || '',
author: formatAuthors(e.author || []),
year: (e.issued?.['date-parts']?.[0]?.[0] || '').toString(),
doi: e.DOI || '',
url: e.URL || '',
journal: e['container-title'] || e['collection-title'] || '',
tags: Array.isArray(e.tags) ? e.tags : []
}));
}
function populateYears(entries) {
const years = Array.from(new Set(entries.map(e => e.year).filter(Boolean)))
.sort((a, b) => b.localeCompare(a));
const sel = $('#yearFilter');
for (const y of years) {
const opt = document.createElement('option');
opt.value = y; opt.textContent = y;
sel.appendChild(opt);
}
}
function render(entries) {
const container = $('#entries');
container.innerHTML = '';
for (const e of entries) {
const el = document.createElement('article');
el.className = 'entry';
el.setAttribute('role', 'listitem');
const title = document.createElement('div');
title.className = 'entry-title';
if (e.doi) {
title.innerHTML = `<a href="https://doi.org/${e.doi}">${e.title}</a>`;
}
else {if (e.url) {
title.innerHTML = `<a href="${e.url}">${e.title}</a>`;
}}
const meta = document.createElement('div');
meta.className = 'entry-meta';
meta.textContent = [e.author, e.journal, e.year].filter(Boolean).join(' • ');
const links = document.createElement('div');
links.className = 'entry-links';
const parts = [];
links.innerHTML = parts.join(' | ');
const tagRow = document.createElement('div');
(e.tags || []).forEach(t => {
const b = document.createElement('span');
b.className = 'badge';
b.textContent = t;
tagRow.appendChild(b);
});
el.appendChild(title);
el.appendChild(links);
el.appendChild(meta);
el.appendChild(tagRow);
container.appendChild(el);
}
$('#count').textContent = `${entries.length} item(s)`;
}
let ALL = [];
let chartInstance = null;
function getFilteredEntries() {
const q = norm($('#search').value);
const y = $('#yearFilter').value;
const checkedTags = Array.from(document.querySelectorAll('#tagFilter input[type=checkbox]:checked'))
.map(el => el.value);
let out = ALL.slice();
if (y) out = out.filter(e => e.year === y);
if (q) {
out = out.filter(e =>
norm(e.title).includes(q) ||
norm(e.author).includes(q) ||
norm(e.journal).includes(q) ||
norm(e.doi).includes(q) ||
norm(e.id).includes(q) ||
norm(e.year).includes(q)
);
}
// OR logic for tags: match any selected tag
if (checkedTags.length) {
out = out.filter(e => (e.tags || []).some(t => checkedTags.includes(t)));
}
return out;
}
function updateHistogram(entries) {
const yearCounts = {};
entries.forEach(e => {
if (e.year) {
yearCounts[e.year] = (yearCounts[e.year] || 0) + 1;
}
});
const sortedYears = Object.keys(yearCounts).sort((a, b) => b.localeCompare(a));
const counts = sortedYears.map(y => yearCounts[y]);
const ctx = $('#yearHistogram');
if (!ctx) return;
if (chartInstance) {
chartInstance.data.labels = sortedYears;
chartInstance.data.datasets[0].data = counts;
chartInstance.update();
} else {
chartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: sortedYears,
datasets: [{
label: 'Number of Publications',
data: counts,
backgroundColor: 'rgba(75, 129, 192, 0.7)',
borderColor: 'rgba(75, 129, 192, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: true,
plugins: {
legend: {
display: false
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Count'
}
},
x: {
title: {
display: true,
text: 'Year'
}
}
}
}
});
}
}
function applyFilters() {
const out = getFilteredEntries();
// Sort: newest first, then title
out.sort((a, b) => (b.year || '').localeCompare(a.year || '') || (a.title || '').localeCompare(b.title || ''));
render(out);
updateHistogram(out);
}
loadData().then(entries => {
ALL = entries;
populateYears(ALL);
applyFilters();
});
// Wire up events
['input', 'change'].forEach(evt => {
$('#search').addEventListener(evt, applyFilters);
$('#yearFilter').addEventListener(evt, applyFilters);
$('#tagFilter').addEventListener(evt, applyFilters);
});