-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopic-view.html
More file actions
864 lines (801 loc) · 32.2 KB
/
topic-view.html
File metadata and controls
864 lines (801 loc) · 32.2 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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Topic</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">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style>
.markdown-content {
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 30px;
margin-top: 20px;
line-height: 1.7;
font-size: 1rem;
}
.markdown-content h1 {
font-size: 2.5rem;
border-bottom: 3px solid #333;
padding-bottom: 12px;
margin-bottom: 25px;
margin-top: 0;
}
.markdown-content h2 {
font-size: 1.8rem;
margin-top: 30px;
margin-bottom: 15px;
color: #333;
border-bottom: 1px solid #ddd;
padding-bottom: 8px;
}
.markdown-content h3 {
font-size: 1.4rem;
margin-top: 25px;
margin-bottom: 12px;
color: #444;
}
.markdown-content h4 {
font-size: 1.2rem;
margin-top: 20px;
margin-bottom: 10px;
color: #555;
}
.markdown-content p {
margin-bottom: 15px;
}
.markdown-content ul, .markdown-content ol {
margin-left: 25px;
margin-bottom: 20px;
}
.markdown-content li {
margin-bottom: 8px;
}
.markdown-content code {
background-color: #f5f5f5;
padding: 3px 8px;
border-radius: 4px;
font-family: 'Courier New', Consolas, Monaco, monospace;
font-size: 0.9em;
color: #c7254e;
}
.markdown-content pre {
background-color: #f8f8f8;
padding: 16px;
border-radius: 6px;
overflow-x: auto;
border: 1px solid #e1e1e1;
margin-bottom: 20px;
}
.markdown-content pre code {
background-color: transparent;
padding: 0;
color: inherit;
font-size: 0.9em;
}
.markdown-content blockquote {
border-left: 4px solid #007bff;
padding-left: 20px;
margin-left: 0;
margin-bottom: 20px;
color: #666;
font-style: italic;
}
.markdown-content a {
color: #007bff;
text-decoration: none;
}
.markdown-content a:hover {
text-decoration: underline;
}
.markdown-content table {
border-collapse: collapse;
width: 100%;
margin-bottom: 20px;
}
.markdown-content table th,
.markdown-content table td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
.markdown-content table th {
background-color: #f8f9fa;
font-weight: bold;
}
.markdown-content input[type="checkbox"] {
margin-right: 8px;
}
.markdown-content hr {
border: 0;
border-top: 2px solid #ddd;
margin: 30px 0;
}
.markdown-content img {
max-width: 100%;
height: auto;
margin: 20px 0;
}
.markdown-editor {
min-height: 400px;
font-family: 'Courier New', Consolas, Monaco, monospace;
font-size: 0.95rem;
}
.topic-header {
background-color: #f8f9fa;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
}
.tech-iteration-summary {
border: 1px solid #d4dde8;
border-radius: 14px;
background: #ffffff;
margin-bottom: 24px;
overflow: hidden;
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}
.tech-iteration-summary-head {
padding: 16px 18px 14px;
background: linear-gradient(90deg, #eef3ff 0%, #f6f8fc 45%, #ecf9ef 100%);
border-bottom: 1px solid #dfe6ee;
text-align: center;
}
.tech-iteration-summary-head h4 {
margin: 0;
font-size: 1.24rem;
letter-spacing: 0.4px;
text-transform: uppercase;
}
.tech-iteration-summary-head small {
color: #5f6b7b;
font-weight: 600;
}
.tech-head-toolbar {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-top: 8px;
}
.tech-zoom-btn {
border: 1px solid #b8c8da;
background: #ffffff;
color: #334155;
border-radius: 8px;
min-width: 34px;
height: 30px;
line-height: 1;
font-weight: 700;
cursor: pointer;
}
.tech-zoom-btn:hover {
background: #eef5ff;
}
.tech-zoom-label {
min-width: 50px;
font-size: 0.86rem;
color: #475569;
font-weight: 700;
}
.tech-matrix-wrap {
overflow-x: auto;
padding: 14px;
background: linear-gradient(180deg, #fbfdff 0%, #f7faff 100%);
}
.tech-iteration-grid {
display: grid;
grid-template-columns: minmax(190px, 230px) repeat(var(--phase-count, 1), minmax(250px, 1fr));
min-width: calc(230px + var(--phase-count, 1) * 250px);
border: 1px solid #d8e1eb;
border-radius: 10px;
overflow: hidden;
background: #fff;
zoom: var(--tech-zoom, 1);
}
.tech-col-header,
.tech-org-header {
font-weight: 700;
padding: 12px;
border-bottom: 1px solid #dfe6ee;
border-right: 1px solid #dfe6ee;
}
.tech-org-header {
background: #f1f4f8;
color: #1f2937;
position: sticky;
left: 0;
z-index: 2;
}
.tech-col-header {
text-align: center;
color: #1e293b;
}
.tech-col-header.phase-0 { background: #dbe9f8; }
.tech-col-header.phase-1 { background: #fde7c8; }
.tech-col-header.phase-2 { background: #d9efd9; }
.tech-col-header.phase-3 { background: #eadcf4; }
.tech-phase-main {
display: block;
font-size: 1rem;
font-weight: 800;
}
.tech-phase-sub {
display: block;
font-size: 0.78rem;
color: #475569;
margin-top: 2px;
}
.tech-org-cell {
font-weight: 700;
background: #f8fafc;
color: #111827;
border-right: 1px solid #dfe6ee;
border-bottom: 1px solid #dfe6ee;
padding: 12px;
position: sticky;
left: 0;
z-index: 1;
}
.tech-cell {
border-right: 1px solid #dfe6ee;
border-bottom: 1px solid #dfe6ee;
padding: 7px;
min-height: 90px;
position: relative;
}
.tech-cell[data-phase-index="0"] { background: #eff5ff; }
.tech-cell[data-phase-index="1"] { background: #fff6e7; }
.tech-cell[data-phase-index="2"] { background: #ecf8ee; }
.tech-cell[data-phase-index="3"] { background: #f3edfa; }
.tech-cell-arrow {
position: absolute;
left: 6px;
top: 6px;
color: #7b8aa0;
font-weight: 700;
font-size: 0.92rem;
}
.tech-item {
background: #ffffff;
border: 1px solid #c8d6e6;
border-radius: 12px;
padding: 9px 10px;
margin-bottom: 8px;
cursor: pointer;
transition: transform 0.14s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.tech-item:hover {
transform: translateY(-1px);
border-color: #8eaccb;
box-shadow: 0 6px 14px rgba(30, 41, 59, 0.14);
}
.tech-item:last-child {
margin-bottom: 0;
}
.tech-item-title {
font-weight: 700;
line-height: 1.32;
margin-bottom: 4px;
color: #0f172a;
}
.tech-item-subtitle {
color: #64748b;
font-size: 0.8rem;
margin-bottom: 6px;
font-weight: 600;
}
.tech-item-hint {
color: #607086;
font-size: 0.74rem;
font-weight: 600;
}
.tech-item-points {
margin: 8px 0 0 0;
padding-left: 17px;
font-size: 0.88rem;
display: none;
}
.tech-item-points li {
margin-bottom: 4px;
}
.tech-item.is-expanded .tech-item-points {
display: block;
}
.tech-item.is-expanded .tech-item-hint {
display: none;
}
.tech-empty {
color: #97a7bb;
font-size: 0.8rem;
padding: 8px 2px 4px;
text-align: center;
opacity: 0.8;
}
</style>
</head>
<body>
<div class="container">
<div class="my-3 d-flex flex-wrap gap-2 align-items-center">
<a href="topics.html" class="btn btn-secondary mr-2 mb-2">← Back to Topics</a>
<a href="index.html" class="btn btn-outline-secondary mr-2 mb-2">Read Papers</a>
<a href="datasets.html" class="btn btn-outline-secondary mr-2 mb-2">Datasets</a>
<a href="useful-links.html" class="btn btn-outline-secondary mr-2 mb-2">Useful Links</a>
</div>
<div id="topic-header" class="topic-header"></div>
<div id="view-mode">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3>Content</h3>
<button id="edit-btn" class="btn btn-primary">Edit Content</button>
</div>
<div id="markdown-display" class="markdown-content">
<p class="text-muted">Loading...</p>
</div>
</div>
<div id="edit-mode" style="display: none;">
<div class="d-flex justify-content-between align-items-center mb-3">
<h3>Edit Markdown</h3>
<div>
<button id="save-btn" class="btn btn-success mr-2">Save Changes</button>
<button id="cancel-btn" class="btn btn-secondary">Cancel</button>
</div>
</div>
<form id="edit-form">
<div class="form-group">
<textarea id="markdown-editor" class="form-control markdown-editor" placeholder="Write your markdown content here..."></textarea>
</div>
</form>
</div>
</div>
<script>
const TOPICS_ENDPOINT = '/topics';
let currentTopic = null;
let currentSlug = null;
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
function formatDateTime(value) {
if (!value) return 'Unknown';
const d = new Date(value);
return isNaN(d.getTime()) ? 'Unknown' : d.toLocaleString();
}
async function fetchTopics() {
try {
const resp = await fetch(TOPICS_ENDPOINT, { cache: 'no-store' });
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const data = await resp.json();
return Array.isArray(data.items) ? data.items : [];
} catch (e) {
console.error('Failed to load topics:', e);
return [];
}
}
async function fetchMarkdown(slug) {
try {
const resp = await fetch(`/topics/${slug}`, { cache: 'no-store' });
if (!resp.ok) return '';
return await resp.text();
} catch (e) {
console.error('Failed to load markdown:', e);
return '';
}
}
async function saveMarkdown(slug, content) {
try {
const resp = await fetch(`/topics/${slug}`, {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: content
});
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
// Update the topic's updatedAt timestamp
await updateTopicTimestamp(slug);
return true;
} catch (e) {
console.error('Failed to save markdown:', e);
alert('Could not save content. Please try again.');
return false;
}
}
async function updateTopicTimestamp(slug) {
try {
const topics = await fetchTopics();
const updatedTopics = topics.map(t => {
if (t.slug === slug) {
return { ...t, updatedAt: new Date().toISOString() };
}
return t;
});
await fetch(TOPICS_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ items: updatedTopics })
});
} catch (e) {
console.error('Failed to update timestamp:', e);
}
}
function renderTopicHeader(topic) {
const header = document.getElementById('topic-header');
if (!header) return;
const modifiedTime = topic.updatedAt || topic.createdAt;
header.innerHTML = `
<h1 class="mb-2">${topic.name}</h1>
${topic.description ? `<p class="text-muted mb-2">${topic.description}</p>` : ''}
<div class="small text-muted">
<span>Created: ${formatDateTime(topic.createdAt)}</span>
${topic.updatedAt ? ` | <span>Last Modified: ${formatDateTime(topic.updatedAt)}</span>` : ''}
</div>
`;
}
function escapeHtml(raw) {
return String(raw || '')
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function parseTechniqueTitleParts(title) {
const trimmed = (title || '').trim();
const matched = trimmed.match(/^(.*?)\s*\(([^)]+)\)\s*$/);
if (!matched) {
const [year, month] = extractDateParts(trimmed);
return { name: trimmed, org: inferOrganizationFromTitle(trimmed), year, month };
}
const name = matched[1].trim();
const meta = matched[2].split(',').map(s => s.trim()).filter(Boolean);
let year = null;
let month = null;
let org = '';
for (const token of meta) {
const [parsedYear, parsedMonth] = extractDateParts(token);
if (!year && parsedYear) year = parsedYear;
if (!month && parsedMonth) month = parsedMonth;
if (!org && !/\b20\d{2}\b/.test(token)) org = token;
}
if (!org) org = inferOrganizationFromTitle(name);
if (!year) {
const [fallbackYear, fallbackMonth] = extractDateParts(name);
year = fallbackYear;
month = month || fallbackMonth;
}
return { name, org, year, month };
}
function isTechniqueSection(sectionTitle) {
const t = (sectionTitle || '').toLowerCase();
return t.includes('public approaches') || t.includes('technique') || t.includes('iterations');
}
function extractDateParts(text) {
const matched = String(text || '').match(/\b(20\d{2})(?:[.\-/](\d{1,2}))?\b/);
if (!matched) return [null, null];
const year = Number(matched[1]);
const month = matched[2] ? Math.max(1, Math.min(12, Number(matched[2]))) : null;
return [year, month];
}
function inferOrganizationFromTitle(title) {
const source = String(title || '');
const known = ['NVIDIA', 'Google DeepMind', 'DeepMind', 'ByteDance', 'Figure', 'Tesla', 'Boston Dynamics', 'Unitree', 'AGIBOT', '1X', 'OpenAI', 'Physical Intelligence', 'Gemini'];
const lowered = source.toLowerCase();
const matched = known.find(item => lowered.includes(item.toLowerCase()));
if (matched) return matched;
const cleaned = source.replace(/[()]/g, ' ').trim();
return (cleaned.split(/\s+/).slice(0, 2).join(' ') || 'Unknown Org');
}
function phaseFromDate(year, month) {
if (!year) return { key: 'unknown', label: 'Unknown' };
const m = month || 6;
let bucket = 'mid';
let labelPrefix = 'Mid';
if (m <= 4) {
bucket = 'early';
labelPrefix = 'Early';
} else if (m >= 9) {
bucket = 'late';
labelPrefix = 'Late';
}
return { key: `${year}-${bucket}`, label: `${labelPrefix} ${year}`, order: year * 100 + m };
}
function looksLikeTechniqueHeading(text) {
const value = String(text || '');
if (/\b20\d{2}\b/.test(value)) return true;
if (/\([^)]*20\d{2}[^)]*\)/.test(value)) return true;
if (/:\s/.test(value)) return true;
return false;
}
function extractTechniqueIterations(content) {
const lines = (content || '').split(/\r?\n/);
let currentSection = '';
let currentOrg = '';
let activeEntry = null;
let inHighlights = false;
const entries = [];
function flushEntry() {
if (!activeEntry) return;
if (activeEntry.points.length === 0) {
activeEntry.points = activeEntry.fallbackPoints.slice(0, 3);
}
delete activeEntry.fallbackPoints;
entries.push(activeEntry);
activeEntry = null;
inHighlights = false;
}
for (const rawLine of lines) {
const line = rawLine.trimEnd();
const h2 = line.match(/^##\s+(.+)$/);
if (h2) {
flushEntry();
currentSection = h2[1].trim();
currentOrg = '';
continue;
}
const h3 = line.match(/^###\s+(.+)$/);
if (h3) {
flushEntry();
if (isTechniqueSection(currentSection)) {
const h3Text = h3[1].trim();
if (looksLikeTechniqueHeading(h3Text)) {
const parts = parseTechniqueTitleParts(h3Text);
activeEntry = {
title: parts.name,
org: parts.org || currentOrg || inferOrganizationFromTitle(parts.name),
year: parts.year,
month: parts.month,
phase: phaseFromDate(parts.year, parts.month),
points: [],
fallbackPoints: []
};
} else {
currentOrg = h3Text;
}
}
continue;
}
const h4OrH5 = line.match(/^#{4,5}\s+(.+)$/);
if (h4OrH5) {
const headingText = h4OrH5[1].trim();
const headingLower = headingText.toLowerCase();
if (headingLower.includes('highlight')) {
inHighlights = true;
continue;
}
if (headingLower.includes('limitation') || headingLower.includes('challenge')) {
inHighlights = false;
continue;
}
if (isTechniqueSection(currentSection)) {
flushEntry();
const parts = parseTechniqueTitleParts(headingText);
activeEntry = {
title: parts.name,
org: currentOrg || parts.org || inferOrganizationFromTitle(parts.name),
year: parts.year,
month: parts.month,
phase: phaseFromDate(parts.year, parts.month),
points: [],
fallbackPoints: []
};
}
continue;
}
if (!activeEntry) continue;
const bullet = line.match(/^\s*-\s+(.+)$/);
if (bullet) {
const point = bullet[1].trim();
if (!point) continue;
const normalizedPoint = point.replace(/\*\*(.*?)\*\*/g, '$1').trim();
activeEntry.fallbackPoints.push(normalizedPoint);
if (inHighlights && activeEntry.points.length < 3) {
activeEntry.points.push(normalizedPoint);
}
}
}
flushEntry();
return entries.filter(item => item.title);
}
function renderTechniqueSummary(content) {
const entries = extractTechniqueIterations(content);
if (entries.length < 2) return '';
const orgSet = new Set(entries.map(e => e.org || 'Unknown Org'));
const phaseMap = new Map();
for (const entry of entries) {
const key = entry.phase.key;
const existing = phaseMap.get(key);
if (!existing || (entry.phase.order || 0) < existing.order) {
phaseMap.set(key, { ...entry.phase });
}
}
const chronologicalPhases = Array.from(phaseMap.values()).sort((a, b) => {
if (a.key === 'unknown') return 1;
if (b.key === 'unknown') return -1;
return (a.order || 0) - (b.order || 0);
});
const knownPhases = chronologicalPhases.filter(phase => phase.key !== 'unknown').reverse();
const unknownPhases = chronologicalPhases.filter(phase => phase.key === 'unknown');
const phases = [...knownPhases, ...unknownPhases];
const organizations = Array.from(orgSet).sort((a, b) => a.localeCompare(b));
const entriesByCell = new Map();
for (const entry of entries) {
const cellKey = `${entry.org || 'Unknown Org'}__${entry.phase.key}`;
if (!entriesByCell.has(cellKey)) entriesByCell.set(cellKey, []);
entriesByCell.get(cellKey).push(entry);
}
const headerHtml = `
<div class="tech-org-header">Organization</div>
${phases.map((phase, idx) => `
<div class="tech-col-header phase-${idx % 4}">
<span class="tech-phase-main">${escapeHtml(phase.label)}</span>
<span class="tech-phase-sub">Phase ${Math.max(1, phases.length - idx)}</span>
</div>
`).join('')}
`;
const bodyHtml = organizations.map((org) => {
const rowCells = phases.map((phase, phaseIndex) => {
const cellKey = `${org}__${phase.key}`;
const cellEntries = entriesByCell.get(cellKey) || [];
if (!cellEntries.length) {
return `<div class="tech-cell" data-phase-key="${escapeHtml(phase.key)}" data-phase-index="${phaseIndex % 4}"><div class="tech-empty">-</div></div>`;
}
const hasNewerUpdate = phases.slice(0, phaseIndex).some(newerPhase => {
const newerKey = `${org}__${newerPhase.key}`;
return (entriesByCell.get(newerKey) || []).length > 0;
});
const cardsHtml = cellEntries.map((item) => {
const points = item.points || [];
const subtitle = item.year ? `${item.year}${item.month ? `.${String(item.month).padStart(2, '0')}` : ''}` : '';
const pointsHtml = points.length
? `<ul class="tech-item-points">${points.map(p => `<li>${marked.parseInline(escapeHtml(p))}</li>`).join('')}</ul>`
: '';
return `
<div class="tech-item" title="Click to show details" tabindex="0">
<div class="tech-item-title">${marked.parseInline(escapeHtml(item.title))}</div>
${subtitle ? `<div class="tech-item-subtitle">${escapeHtml(subtitle)}</div>` : ''}
<div class="tech-item-hint">Click for details</div>
${pointsHtml}
</div>
`;
}).join('');
return `
<div class="tech-cell" data-phase-key="${escapeHtml(phase.key)}" data-phase-index="${phaseIndex % 4}">
${hasNewerUpdate ? '<div class="tech-cell-arrow">←</div>' : ''}
${cardsHtml}
</div>
`;
}).join('');
return `
<div class="tech-org-cell" data-org-name="${escapeHtml(org)}">${escapeHtml(org)}</div>
${rowCells}
`;
}).join('');
return `
<div class="tech-iteration-summary">
<div class="tech-iteration-summary-head">
<h4>Parallel Iteration of ${(currentTopic?.name || 'Topic')} Techniques</h4>
<small>Click each card to expand details</small>
<div class="tech-head-toolbar">
<button type="button" class="tech-zoom-btn" data-tech-action="zoom-out" title="Zoom out">-</button>
<span class="tech-zoom-label" data-tech-zoom-label>100%</span>
<button type="button" class="tech-zoom-btn" data-tech-action="zoom-in" title="Zoom in">+</button>
<button type="button" class="tech-zoom-btn" data-tech-action="zoom-reset" title="Reset zoom">100</button>
</div>
</div>
<div class="tech-matrix-wrap">
<div class="tech-iteration-grid" style="--phase-count:${phases.length}">
${headerHtml}
${bodyHtml}
</div>
</div>
</div>
`;
}
function setupTechniqueSummaryInteractions(container) {
if (!container) return;
const summary = container.querySelector('.tech-iteration-summary');
if (!summary) return;
const matrix = summary.querySelector('.tech-iteration-grid');
const zoomLabel = summary.querySelector('[data-tech-zoom-label]');
const zoomInBtn = summary.querySelector('[data-tech-action="zoom-in"]');
const zoomOutBtn = summary.querySelector('[data-tech-action="zoom-out"]');
const zoomResetBtn = summary.querySelector('[data-tech-action="zoom-reset"]');
let currentZoom = 1;
const minZoom = 0.7;
const maxZoom = 1.5;
const zoomStep = 0.1;
const applyZoom = () => {
if (!matrix) return;
const clamped = Math.max(minZoom, Math.min(maxZoom, currentZoom));
currentZoom = Number(clamped.toFixed(2));
matrix.style.setProperty('--tech-zoom', String(currentZoom));
if (zoomLabel) zoomLabel.textContent = `${Math.round(currentZoom * 100)}%`;
};
zoomInBtn?.addEventListener('click', () => {
currentZoom += zoomStep;
applyZoom();
});
zoomOutBtn?.addEventListener('click', () => {
currentZoom -= zoomStep;
applyZoom();
});
zoomResetBtn?.addEventListener('click', () => {
currentZoom = 1;
applyZoom();
});
applyZoom();
summary.querySelectorAll('.tech-item').forEach(item => {
item.addEventListener('click', () => item.classList.toggle('is-expanded'));
item.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
item.classList.toggle('is-expanded');
}
});
});
}
async function renderMarkdown(content) {
const display = document.getElementById('markdown-display');
if (!display) return;
if (!content || content.trim() === '') {
display.innerHTML = '<div class="alert alert-info">No content yet. Click "Edit Content" to add notes.</div>';
return;
}
marked.setOptions({
breaks: true,
gfm: true
});
const summaryHtml = renderTechniqueSummary(content);
display.innerHTML = `${summaryHtml}${marked.parse(content)}`;
setupTechniqueSummaryInteractions(display);
}
function switchToEditMode(content) {
document.getElementById('view-mode').style.display = 'none';
document.getElementById('edit-mode').style.display = 'block';
document.getElementById('markdown-editor').value = content || '';
}
function switchToViewMode() {
document.getElementById('view-mode').style.display = 'block';
document.getElementById('edit-mode').style.display = 'none';
}
async function loadTopic() {
currentSlug = getQueryParam('slug');
if (!currentSlug) {
alert('No topic specified');
window.location.href = 'topics.html';
return;
}
const topics = await fetchTopics();
currentTopic = topics.find(t => t.slug === currentSlug);
if (!currentTopic) {
alert('Topic not found');
window.location.href = 'topics.html';
return;
}
renderTopicHeader(currentTopic);
const content = await fetchMarkdown(currentSlug);
await renderMarkdown(content);
}
document.getElementById('edit-btn').addEventListener('click', async () => {
const content = await fetchMarkdown(currentSlug);
switchToEditMode(content);
});
document.getElementById('cancel-btn').addEventListener('click', () => {
switchToViewMode();
});
document.getElementById('save-btn').addEventListener('click', async () => {
const content = document.getElementById('markdown-editor').value;
const ok = await saveMarkdown(currentSlug, content);
if (ok) {
await renderMarkdown(content);
switchToViewMode();
// Reload topic to update timestamp in header
await loadTopic();
}
});
loadTopic();
</script>
</body>
</html>