-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
156 lines (136 loc) · 5.65 KB
/
scripts.js
File metadata and controls
156 lines (136 loc) · 5.65 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
// Minimal client-side search & filters (no deps)
const state = { data: [], section: 'All', tag: null, q: '' };
const $ = (sel) => document.querySelector(sel);
const el = (tag, props = {}, ...children) => {
const n = document.createElement(tag);
Object.entries(props).forEach(([k, v]) => {
if (k === 'class') n.className = v;
else if (k === 'html') n.innerHTML = v;
else n.setAttribute(k, v);
});
children.forEach(c => n.append(c));
return n;
};
async function load() {
// Load data/papers.json; if missing, fall back to a tiny embedded sample
let data = [];
try {
const res = await fetch('data/papers.json', { cache: 'no-store' });
if (res.ok) data = await res.json();
} catch (_) {}
if (!data.length) {
data = [
{
"title": "Attention Is All You Need",
"authors": ["Vaswani et al."],
"venue": "NeurIPS",
"year": 2017,
"section": "Machine Learning",
"tags": ["Transformers", "Sequence Modeling"],
"link": "https://arxiv.org/abs/1706.03762",
"reflection": "Why transformers beat RNNs for long dependencies; key insight: self-attention scales O(n^2) but parallelizes beautifully."
}
];
}
state.data = data;
// Auto-fill repo link if hosted on GitHub Pages
const m = location.href.match(/^https:\/\/([^.]+)\.github\.io\/([^/?#]+)\//);
if (m) {
const [, user, repo] = m;
const a = document.getElementById('repoLink');
a.href = `https://github.com/${user}/${repo}`;
a.hidden = false;
}
const sections = Array.from(new Set(state.data.map(x => x.section))).sort();
renderSections(['All', ...sections]);
renderTags();
applyHash();
render();
}
function renderSections(sections) {
const wrap = $('#sections'); wrap.innerHTML = '';
sections.forEach(name => {
const active = state.section === name;
const chip = el('button', { class: `chip ${active ? 'active' : ''}`, 'aria-pressed': active }, name);
chip.onclick = () => { state.section = name; state.tag = null; updateHash(); render(); };
wrap.append(chip);
});
}
function renderTags() {
const wrap = $('#tags'); wrap.innerHTML = '';
const tags = new Map(); // tag -> count
state.data.forEach(x => (x.tags || []).forEach(t => tags.set(t, (tags.get(t) || 0) + 1)));
[...tags.entries()].sort((a,b)=>a[0].localeCompare(b[0])).forEach(([tag, count]) => {
const active = state.tag === tag;
const chip = el('button', { class: `chip ${active ? 'active':''}` }, `${tag} (${count})`);
chip.onclick = () => { state.tag = active ? null : tag; updateHash(); render(); };
wrap.append(chip);
});
}
function searchFilter(item) {
const q = state.q.trim().toLowerCase();
if (!q) return true;
const hay = [
item.title, item.authors?.join(' '), item.venue, item.year, item.abstract,
(item.tags||[]).join(' '), item.reflection
].filter(Boolean).join(' ').toLowerCase();
return hay.includes(q);
}
function render() {
const list = $('#list'); list.innerHTML = '';
const filtered = state.data
.filter(x => state.section === 'All' || x.section === state.section)
.filter(x => !state.tag || (x.tags||[]).includes(state.tag))
.filter(searchFilter);
$('#stats').textContent = `${filtered.length} item(s) • Section: ${state.section}${state.tag ? ` • Tag: ${state.tag}` : ''}${state.q ? ` • Query: “${state.q}”` : ''}`;
filtered
.sort((a,b) => (b.year||0) - (a.year||0) || a.title.localeCompare(b.title))
.forEach(p => {
const card = el('article', { class:'card' });
card.append(el('h3', {}, p.title));
const metaBits = [
p.authors?.join(', ') || '—',
p.venue ? ` • ${p.venue}` : '',
p.year ? ` • ${p.year}` : ''
].join('');
card.append(el('div', { class:'meta' }, metaBits));
if (p.abstract) card.append(el('p', {}, p.abstract));
const badges = el('div', { class:'badges' });
(p.tags || []).forEach(t => badges.append(el('span', { class:'badge'}, t)));
badges.append(el('span', { class:'badge'}, p.section));
card.append(badges);
const links = el('div', {});
if (p.pdf) links.append(el('a', { class:'btn', href:p.pdf, target:'_blank', rel:'noopener' }, 'PDF'));
if (p.link) links.append(el('a', { class:'btn', href:p.link, target:'_blank', rel:'noopener' }, 'Publisher'));
if (p.code) links.append(el('a', { class:'btn', href:p.code, target:'_blank', rel:'noopener' }, 'Code'));
if (p.notes)links.append(el('a', { class:'btn', href:p.notes,target:'_blank', rel:'noopener' }, 'Notes'));
card.append(links);
// Paper Reflections (collapsible)
if (p.reflection) {
const details = el('details', { class: 'reflect' });
const sum = el('summary', {}, 'Paper Reflections');
const body = el('div', { class: 'reflect-body' }, p.reflection);
details.append(sum, body);
card.append(details);
}
list.append(card);
});
}
function updateHash() {
const params = new URLSearchParams();
if (state.section && state.section !== 'All') params.set('section', state.section);
if (state.tag) params.set('tag', state.tag);
if (state.q) params.set('q', state.q);
const hash = params.toString();
history.replaceState(null, '', hash ? `#${hash}` : location.pathname);
}
function applyHash() {
const params = new URLSearchParams(location.hash.replace(/^#/, ''));
state.section = params.get('section') || state.section;
state.tag = params.get('tag');
state.q = params.get('q') || '';
$('#search').value = state.q;
}
$('#search').addEventListener('input', (e) => { state.q = e.target.value; updateHash(); render(); });
window.addEventListener('hashchange', () => { applyHash(); render(); });
load();