-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblog.html
More file actions
268 lines (238 loc) · 8.59 KB
/
Copy pathblog.html
File metadata and controls
268 lines (238 loc) · 8.59 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Blog – The Quantifier</title>
<meta name="description" content="The Quantifier Blog — exploring mathematics, programming, and gaming." />
<meta name="author" content="John Hand" />
<link rel="icon" type="image/png" href="images/favicon.png" />
<link rel="stylesheet" href="styles/default.css" />
<link rel="stylesheet" href="styles/blog.css" />
</head>
<script>
(function () {
const DURATION = 100; // keep in sync with --fade-duration
// Mark page as ready (fade in)
function ready() {
// In case we returned from bfcache, remove fading state
document.body.classList.remove('is-fading');
document.body.classList.add('is-ready');
}
// On normal load & bfcache restore
window.addEventListener('DOMContentLoaded', ready);
window.addEventListener('pageshow', (e) => {
if (e.persisted) ready();
});
// Only intercept safe, same-tab, same-origin links
function shouldIntercept(a) {
if (!a) return false;
const url = new URL(a.href, location.href);
if (url.origin !== location.origin) return false; // external
if (a.target && a.target !== '_self') return false; // new tab/window
if (a.hasAttribute('download')) return false; // download
if (a.getAttribute('href')?.startsWith('#')) return false; // in-page
return true;
}
document.addEventListener('click', (e) => {
const a = e.target.closest('a');
if (!shouldIntercept(a)) return;
// Respect reduced motion
const prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
e.preventDefault();
if (!prefersReduced) {
document.body.classList.add('is-fading');
setTimeout(() => (location.href = a.href), DURATION);
} else {
location.href = a.href;
}
});
})();
</script>
<body>
<!-- ==================== HEADER ==================== -->
<header class="thin-header">
<div class="header-bar">
<div class="header-left">
<h1 class="site-title">The Quantifier</h1>
<span class="tagline">Math • Code • Game • Repeat</span>
</div>
<nav aria-label="Main Navigation">
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="blog.html" class="active">Blog</a></li>
</ul>
</nav>
</div>
</header>
<!-- ==================== BANNER ==================== -->
<section class="banner">
<img src="images/blog-banner.jpg" alt="Abstract geometric banner for The Quantifier Blog" />
<div class="banner-overlay">
<h2>The Quantifier Blog</h2>
<p>Exploring mathematics, programming, and gaming — where logic meets creativity.</p>
</div>
</section>
<!-- ==================== MAIN ==================== -->
<main class="container">
<section class="hero">
<h2>Latest Posts</h2>
<p>Notes on mathematics, Godot development, and gaming — from theory to creation.</p>
</section>
<!-- Controls -->
<section class="blog-controls" aria-label="Blog controls">
<label for="blog-search" class="visually-hidden">Search posts by title</label>
<input id="blog-search" type="search" placeholder="Search by title…" autocomplete="off" />
<div class="blog-meta">
<span id="results-count" aria-live="polite"></span>
</div>
</section>
<!-- Posts -->
<section id="blog" class="blog-grid" aria-live="polite" aria-busy="true">
<!-- Blog posts will load here dynamically -->
</section>
<!-- Load more -->
<div class="load-more-wrap">
<button id="load-more" class="button" type="button">Load more</button>
</div>
<!-- Error -->
<div id="blog-error" class="blog-error" hidden>
<p>Couldn’t load posts. Please refresh.</p>
</div>
</main>
<!-- ==================== FOOTER ==================== -->
<footer>
<div class="container footer-content">
<p>© <span id="year"></span> The Quantifier. All rights reserved.</p>
<p class="credit">Site by <strong>Manus Webworks</strong></p>
</div>
</footer>
<!-- ==================== SCRIPTS ==================== -->
<script>
const PAGE_SIZE = 6;
const $ = (sel) => document.querySelector(sel);
function nl2br(str) {
return (str || "").replace(/\n/g, "<br>");
}
function formatDate(iso) {
try {
const d = new Date(iso);
return d.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
} catch {
return iso;
}
}
function renderImages(images) {
if (!Array.isArray(images) || images.length === 0) return "";
return `
<div class="post-images">
${images.map(src => `
<figure>
<img
loading="lazy"
src="images/blog/${src}"
alt=""
onclick="openLightbox('images/blog/${src}')"
/>
</figure>
`).join("")}
</div>
`;
}
function renderPost(post) {
const title = post.title || "Untitled";
const messageHTML = nl2br(post.message);
const dateShown = post.displayDate || formatDate(post.date);
return `
<article class="post-card" tabindex="0">
<header class="post-header">
<h3 class="post-title">${title}</h3>
<time class="post-date" datetime="${post.date || ""}">${dateShown}</time>
</header>
<div class="post-body">
<p>${messageHTML}</p>
${renderImages(post.images)}
</div>
</article>
`;
}
// -------- Lightbox --------
function openLightbox(src) {
const overlay = document.createElement("div");
overlay.className = "lightbox-overlay";
overlay.innerHTML = `
<div class="lightbox-content" role="dialog" aria-modal="true">
<img src="${src}" alt="">
</div>
`;
overlay.addEventListener("click", () => document.body.removeChild(overlay));
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && document.body.contains(overlay)) {
document.body.removeChild(overlay);
}
});
document.body.appendChild(overlay);
}
// -------- Blog Logic --------
let allPosts = [];
let filtered = [];
let shownCount = 0;
function updateResultsCount() {
const el = $("#results-count");
el.textContent = filtered.length
? `${Math.min(shownCount, filtered.length)} of ${filtered.length} posts`
: "No posts found";
}
function renderNextPage() {
const blogEl = $("#blog");
const slice = filtered.slice(shownCount, shownCount + PAGE_SIZE);
blogEl.insertAdjacentHTML("beforeend", slice.map(renderPost).join(""));
shownCount += slice.length;
$("#load-more").style.display = (shownCount >= filtered.length) ? "none" : "inline-block";
blogEl.setAttribute("aria-busy", "false");
updateResultsCount();
}
function resetAndRender() {
$("#blog").innerHTML = "";
shownCount = 0;
renderNextPage();
}
function applyFilter(query) {
const q = (query || "").trim().toLowerCase();
filtered = !q ? [...allPosts] : allPosts.filter(p => (p.title || "").toLowerCase().includes(q));
resetAndRender();
}
async function loadBlog() {
const errorEl = $("#blog-error");
try {
const res = await fetch("data/blog.json", { cache: "no-store" });
if (!res.ok) throw new Error("HTTP " + res.status);
const data = await res.json();
allPosts = Array.isArray(data.posts) ? data.posts : [];
allPosts.sort((a, b) => new Date(b.date || 0) - new Date(a.date || 0));
filtered = [...allPosts];
resetAndRender();
} catch (e) {
errorEl.hidden = false;
console.error("Blog load failed:", e);
}
}
document.addEventListener("DOMContentLoaded", () => {
$("#year").textContent = new Date().getFullYear();
const searchInput = $("#blog-search");
let t = null;
searchInput.addEventListener("input", () => {
clearTimeout(t);
$("#blog").setAttribute("aria-busy", "true");
t = setTimeout(() => applyFilter(searchInput.value), 180);
});
$("#load-more").addEventListener("click", () => {
$("#blog").setAttribute("aria-busy", "true");
renderNextPage();
});
loadBlog();
});
</script>
</body>
</html>