-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
576 lines (527 loc) · 18.1 KB
/
viewer.html
File metadata and controls
576 lines (527 loc) · 18.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>21no.de — Reader</title>
<meta name="theme-color" content="#0a0a0b" />
<!-- Fonts: Outfit + Monaspace Neon (matching website) -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet" />
<style>
/* === Design Tokens (matching 21no.de website) === */
:root {
--bg-primary: #0a0a0b;
--bg-card: #16161a;
--bg-code: #0d0d10;
--border-subtle: rgba(255,255,255,0.06);
--border-card: rgba(255,255,255,0.08);
--text-primary: #ededef;
--text-secondary: #9b9ba3;
--text-tertiary: #6b6b75;
--accent: #38bdf8;
--accent-glow: rgba(56,189,248,0.12);
--accent-subtle: rgba(56,189,248,0.08);
--radius-sm: 6px;
--radius-md: 8px;
--radius-lg: 12px;
--font-sans: 'Outfit', system-ui, -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', 'Monaspace Neon', ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
--max-width: 1100px;
--content-width: 740px;
}
/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
font-family: var(--font-sans);
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.7;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* === Navigation (matching website) === */
.nav {
position: sticky; top: 0; z-index: 100;
background: rgba(10,10,11,0.85);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-bottom: 1px solid var(--border-subtle);
}
.nav-inner {
display: flex; align-items: center; justify-content: space-between;
height: 56px; max-width: var(--max-width); margin: 0 auto; padding: 0 24px;
}
.nav-logo {
display: flex; align-items: center; gap: 10px;
font-weight: 600; font-size: 18px; color: var(--text-primary);
letter-spacing: -0.3px; text-decoration: none;
}
.nav-logo svg { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.nav-logo:hover { color: #fff; }
.nav-links { display: flex; gap: 24px; align-items: center; }
.nav-links a {
font-size: 14px; font-weight: 400; color: var(--text-secondary);
letter-spacing: -0.1px; transition: color 0.15s; text-decoration: none;
}
.nav-links a:hover { color: var(--text-primary); }
/* === Layout === */
.book-container {
max-width: var(--content-width);
margin: 0 auto;
padding: 48px 24px 80px;
}
/* === Loading / Error States === */
#loading, #error {
text-align: center;
padding: 120px 24px;
color: var(--text-secondary);
}
#loading .spinner {
width: 32px; height: 32px;
border: 2px solid var(--border-card);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#error h2 { color: #f87171; margin-bottom: 12px; font-weight: 500; }
#error a { color: var(--accent); }
/* === Book Header === */
.book-header {
text-align: center;
margin-bottom: 48px;
padding-bottom: 40px;
border-bottom: 1px solid var(--border-subtle);
}
.book-header .section-label {
font-family: var(--font-mono);
font-size: 12px;
font-weight: 500;
color: var(--accent);
text-transform: uppercase;
letter-spacing: 0.8px;
margin-bottom: 16px;
}
.book-header h1 {
font-size: clamp(32px, 4vw, 44px);
font-weight: 700;
color: #fff;
letter-spacing: -1.6px;
line-height: 1.08;
margin-bottom: 12px;
}
.book-header .subtitle {
font-size: 16px;
font-weight: 300;
color: var(--text-secondary);
line-height: 1.5;
}
.book-header .meta {
display: flex; gap: 16px; justify-content: center; align-items: center; flex-wrap: wrap;
margin-top: 20px;
font-size: 13px;
color: var(--text-tertiary);
}
.book-header .meta .badge {
display: inline-flex; align-items: center; gap: 6px;
background: var(--accent-subtle);
border: 1px solid rgba(56,189,248,0.2);
color: var(--accent);
padding: 3px 12px;
border-radius: 999px;
font-size: 12px;
font-weight: 500;
}
.book-header .meta .badge .dot {
width: 5px; height: 5px;
background: var(--accent);
border-radius: 50%;
}
/* === Typography — Title Page === */
.book-content {
font-size: 16px;
line-height: 1.7;
}
.book-content h1 {
font-size: clamp(26px, 3.5vw, 34px);
font-weight: 700;
color: #fff;
margin-top: 48px;
margin-bottom: 16px;
letter-spacing: -1.2px;
line-height: 1.15;
padding-bottom: 12px;
border-bottom: 1px solid rgba(56,189,248,0.25);
}
/* — First h1 (book title) — no border, no top margin */
.book-content h1:first-child {
margin-top: 0;
border-bottom: none;
padding-bottom: 0;
}
/* — Subtitle: h2 immediately after first h1 */
.book-content h1:first-child + h2 {
font-size: 16px;
font-weight: 300;
color: var(--text-secondary);
font-style: italic;
line-height: 1.5;
border: none;
padding: 0;
margin: 8px 0 20px;
}
/* — Author line */
.book-content h1:first-child + h2 + p {
font-size: 14px;
color: var(--text-secondary);
}
/* — Epigraph blockquote on title page */
.book-content h1:first-child + h2 + p + blockquote {
text-align: center;
max-width: 80%;
margin: 24px auto;
border-left: none;
background: transparent;
color: var(--text-tertiary);
font-size: 14px;
}
.book-content h1:first-child + h2 + p + blockquote p {
color: var(--text-tertiary);
}
/* — Second h1 = About the Author */
.book-content h1:nth-child(2 of h1) {
margin-top: 48px;
}
/* === Typography — Chapter Headings === */
.book-content h2 {
font-family: var(--font-sans);
font-size: 20px;
font-weight: 600;
color: var(--text-primary);
margin-top: 40px;
margin-bottom: 12px;
line-height: 1.3;
letter-spacing: -0.4px;
}
.book-content h3 {
font-family: var(--font-sans);
font-size: 17px;
font-weight: 600;
color: var(--text-primary);
margin-top: 32px;
margin-bottom: 8px;
line-height: 1.3;
}
.book-content h4 {
font-family: var(--font-sans);
font-size: 15px;
font-weight: 500;
color: var(--text-secondary);
font-style: italic;
margin-top: 24px;
margin-bottom: 6px;
}
/* === Body Text === */
.book-content p {
margin-bottom: 16px;
line-height: 1.7;
color: var(--text-primary);
}
/* === Strong / Emphasis === */
.book-content strong { font-weight: 600; color: #fff; }
.book-content em { color: #e8e8ec; font-style: italic; }
/* === Blockquotes === */
.book-content blockquote {
margin: 24px 0;
padding: 16px 20px;
border-left: 3px solid rgba(56,189,248,0.35);
font-style: italic;
background: var(--bg-card);
border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
line-height: 1.6;
}
.book-content blockquote p {
margin-bottom: 8px;
color: var(--text-secondary);
}
.book-content blockquote p:last-child { margin-bottom: 0; }
/* === Code === */
.book-content code {
font-family: var(--font-mono);
font-size: 14px;
background: var(--bg-card);
color: var(--accent);
padding: 2px 6px;
border-radius: 4px;
}
.book-content pre {
font-family: var(--font-mono);
font-size: 13px;
background: var(--bg-code);
color: var(--text-primary);
padding: 16px 20px;
border: 1px solid var(--border-card);
border-radius: var(--radius-md);
line-height: 1.45;
overflow-x: auto;
margin: 20px 0;
}
.book-content pre code {
background: none;
padding: 0;
font-size: inherit;
color: inherit;
}
/* === Tables === */
.book-content table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
font-size: 14px;
background: var(--bg-card);
border-radius: var(--radius-md);
overflow: hidden;
}
.book-content th {
background: var(--accent);
color: #000;
padding: 10px 14px;
text-align: left;
font-weight: 600;
font-size: 13px;
}
.book-content td {
padding: 8px 14px;
border: 1px solid var(--border-subtle);
vertical-align: top;
color: var(--text-primary);
line-height: 1.5;
}
.book-content tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
/* === Lists === */
.book-content ul, .book-content ol {
margin: 12px 0 16px;
padding-left: 28px;
}
.book-content li {
margin-bottom: 6px;
line-height: 1.65;
color: var(--text-primary);
}
.book-content ol li::marker {
color: var(--accent);
font-weight: 600;
}
.book-content ul li::marker {
color: var(--text-tertiary);
}
/* === Links === */
.book-content a {
color: var(--accent);
text-decoration: none;
transition: color 0.15s;
}
.book-content a:hover { color: #7dd3fc; }
/* === Horizontal Rule === */
.book-content hr {
border: none;
border-top: 1px solid var(--border-subtle);
margin: 32px 0;
}
/* === Images === */
.book-content img {
max-width: 100%;
border-radius: var(--radius-md);
margin: 20px 0;
border: 1px solid var(--border-card);
}
/* === Footer === */
.book-footer {
margin-top: 64px;
padding: 40px 0 0;
border-top: 1px solid var(--border-subtle);
text-align: center;
}
.book-footer .social-links {
display: flex; gap: 20px; justify-content: center; margin-bottom: 16px;
}
.book-footer .social-links a {
color: var(--text-tertiary); font-size: 14px;
display: inline-flex; align-items: center; gap: 6px;
text-decoration: none; transition: color 0.15s;
}
.book-footer .social-links a:hover { color: var(--text-primary); }
.book-footer p {
font-size: 13px;
color: var(--text-tertiary);
}
.book-footer a { color: var(--text-secondary); text-decoration: none; }
.book-footer a:hover { color: var(--text-primary); }
/* === Responsive === */
@media (max-width: 768px) {
.book-container { padding: 24px 16px 60px; }
.book-content { font-size: 15px; }
.book-content pre { font-size: 12px; padding: 12px 14px; }
.book-content blockquote { padding: 12px 16px; }
.nav-links a:not(.nav-cta) { display: none; }
}
</style>
</head>
<body>
<!-- Navigation (matching 21no.de website) -->
<nav class="nav">
<div class="nav-inner">
<a href="/" class="nav-logo">
<svg width="28" height="28" viewBox="0 0 28 28" fill="none">
<rect width="28" height="28" rx="6" fill="#38bdf8"/>
<text x="14" y="20" text-anchor="middle" fill="#0a0a0b" font-family="system-ui" font-weight="700" font-size="16">21</text>
</svg>
21no.de
</a>
<div class="nav-links">
<a href="/">Home</a>
<a href="/#projects">Projects</a>
<a href="/#blog">Blog</a>
<a href="https://github.com/BackendStack21" target="_blank" rel="noopener">GitHub</a>
</div>
</div>
</nav>
<!-- Loading State -->
<div id="loading">
<div class="spinner"></div>
<p>Loading book...</p>
</div>
<!-- Error State -->
<div id="error" style="display:none">
<h2>Could not load book</h2>
<p id="errorMessage">The book file could not be found or loaded.</p>
<p style="margin-top:16px"><a href="/" style="color:var(--accent)">← Back to 21no.de</a></p>
</div>
<!-- Book Content -->
<main id="content" class="book-container" style="display:none">
<div id="bookHeader" class="book-header" style="display:none"></div>
<div id="bookContent" class="book-content"></div>
<div id="bookFooter" class="book-footer" style="display:none">
<div class="social-links">
<a href="https://github.com/BackendStack21" target="_blank" rel="noopener">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>
GitHub
</a>
<a href="https://medium.com/@21node" target="_blank" rel="noopener">Medium</a>
</div>
<p>© 2046 <a href="https://21no.de">21no.de</a> — Open-source research lab</p>
</div>
</main>
<script>
(function() {
const loading = document.getElementById('loading');
const error = document.getElementById('error');
const errorMsg = document.getElementById('errorMessage');
const content = document.getElementById('content');
const bookContent = document.getElementById('bookContent');
const bookHeader = document.getElementById('bookHeader');
const bookFooter = document.getElementById('bookFooter');
const params = new URLSearchParams(window.location.search);
const file = params.get('file') || 'the-next-frontier.md';
function loadMarked() {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/marked@15.0.7/marked.min.js';
script.onload = resolve;
script.onerror = () => reject(new Error('Failed to load marked.js'));
document.head.appendChild(script);
});
}
function stripHtml(html) {
const tmp = document.createElement('div');
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || '';
}
async function init() {
try {
await loadMarked();
const res = await fetch(file);
if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
const md = await res.text();
// Extract metadata
const titleMatch = md.match(/^# (.+)$/m);
const subtitleMatch = md.match(/^## (.+)$/m);
const title = titleMatch ? titleMatch[1] : 'Untitled';
const subtitle = subtitleMatch ? subtitleMatch[1] : '';
const words = md.split(/\s+/).length;
// Configure marked with heading IDs
const renderer = new marked.Renderer();
renderer.heading = function({ text, depth }) {
const id = text.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.replace(/(^-|-$)/g, '');
return `<h${depth} id="${id}">${text}</h${depth}>`;
};
marked.setOptions({
breaks: true,
gfm: true,
renderer: renderer,
});
// Render
const html = marked.parse(md);
bookContent.innerHTML = html;
// Set page title
document.title = `${title} — 21no.de`;
// Build header
bookHeader.style.display = 'block';
bookHeader.innerHTML = `
<div class="section-label">Book</div>
<h1>${title}</h1>
${subtitle ? `<p class="subtitle">${subtitle}</p>` : ''}
<div class="meta">
<span class="badge"><span class="dot"></span> ${title}</span>
<span>~${(words / 1000).toFixed(0)}K words</span>
</div>
`;
// Show content
content.style.display = 'block';
bookFooter.style.display = 'block';
loading.style.display = 'none';
// Wrap tables for horizontal scroll
document.querySelectorAll('.book-content table').forEach(t => {
const wrapper = document.createElement('div');
wrapper.style.overflowX = 'auto';
t.parentNode.insertBefore(wrapper, t);
wrapper.appendChild(t);
});
// Smooth scroll for anchor links in the same page
document.querySelectorAll('.book-content a[href^="#"]').forEach(a => {
a.addEventListener('click', function(e) {
e.preventDefault();
const id = this.getAttribute('href').replace('#', '');
const el = document.getElementById(id);
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
} catch (err) {
loading.style.display = 'none';
error.style.display = 'block';
errorMsg.textContent = err.message || 'Unknown error loading the book.';
console.error('Book viewer error:', err);
}
}
init();
})();
</script>
<!-- Service Worker for offline access -->
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').catch(err =>
console.warn('SW registration failed:', err)
);
}
</script>
</body>
</html>