-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
515 lines (462 loc) · 27.1 KB
/
Copy pathindex.html
File metadata and controls
515 lines (462 loc) · 27.1 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ScholarSphere</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/png" href="scholarsphere-icon.png">
</head>
<body>
<div class="container">
<h1 class="my-3 text-center brand-title">
<img src="scholarsphere-icon.png" alt="ScholarSphere logo" class="brand-logo">
<span>ScholarSphere</span>
</h1>
<div class="mb-3 d-flex flex-wrap gap-2">
<a href="index.html" class="btn btn-secondary mr-2 mb-2 disabled" tabindex="-1" aria-disabled="true">Read Papers</a>
<a href="unread-papers.html" class="btn btn-primary mr-2 mb-2">Unread Papers</a>
<a href="datasets.html" class="btn btn-warning mr-2 mb-2">Datasets</a>
<a href="topics.html" class="btn btn-secondary mr-2 mb-2">Topics</a>
<a href="useful-links.html" class="btn btn-info mb-2">Useful Links</a>
</div>
<div class="card mb-3 subitems-panel">
<div class="card-body">
<div class="d-flex flex-wrap gap-2 mb-2">
<a href="create-paper.html" class="btn btn-success btn-sm mr-2 mb-2">Create New Paper</a>
<button type="button" id="search-panel-toggle" class="btn btn-primary btn-sm mb-2">Search Papers</button>
</div>
<div id="search-panel" style="display:none;" class="mb-0">
<label for="search-input" class="small text-muted">Search</label>
<input type="text" id="search-input" placeholder="Search by title, author, or keywords"
class="form-control">
<button onclick="searchPapers()" class="btn btn-primary mt-2">Search</button>
</div>
</div>
</div>
<div id="filter-controls" class="mb-3">
<div class="form-row">
<div class="form-group col-md-3 col-sm-6">
<label for="category-filter">Category:</label>
<select id="category-filter" onchange="filterPapers()" class="form-control">
<option value="">All Categories</option>
</select>
</div>
<div class="form-group col-md-3 col-sm-6">
<label for="conference-filter">Conference:</label>
<select id="conference-filter" onchange="filterPapers()" class="form-control">
<option value="">All Conferences</option>
</select>
</div>
<div class="form-group col-md-3 col-sm-6">
<label for="year-filter">Year:</label>
<select id="year-filter" onchange="filterPapers()" class="form-control">
<option value="">All Years</option>
</select>
</div>
<div class="form-group col-md-3 col-sm-6">
<label for="rating-filter">Importance (stars):</label>
<select id="rating-filter" onchange="filterPapers()" class="form-control">
<option value="">All Ratings</option>
<option value="5">5 - Must-read</option>
<option value="4">4 - Very important</option>
<option value="3">3 - Important</option>
<option value="2">2 - Optional</option>
<option value="1">1 - Low priority</option>
</select>
</div>
</div>
</div>
<div id="paper-list">
<!-- Paper list will be dynamically loaded here -->
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
let allPapers = [];
const DEFAULT_RATING = 3;
let isSearchPanelVisible = false;
function setSearchPanelVisible(visible, options = {}) {
const panel = document.getElementById('search-panel');
const toggle = document.getElementById('search-panel-toggle');
if (!panel || !toggle) return;
isSearchPanelVisible = visible;
panel.style.display = visible ? 'block' : 'none';
toggle.textContent = visible ? 'Hide Search' : 'Search Papers';
if (visible && options.focusInput) {
document.getElementById('search-input')?.focus();
}
}
function renderStars(rating) {
const safeRating = Math.max(0, Math.min(5, parseInt(rating, 10) || 0));
return safeRating ? '⭐'.repeat(safeRating) : 'Not rated';
}
function normalizeRating(value) {
const parsed = parseInt(value, 10);
if (isNaN(parsed) || parsed < 1) return DEFAULT_RATING;
return Math.max(1, Math.min(5, parsed));
}
async function loadPapers() {
const paperListDiv = document.getElementById('paper-list');
const paperFiles = await fetchPapersList();
if (!paperFiles || paperFiles.length === 0) {
paperListDiv.innerHTML = `
<div class="alert alert-warning">
<h4>No papers found</h4>
<p>To enable dynamic paper discovery, start a server:</p>
<ul>
<li><strong>Python:</strong> <code>python3 server.py 8001</code></li>
<li><strong>PHP:</strong> Use a PHP-enabled web server</li>
<li><strong>Node.js:</strong> <code>node list-papers.js</code></li>
</ul>
<p>Then visit <a href="http://localhost:8001">http://localhost:8001</a></p>
<p><small>Pure dynamic discovery - no papers.json needed!</small></p>
</div>
`;
return;
}
allPapers = [];
paperListDiv.innerHTML = "";
// Sort paperFiles by addedTime (latest to oldest)
const paperFileData = [];
for (const paperFile of paperFiles) {
try {
const filePath = paperFile.startsWith('papers/') ? paperFile : `papers/${paperFile}`;
const response = await fetch(filePath + '?t=' + Date.now(), { cache: 'no-store' });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const paperData = await response.json();
paperData.rating = normalizeRating(paperData.rating);
// Keep track of the source filePath so links remain correct even if title changes
paperFileData.push({ paperData, filePath });
} catch (error) {
console.error(`Error loading ${paperFile}:`, error);
paperListDiv.innerHTML += `<p>Error loading paper data: ${paperFile}</p>`;
}
}
// Sort by addedTime (latest to oldest)
paperFileData.sort((a, b) => {
const aTime = new Date(a.paperData.addedTime || 0).getTime();
const bTime = new Date(b.paperData.addedTime || 0).getTime();
return bTime - aTime;
});
for (const { paperData, filePath } of paperFileData) {
allPapers.push(paperData);
console.log('Loaded paper:', paperData.title, 'addedTime:', paperData.addedTime);
const paperLink = document.createElement('a');
paperLink.href = `paper.html?file=${encodeURIComponent(filePath)}`;
paperLink.classList.add('paper-link');
const mainIdeaHtml = paperData.mainIdea && paperData.mainIdea.includes('\n')
? `<ul>` + paperData.mainIdea.split(/\n|\r/).filter(line => line.trim()).map(line => `<li>${marked.parseInline(line.replace(/^\d+\.|[-*]\s/, '').trim())}</li>`).join('') + `</ul>`
: `<span>${marked.parseInline(paperData.mainIdea || '')}</span>`;
const takeawaysHtml = paperData.takeaways && paperData.takeaways.includes('\n')
? `<ul>` + paperData.takeaways.split(/\n|\r/).filter(line => line.trim()).map(line => `<li>${marked.parseInline(line.replace(/^\d+\.|[-*]\s/, '').trim())}</li>`).join('') + `</ul>`
: `<span>${marked.parseInline(paperData.takeaways || '')}</span>`;
// Generate figures HTML if there are any figures
const figuresHtml = paperData.figures && paperData.figures.length > 0
? `
<div class="figures-container mt-3">
<p style="color:green"><strong>Figures:</strong></p>
<div class="row">
${paperData.figures.map((figure, index) => `
<div class="col-md-4 mb-3">
<div class="card">
<img src="${figure.image}" data-fullsrc="${figure.image}" class="card-img-top figure-thumbnail" alt="Figure ${index + 1}" style="max-height: 200px; object-fit: contain; cursor: zoom-in;">
<div class="card-body">
<p class="card-text">${marked.parseInline(figure.description || '')}</p>
</div>
</div>
</div>
`).join('')}
</div>
</div>`
: '';
paperLink.innerHTML = `
<h2 style="color:green">${paperData.title}</h2>
${isValidDate(paperData.addedTime) ? `<p style="color:green"><strong>Added Time:</strong> ${new Date(paperData.addedTime).toLocaleString()}</p>` : '<p style="color:red"><strong>Added Time:</strong> Invalid or missing</p>'}
<p style="color:green"><strong>Authors:</strong> ${paperData.authors}</p>
<p style="color:green"><strong>Conference:</strong> ${paperData.conference} (${paperData.year})</p>
<p style="color:green"><strong>Importance:</strong> ${renderStars(paperData.rating)}${paperData.rating ? ` (${paperData.rating}/5)` : ''}</p>
<p style="color:green"><strong>Keywords:</strong> ${paperData.keywords.join(', ')}</p>
<p style="color:blue"><strong>Main Idea:</strong> ${mainIdeaHtml}</p>
<p style="color:blue"><strong>Takeaways:</strong> ${takeawaysHtml}</p>
${figuresHtml}
`;
paperListDiv.appendChild(paperLink);
}
populateFilters();
}
async function fetchPapersList() {
// Try dynamic server endpoints in order of preference
const endpoints = [
"list-papers.php", // PHP endpoint
"/list-papers" // Python/Node.js endpoint
];
for (const endpoint of endpoints) {
try {
console.log(`Trying endpoint: ${endpoint}`);
const response = await fetch(endpoint);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(`Successfully loaded ${data.paperFiles.length} papers from ${endpoint}`);
return data.paperFiles;
} catch (error) {
console.log(`Endpoint ${endpoint} not available:`, error.message);
}
}
// If no server endpoints work, inform the user
console.error("No dynamic server endpoints available. Please start a server:");
console.error(" Python: python3 server.py 8001");
console.error(" PHP: Use a PHP-enabled web server");
console.error(" Node.js: node list-papers.js");
// Return empty array - no fallbacks, pure dynamic discovery only
return [];
}
async function populateFilters() {
const categoryFilter = document.getElementById('category-filter');
const conferenceFilter = document.getElementById('conference-filter');
const yearFilter = document.getElementById('year-filter');
categoryFilter.innerHTML = '<option value="">All Categories</option>';
conferenceFilter.innerHTML = '<option value="">All Conferences</option>';
yearFilter.innerHTML = '<option value="">All Years</option>';
const categories = new Set();
const conferences = new Set();
const years = new Set();
allPapers.forEach(paper => {
if (paper.categories) {
paper.categories.forEach(category => categories.add(category));
}
conferences.add(paper.conference);
years.add(paper.year);
});
categories.forEach(category => {
const option = document.createElement('option');
option.value = category;
option.textContent = category;
categoryFilter.appendChild(option);
});
conferences.forEach(conference => {
const option = document.createElement('option');
option.value = conference;
option.textContent = conference;
conferenceFilter.appendChild(option);
});
years.forEach(year => {
const option = document.createElement('option');
option.value = year;
option.textContent = year;
yearFilter.appendChild(option);
});
}
async function filterPapers() {
const category = document.getElementById('category-filter').value;
const conference = document.getElementById('conference-filter').value;
const year = document.getElementById('year-filter').value;
const ratingFilter = document.getElementById('rating-filter').value;
const paperListDiv = document.getElementById('paper-list');
paperListDiv.innerHTML = "";
const filteredPapers = allPapers.filter(paper => {
let categoryMatch = true;
if (category && paper.categories) {
categoryMatch = paper.categories.includes(category);
} else if (category) {
categoryMatch = false;
}
const conferenceMatch = conference ? paper.conference === conference : true;
const yearMatch = year ? paper.year === parseInt(year) : true;
const ratingMatch = ratingFilter ? paper.rating === parseInt(ratingFilter, 10) : true;
return categoryMatch && conferenceMatch && yearMatch && ratingMatch;
});
if (filteredPapers.length === 0) {
paperListDiv.innerHTML = "<p>No papers found matching your filter criteria.</p>";
return;
}
// We need to know each paper's source file; build a lookup once
const titleToFilePath = new Map();
// If multiple with same sanitized title, the latest loaded will win; acceptable here
document.querySelectorAll('#paper-list a.paper-link').forEach(a => {
const url = new URL(a.href, window.location.href);
const file = url.searchParams.get('file');
const titleEl = a.querySelector('h2');
if (titleEl && file) {
titleToFilePath.set(titleEl.textContent, file);
}
});
filteredPapers.forEach(paper => {
// Prefer filePath we loaded earlier if present
const fallback = `papers/${paper.title.replace(/[^a-zA-Z0-9]/g, '')}.json`;
const resolvedFilePath = titleToFilePath.get(paper.title) || fallback;
const paperLink = document.createElement('a');
paperLink.href = `paper.html?file=${encodeURIComponent(resolvedFilePath)}`;
paperLink.classList.add('paper-link');
const mainIdeaHtml = paper.mainIdea && paper.mainIdea.includes('\n')
? `<ul>` + paper.mainIdea.split(/\n|\r/).filter(line => line.trim()).map(line => `<li>${marked.parseInline(line.replace(/^\d+\.|[-*]\s/, '').trim())}</li>`).join('') + `</ul>`
: `<span>${marked.parseInline(paper.mainIdea || '')}</span>`;
const takeawaysHtml = paper.takeaways && paper.takeaways.includes('\n')
? `<ul>` + paper.takeaways.split(/\n|\r/).filter(line => line.trim()).map(line => `<li>${marked.parseInline(line.replace(/^\d+\.|[-*]\s/, '').trim())}</li>`).join('') + `</ul>`
: `<span>${marked.parseInline(paper.takeaways || '')}</span>`;
// Generate figures HTML if there are any figures
const figuresHtml = paper.figures && paper.figures.length > 0
? `
<div class="figures-container mt-3">
<p style="color:green"><strong>Figures:</strong></p>
<div class="row">
${paper.figures.map((figure, index) => `
<div class="col-md-4 mb-3">
<div class="card">
<img src="${figure.image}" data-fullsrc="${figure.image}" class="card-img-top figure-thumbnail" alt="Figure ${index + 1}" style="max-height: 200px; object-fit: contain; cursor: zoom-in;">
<div class="card-body">
<p class="card-text">${marked.parseInline(figure.description || '')}</p>
</div>
</div>
</div>
`).join('')}
</div>
</div>`
: '';
paperLink.innerHTML = `
<h2 style="color:green">${paper.title}</h2>
${isValidDate(paper.addedTime) ? `<p style="color:green"><strong>Added Time:</strong> ${new Date(paper.addedTime).toLocaleString()}</p>` : '<p style="color:red"><strong>Added Time:</strong> Invalid or missing</p>'}
<p style="color:green"><strong>Authors:</strong> ${paper.authors}</p>
<p style="color:green"><strong>Conference:</strong> ${paper.conference} (${paper.year})</p>
<p style="color:green"><strong>Importance:</strong> ${renderStars(paper.rating)}${paper.rating ? ` (${paper.rating}/5)` : ''}</p>
<p style="color:green"><strong>Keywords:</strong> ${paper.keywords.join(', ')}</p>
<p style="color:blue"><strong>Main Idea:</strong> ${mainIdeaHtml}</p>
<p style="color:blue"><strong>Takeaways:</strong> ${takeawaysHtml}</p>
${figuresHtml}
`;
paperListDiv.appendChild(paperLink);
});
}
async function searchPapers() {
const searchTerm = document.getElementById('search-input').value.toLowerCase();
const paperListDiv = document.getElementById('paper-list');
paperListDiv.innerHTML = "";
const filteredPapers = allPapers.filter(paper => {
const title = paper.title.toLowerCase();
const authors = paper.authors.toLowerCase();
const keywords = paper.keywords.map(keyword => keyword.toLowerCase()).join(' ');
const mainIdea = paper.mainIdea.toLowerCase();
const ratingString = String(paper.rating || '');
const starString = renderStars(paper.rating).toLowerCase();
return (
title.includes(searchTerm) ||
authors.includes(searchTerm) ||
keywords.includes(searchTerm) ||
mainIdea.includes(searchTerm) ||
ratingString.includes(searchTerm) ||
starString.includes(searchTerm)
);
});
if (filteredPapers.length === 0) {
paperListDiv.innerHTML = "<p>No papers found matching your search.</p>";
return;
}
// Build lookup of displayed items for consistent linking
const titleToFilePathSearch = new Map();
document.querySelectorAll('#paper-list a.paper-link').forEach(a => {
const url = new URL(a.href, window.location.href);
const file = url.searchParams.get('file');
const titleEl = a.querySelector('h2');
if (titleEl && file) {
titleToFilePathSearch.set(titleEl.textContent, file);
}
});
filteredPapers.forEach(paper => {
const fallback = `papers/${paper.title.replace(/[^a-zA-Z0-9]/g, '')}.json`;
const resolvedFilePath = titleToFilePathSearch.get(paper.title) || fallback;
const paperLink = document.createElement('a');
paperLink.href = `paper.html?file=${encodeURIComponent(resolvedFilePath)}`;
paperLink.classList.add('paper-link');
const mainIdeaHtml = paper.mainIdea && paper.mainIdea.includes('\n')
? `<ul>` + paper.mainIdea.split(/\n|\r/).filter(line => line.trim()).map(line => `<li>${marked.parseInline(line.replace(/^\d+\.|[-*]\s/, '').trim())}</li>`).join('') + `</ul>`
: `<span>${marked.parseInline(paper.mainIdea || '')}</span>`;
const takeawaysHtml = paper.takeaways && paper.takeaways.includes('\n')
? `<ul>` + paper.takeaways.split(/\n|\r/).filter(line => line.trim()).map(line => `<li>${marked.parseInline(line.replace(/^\d+\.|[-*]\s/, '').trim())}</li>`).join('') + `</ul>`
: `<span>${marked.parseInline(paper.takeaways || '')}</span>`;
// Generate figures HTML if there are any figures
const figuresHtml = paper.figures && paper.figures.length > 0
? `
<div class="figures-container mt-3">
<p style="color:green"><strong>Figures:</strong></p>
<div class="row">
${paper.figures.map((figure, index) => `
<div class="col-md-4 mb-3">
<div class="card">
<img src="${figure.image}" data-fullsrc="${figure.image}" class="card-img-top figure-thumbnail" alt="Figure ${index + 1}" style="max-height: 200px; object-fit: contain; cursor: zoom-in;">
<div class="card-body">
<p class="card-text">${marked.parseInline(figure.description || '')}</p>
</div>
</div>
</div>
`).join('')}
</div>
</div>`
: '';
paperLink.innerHTML = `
<h2 style="color:green">${paper.title}</h2>
${isValidDate(paper.addedTime) ? `<p style="color:green"><strong>Added Time:</strong> ${new Date(paper.addedTime).toLocaleString()}</p>` : '<p style="color:red"><strong>Added Time:</strong> Invalid or missing</p>'}
<p style="color:green"><strong>Authors:</strong> ${paper.authors}</p>
<p style="color:green"><strong>Conference:</strong> ${paper.conference} (${paper.year})</p>
<p style="color:green"><strong>Importance:</strong> ${renderStars(paper.rating)}${paper.rating ? ` (${paper.rating}/5)` : ''}</p>
<p style="color:green"><strong>Keywords:</strong> ${paper.keywords.join(', ')}</p>
<p style="color:blue"><strong>Main Idea:</strong> ${mainIdeaHtml}</p>
<p style="color:blue"><strong>Takeaways:</strong> ${takeawaysHtml}</p>
${figuresHtml}
`;
paperListDiv.appendChild(paperLink);
});
}
function isValidDate(dateString) {
const d = new Date(dateString);
return dateString && !isNaN(d.getTime());
}
// Simple lightbox overlay
function ensureLightbox() {
if (document.getElementById('lightbox-overlay')) return;
const overlay = document.createElement('div');
overlay.id = 'lightbox-overlay';
overlay.style.position = 'fixed';
overlay.style.inset = '0';
overlay.style.background = 'rgba(0,0,0,0.8)';
overlay.style.display = 'none';
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.zIndex = '1050';
overlay.innerHTML = '<img id="lightbox-image" style="max-width: 95%; max-height: 95%; box-shadow: 0 0 12px rgba(0,0,0,0.6); cursor: zoom-out;" />';
overlay.addEventListener('click', () => overlay.style.display = 'none');
document.body.appendChild(overlay);
}
function openLightbox(src) {
ensureLightbox();
const overlay = document.getElementById('lightbox-overlay');
const img = document.getElementById('lightbox-image');
img.src = src;
overlay.style.display = 'flex';
}
// Prevent navigation when clicking a figure inside an anchor and open lightbox instead
document.addEventListener('click', function(e) {
const img = e.target.closest('img.figure-thumbnail');
if (img) {
e.preventDefault();
e.stopPropagation();
openLightbox(img.getAttribute('data-fullsrc') || img.src);
}
}, true);
document.getElementById('search-panel-toggle').addEventListener('click', () => {
setSearchPanelVisible(!isSearchPanelVisible, { focusInput: !isSearchPanelVisible });
});
document.getElementById('search-input').addEventListener('keyup', (e) => {
if (e.key === 'Enter') {
e.preventDefault();
searchPapers();
}
});
loadPapers();
</script>
</body>
</html>