-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogReader.html
More file actions
300 lines (255 loc) · 12.3 KB
/
BlogReader.html
File metadata and controls
300 lines (255 loc) · 12.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog Reader</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script src="https://unpkg.com/lucide@latest"></script>
<style>
:root {
--bg: #fafafa;
--fg: #111827;
--accent: #2563eb;
--muted: #6b7280;
--border: #e5e7eb;
--card: #ffffff;
--note: #eef6ff;
--warn: #fffbeb;
--success: #f0fdf4;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg);
color: var(--fg);
line-height: 1.7;
}
/* --- Layout --- */
header {
position: fixed; top: 0; width: 100%; height: 70px;
background: rgba(250, 250, 250, 0.8);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border);
z-index: 100; padding: 0 2rem;
display: flex; align-items: center; justify-content: space-between;
}
main { max-width: 1100px; margin: 0 auto; padding: 120px 2rem 4rem; }
/* --- Search & Categories --- */
.search-box {
position: relative; flex: 1; max-width: 400px; margin: 0 2rem;
}
.search-box input {
width: 100%; padding: 0.6rem 1rem 0.6rem 2.5rem;
border-radius: 12px; border: 1px solid var(--border);
outline: none; transition: 0.2s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37,99,235,0.05); }
.search-box i { position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; }
.cat-panel-btn {
background: var(--card); border: 1px solid var(--border);
padding: 0.5rem 1rem; border-radius: 10px; cursor: pointer;
display: flex; align-items: center; gap: 8px; font-weight: 500;
}
#cat-panel {
position: fixed; top: 80px; right: 2rem; width: 260px;
background: var(--card); border: 1px solid var(--border);
border-radius: 14px; padding: 1.5rem; box-shadow: 0 10px 30px rgba(0,0,0,0.05);
display: none; z-index: 101;
}
#cat-panel.active { display: block; animation: slideIn 0.2s ease; }
/* --- Blog Cards --- */
.blog-grid {
display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 2rem;
}
.card {
background: var(--card); border: 1px solid var(--border);
border-radius: 18px; padding: 1.8rem; cursor: pointer;
transition: all 0.2s ease; display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-5px); box-shadow: 0 15px 35px rgba(0,0,0,0.05); border-color: var(--accent); }
.card-status { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; color: var(--accent); margin-bottom: 0.5rem; }
.card-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.8rem; line-height: 1.3; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 1.2rem; }
.tag {
font-size: 0.75rem; background: #f1f5f9; padding: 0.3rem 0.7rem;
border-radius: 8px; color: #475569; cursor: pointer;
}
.tag:hover, .tag.active { background: var(--accent); color: white; }
/* --- Full Blog Content Rendering (Matches Builder) --- */
#full-view {
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: white; z-index: 1000; display: none; overflow-y: auto;
}
#full-view.active { display: block; }
.article-container { max-width: 800px; margin: 0 auto; padding: 6rem 2rem; }
.back-btn {
position: absolute; top: 2rem; left: 2rem; background: white;
border: 1px solid var(--border); padding: 0.6rem 1.2rem;
border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 8px;
}
.hero-img { width: 100%; height: 450px; object-fit: cover; border-radius: 24px; margin-bottom: 2.5rem; }
/* Custom Block Styles */
.blog-content h2 { margin: 2.5rem 0 1rem; font-size: 2rem; }
.blog-content p { margin-bottom: 1.5rem; color: #374151; font-size: 1.15rem; }
.blog-content .note, .blog-content .warn, .blog-content .success {
padding: 1.2rem 1.5rem; border-radius: 12px; margin: 1.5rem 0; border-left: 5px solid;
}
.blog-content .note { background: var(--note); border-color: #3b82f6; }
.blog-content .warn { background: var(--warn); border-color: #f59e0b; }
.blog-content .success { background: var(--success); border-color: #10b981; }
.blog-content pre {
background: #1e293b; color: #f8fafc; padding: 1.5rem;
border-radius: 12px; overflow-x: auto; margin: 1.5rem 0; font-family: 'Consolas', monospace;
}
.blog-content table { width: 100%; border-collapse: collapse; margin: 2rem 0; }
.blog-content td { border: 1px solid var(--border); padding: 12px; }
.blog-content blockquote { border-left: 4px solid var(--accent); padding-left: 1.5rem; font-style: italic; color: var(--muted); margin: 2rem 0; }
@keyframes slideIn { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: translateX(0); } }
</style>
</head>
<body>
<header>
<div style="font-weight: 800; font-size: 1.5rem; letter-spacing: -1.5px;">CORE.</div>
<div class="search-box">
<i data-lucide="search"></i>
<input type="text" id="search" placeholder="Search blogs...">
</div>
<button class="cat-panel-btn" id="catBtn">
<i data-lucide="filter"></i> <span>Topics</span>
</button>
</header>
<div id="cat-panel">
<h4 style="font-size: 0.8rem; color: var(--muted); margin-bottom: 1rem; text-transform: uppercase;">Categories</h4>
<div id="cat-list" class="card-tags"></div>
</div>
<main>
<div class="blog-grid" id="grid">
<!-- JS injection -->
</div>
</main>
<div id="full-view">
<button class="back-btn" id="backBtn"><i data-lucide="arrow-left"></i> Back</button>
<div class="article-container" id="articleBody">
<!-- JS injection -->
</div>
</div>
<script>
const DATA_INDEX = "https://raw.githubusercontent.com/MainRoute-Core/blog/refs/heads/output/blogs.json";
let blogs = [];
// --- PARSER LOGIC (Exact match to Builder) ---
function customSyntaxToHtml(txt) {
if(!txt) return "";
let s = txt;
// Escape standard HTML tags
s = s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
// Block elements
s = s.replace(/\\h2:([\s\S]*?):h2\\/g, "<h2>$1</h2>");
s = s.replace(/\\h3:([\s\S]*?):h3\\/g, "<h3>$1</h3>");
s = s.replace(/\\h4:([\s\S]*?):h4\\/g, "<h4>$1</h4>");
s = s.replace(/\\p:([\s\S]*?):p\\/g, "<p>$1</p>");
s = s.replace(/\\quote:([\s\S]*?):quote\\/g, "<blockquote>$1</blockquote>");
// Complex blocks
s = s.replace(/\\note:([\s\S]*?):note\\/g, '<div class="note">$1</div>');
s = s.replace(/\\warn:([\s\S]*?):warn\\/g, '<div class="warn">$1</div>');
s = s.replace(/\\success:([\s\S]*?):success\\/g, '<div class="success">$1</div>');
s = s.replace(/\\code=([a-z0-9]*):\n([\s\S]*?)\n?:code\\/gi, '<pre><code>$2</code></pre>');
s = s.replace(/\\code:\n([\s\S]*?)\n?:code\\/gi, '<pre><code>$1</code></pre>');
s = s.replace(/\\tbl:\n([\s\S]*?)\n?:tbl\\/g, (_, t) => {
let rows = t.trim().split('\n');
let h = '<table><tbody>';
rows.forEach(r => h += '<tr>' + r.split('|').map(c => `<td>${c}</td>`).join('') + '</tr>');
return h + '</tbody></table>';
});
// Inline elements
s = s.replace(/\\b:([\s\S]*?):b\\/g, "<strong>$1</strong>");
s = s.replace(/\\i:([\s\S]*?):i\\/g, "<em>$1</em>");
s = s.replace(/\\u:([\s\S]*?):u\\/g, "<u>$1</u>");
s = s.replace(/\\s:([\s\S]*?):s\\/g, "<s>$1</s>");
s = s.replace(/\\ic:([\s\S]*?):ic\\/g, "<code>$1</code>");
s = s.replace(/\\a=([^\s:]+):([\s\S]*?):a\\/g, '<a href="$1" target="_blank">$2</a>');
s = s.replace(/\\img=([^\s:]+):([\s\S]*?):img\\/g, '<img src="$1" alt="$2" class="content-img">');
s = s.replace(/\\hr\\/g, "<hr>");
return s;
}
// --- CORE SPA LOGIC ---
async function load() {
lucide.createIcons();
const res = await fetch(DATA_INDEX);
blogs = await res.json();
renderCards(blogs);
renderCategories();
handleUrlParams();
}
function renderCards(data) {
const grid = document.getElementById('grid');
grid.innerHTML = data.map(b => `
<div class="card" onclick="openBlog('${b.id}', '${b.Url}')">
<div class="card-status">${b.Status || 'Published'}</div>
<h2 class="card-title">${b.Name}</h2>
<div style="font-size: 0.8rem; color: var(--muted);">${b.Date}</div>
<div class="card-tags">
${b.Tags.map(t => `<span class="tag">${t}</span>`).join('')}
</div>
</div>
`).join('');
}
function renderCategories() {
const list = document.getElementById('cat-list');
const tags = [...new Set(blogs.flatMap(b => b.Tags))];
list.innerHTML = `<span class="tag active" onclick="filterByTag(null, this)">All</span>` +
tags.map(t => `<span class="tag" onclick="filterByTag('${t}', this)">${t}</span>`).join('');
}
async function openBlog(id, url) {
const view = document.getElementById('full-view');
const body = document.getElementById('articleBody');
// Set loading and URL
body.innerHTML = "<h2>Loading...</h2>";
view.classList.add('active');
document.body.style.overflow = 'hidden';
window.history.pushState({id}, '', `?blog=${id}`);
try {
const res = await fetch(url);
const blogData = await res.json();
body.innerHTML = `
${blogData.Img ? `<img src="${blogData.Img}" class="hero-img">` : ''}
<div class="card-status">${blogData.Status}</div>
<h1 style="font-size: 3rem; line-height: 1.1; margin-bottom: 1rem;">${blogData.Title}</h1>
<p style="color: var(--muted); font-weight: 500;">${blogData.Date} • By Core Admin</p>
<div class="blog-content" style="margin-top: 3rem;">
${customSyntaxToHtml(blogData.Data)}
</div>
`;
} catch (e) {
body.innerHTML = "<h2>Error loading post.</h2>";
}
}
// --- Event Listeners ---
document.getElementById('backBtn').onclick = () => {
document.getElementById('full-view').classList.remove('active');
document.body.style.overflow = 'auto';
window.history.pushState({}, '', window.location.origin + window.location.pathname);
};
document.getElementById('search').oninput = (e) => {
const q = e.target.value.toLowerCase();
const filtered = blogs.filter(b => b.Name.toLowerCase().includes(q) || b.Tags.join(' ').toLowerCase().includes(q));
renderCards(filtered);
};
function filterByTag(tag, el) {
document.querySelectorAll('#cat-list .tag').forEach(t => t.classList.remove('active'));
el.classList.add('active');
const filtered = tag ? blogs.filter(b => b.Tags.includes(tag)) : blogs;
renderCards(filtered);
}
function handleUrlParams() {
const id = new URLSearchParams(window.location.search).get('blog');
if (id) {
const b = blogs.find(x => x.id === id);
if (b) openBlog(b.id, b.Url);
}
}
document.getElementById('catBtn').onclick = () => document.getElementById('cat-panel').classList.toggle('active');
load();
</script>
</body>
</html>