-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-pages.js
More file actions
332 lines (286 loc) ยท 13.4 KB
/
Copy pathgenerate-pages.js
File metadata and controls
332 lines (286 loc) ยท 13.4 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
'use strict';
/**
* generate-pages.js โ GitHub Pages ้ๆๆฅๆฅ็ๆๅจ
*
* ไป Supabase ่ฏปๅ่ฟ 30 ๅคฉ้่ฆๆ
ๆฅ๏ผ็ๆ docs/index.html
* ไพ GitHub Pages ๅ
ฌๅผๅฑ็คบ๏ผ่ฎฉ้ข่ฏๅฎ / ๅไฝๆน็ดๆฅ็ๅฐ็ณป็ปๅฎ้
่พๅบใ
*
* ็จๆณ๏ผ
* node generate-pages.js
* node generate-pages.js --days=7
*/
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const { createClient } = require('@supabase/supabase-js');
const DAYS = parseInt(process.argv.find(a => a.startsWith('--days='))?.split('=')[1] || '30', 10);
const DOCS = path.join(__dirname, 'docs');
const REPORTS = path.join(DOCS, 'reports');
// โโ Supabase โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_KEY,
);
// โโ ๆฐๆฎ่ทๅ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function fetchRecentNews(days) {
const since = Date.now() - days * 86400000;
const { data, error } = await supabase
.from('news')
.select('id,title,detail,source,timestamp,business_category,alpha_score,is_important,impact,bitv_action,url')
.gte('timestamp', since)
.or('alpha_score.gte.60,is_important.eq.1')
.order('timestamp', { ascending: false })
.limit(500);
if (error) throw new Error(`Supabase error: ${error.message}`);
return data || [];
}
// โโ ๅทฅๅ
ท โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function bjDate(ts) {
return new Date(ts + 8 * 3600000).toISOString().slice(0, 10);
}
function formatTime(ts) {
return new Date(ts).toLocaleTimeString('zh-CN', { timeZone: 'Asia/Shanghai', hour: '2-digit', minute: '2-digit' });
}
function scoreColor(s) {
if (s >= 90) return '#d32f2f';
if (s >= 75) return '#f57c00';
if (s >= 60) return '#388e3c';
return '#757575';
}
function scoreBadge(s) {
if (!s) return '';
const color = scoreColor(s);
return `<span style="display:inline-block;padding:1px 6px;border-radius:10px;font-size:11px;font-weight:700;background:${color}20;color:${color};border:1px solid ${color}50;">${s}</span>`;
}
function impactBadge(impact) {
const map = { 'ๅฉๅฅฝ': ['#388e3c', '๐'], 'ๅฉ็ฉบ': ['#d32f2f', '๐'], 'ไธญๆง': ['#757575', 'โก๏ธ'] };
const [color, icon] = map[impact] || ['#757575', ''];
return impact ? `<span style="font-size:11px;color:${color};">${icon} ${impact}</span>` : '';
}
function escHtml(str) {
return (str || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
const CATEGORY_ICONS = {
'ๅ่ง': 'โ๏ธ', 'RWA': '๐ข', '็จณๅฎๅธ/ๅนณๅฐๅธ': '๐ต',
'ๆ่่ต': '๐ฐ', 'ไบคๆ/้ๅ/AI': '๐ค', '้ฑๅ
/ๆฏไป': '๐ณ',
'toB/ๆบๆ': '๐ฆ', 'ๅ็บฆ': '๐', 'ๅ
ฌ้พ': '๐',
'ๆณๅธๅ
ๆข': '๐', '็่ดข': '๐', 'ๆๆฐ/็คพๅช/็คพ็พค/pr': '๐ฃ',
'็ป็บช/OTC/ๆ็ฎก': '๐ค', 'ๅคง้ถๆท/VIP': '๐', 'ๅญฆ้ข/็คพไบค/ๅ
ๅฎน/ๆดปๅจ': '๐',
};
// โโ HTML ็ๆ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function buildNewsCard(item) {
const cat = item.business_category || 'ๆชๅ็ฑป';
const icon = CATEGORY_ICONS[cat] || '๐ฐ';
const link = item.url ? `href="${escHtml(item.url)}" target="_blank" rel="noopener"` : '';
return `
<article class="card" data-score="${item.alpha_score || 0}" data-cat="${escHtml(cat)}">
<div class="card-meta">
<span class="cat-badge">${icon} ${escHtml(cat)}</span>
${scoreBadge(item.alpha_score)}
${impactBadge(item.impact)}
<span class="source-time">${escHtml(item.source)} ยท ${formatTime(item.timestamp)}</span>
</div>
<h3 class="card-title">
${link ? `<a ${link}>${escHtml(item.title)}</a>` : escHtml(item.title)}
</h3>
${item.detail ? `<p class="card-detail">${escHtml(item.detail)}</p>` : ''}
${item.bitv_action ? `<div class="card-action">๐ก ${escHtml(item.bitv_action)}</div>` : ''}
</article>`;
}
function buildDayPage(dateStr, items, allDates) {
const dateLabel = new Date(dateStr + 'T12:00:00+08:00').toLocaleDateString('zh-CN', {
year: 'numeric', month: 'long', day: 'numeric', weekday: 'long',
});
const top = items.filter(i => i.alpha_score >= 75);
const others = items.filter(i => i.alpha_score < 75 || !i.alpha_score);
const archiveLinks = allDates.map(d => {
const active = d === dateStr ? ' class="active"' : '';
return `<a href="${d}.html"${active}>${d}</a>`;
}).join('\n');
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Web3Watch HK | ${dateStr}</title>
${commonStyles()}
</head>
<body>
${header(dateStr)}
<div class="layout">
<aside class="sidebar">
<h4>๐
ๅๅฒๅญๆกฃ</h4>
<nav class="archive-nav">${archiveLinks}</nav>
<div class="sidebar-foot">
<a href="https://github.com/Beltran12138/Web3Watch-HK" target="_blank" rel="noopener">GitHub โ</a>
</div>
</aside>
<main>
<h2 class="day-title">${dateLabel}</h2>
<p class="day-stats">ๅ
ฑ <strong>${items.length}</strong> ๆกๆ
ๆฅ ยท ้่ฆ <strong>${top.length}</strong> ๆก</p>
${top.length > 0 ? `<h3 class="section-head">๐ฅ ้่ฆๅจๆ</h3>${top.map(buildNewsCard).join('')}` : ''}
${others.length > 0 ? `<h3 class="section-head">๐ก ๅ
ถไปๅจๆ</h3>${others.map(buildNewsCard).join('')}` : ''}
</main>
</div>
${footer()}
</body>
</html>`;
}
function buildIndexPage(today, items, allDates, stats) {
const dateLabel = new Date(today + 'T12:00:00+08:00').toLocaleDateString('zh-CN', {
year: 'numeric', month: 'long', day: 'numeric', weekday: 'long',
});
const top = items.filter(i => i.alpha_score >= 75);
const others = items.filter(i => i.alpha_score < 75 || !i.alpha_score);
const archiveLinks = allDates.map(d => {
const active = d === today ? ' class="active"' : '';
return `<a href="reports/${d}.html"${active}>${d}</a>`;
}).join('\n');
return `<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Web3Watch HK โ ้ฆๆธฏ Web3 ่กไธๆ
ๆฅ็ณป็ป</title>
${commonStyles()}
</head>
<body>
${header(today)}
<div class="hero-stats">
<div class="stat"><span>${stats.sources}</span>ๆฐๆฎๆบ</div>
<div class="stat"><span>${stats.total30d}+</span>่ฟ30ๅคฉๆ
ๆฅ</div>
<div class="stat"><span>${stats.important30d}</span>้่ฆไบไปถ</div>
<div class="stat"><span>ๆฏ15ๅ้</span>ๆดๆฐ้ข็</div>
</div>
<div class="layout">
<aside class="sidebar">
<h4>๐
ๅๅฒๅญๆกฃ</h4>
<nav class="archive-nav">${archiveLinks}</nav>
<div class="sidebar-foot">
<a href="https://github.com/Beltran12138/Web3Watch-HK" target="_blank" rel="noopener">GitHub โ</a>
</div>
</aside>
<main>
<h2 class="day-title">ไปๆฅๆ
ๆฅ ยท ${dateLabel}</h2>
<p class="day-stats">ๅ
ฑ <strong>${items.length}</strong> ๆกๆ
ๆฅ ยท ้่ฆ <strong>${top.length}</strong> ๆก</p>
${top.length > 0 ? `<h3 class="section-head">๐ฅ ้่ฆๅจๆ</h3>${top.map(buildNewsCard).join('')}` : '<p class="empty">ไปๆฅๆๆ ้ซๅๆ
ๆฅ</p>'}
${others.length > 0 ? `<h3 class="section-head">๐ก ๅ
ถไปๅจๆ</h3>${others.map(buildNewsCard).join('')}` : ''}
</main>
</div>
${footer()}
</body>
</html>`;
}
function commonStyles() {
return `<style>
*{box-sizing:border-box;margin:0;padding:0}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif;background:#f5f7fa;color:#1a1a2e;min-height:100vh}
a{color:#00A7E1;text-decoration:none}a:hover{text-decoration:underline}
/* Header */
.site-header{background:linear-gradient(135deg,#00A7E1 0%,#0077b6 100%);color:#fff;padding:20px 32px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px}
.site-header h1{font-size:20px;font-weight:700;letter-spacing:.5px}
.header-meta{font-size:12px;opacity:.85}
.header-nav a{color:#fff;margin-left:16px;font-size:13px;opacity:.9}
/* Hero Stats */
.hero-stats{display:flex;gap:0;background:#fff;border-bottom:1px solid #e8edf2;justify-content:center}
.stat{flex:1;text-align:center;padding:16px 8px;border-right:1px solid #e8edf2}
.stat:last-child{border-right:none}
.stat span{display:block;font-size:24px;font-weight:700;color:#00A7E1}
.stat{font-size:12px;color:#666}
/* Layout */
.layout{display:grid;grid-template-columns:200px 1fr;gap:0;max-width:1200px;margin:24px auto;padding:0 16px}
/* Sidebar */
.sidebar{padding:0 16px 0 0}
.sidebar h4{font-size:12px;text-transform:uppercase;letter-spacing:.8px;color:#999;margin-bottom:10px}
.archive-nav{display:flex;flex-direction:column;gap:4px}
.archive-nav a{display:block;padding:5px 10px;border-radius:6px;font-size:13px;color:#555;transition:.15s}
.archive-nav a:hover{background:#e8f4fb;color:#00A7E1;text-decoration:none}
.archive-nav a.active{background:#00A7E1;color:#fff;font-weight:600}
.sidebar-foot{margin-top:20px;font-size:12px}
/* Main */
main{min-width:0}
.day-title{font-size:18px;font-weight:700;color:#1a1a2e;margin-bottom:4px}
.day-stats{font-size:13px;color:#888;margin-bottom:20px}
.section-head{font-size:13px;text-transform:uppercase;letter-spacing:.6px;color:#999;margin:20px 0 10px;padding-bottom:6px;border-bottom:1px solid #e8edf2}
/* Card */
.card{background:#fff;border-radius:10px;padding:16px 18px;margin-bottom:12px;border:1px solid #e8edf2;transition:.2s;position:relative}
.card:hover{border-color:#00A7E1;box-shadow:0 2px 12px rgba(0,167,225,.08)}
.card-meta{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:8px}
.cat-badge{font-size:12px;background:#f0f9ff;color:#00A7E1;padding:2px 8px;border-radius:10px;border:1px solid #bee3f8}
.source-time{font-size:11px;color:#aaa;margin-left:auto}
.card-title{font-size:14px;font-weight:600;line-height:1.5;color:#1a1a2e;margin-bottom:6px}
.card-title a{color:#1a1a2e}
.card-title a:hover{color:#00A7E1;text-decoration:none}
.card-detail{font-size:13px;color:#555;line-height:1.7;margin-bottom:6px}
.card-action{font-size:12px;color:#666;background:#fffbf0;border-left:3px solid #f5a623;padding:6px 10px;border-radius:0 4px 4px 0;margin-top:6px}
/* Footer */
.site-footer{background:#1a1a2e;color:#aaa;text-align:center;padding:20px;font-size:12px;margin-top:40px}
.site-footer a{color:#00A7E1}
.empty{color:#aaa;font-size:13px;padding:20px 0}
@media(max-width:700px){
.layout{grid-template-columns:1fr}
.sidebar{padding:0 0 16px;margin-bottom:16px;border-bottom:1px solid #e8edf2}
.archive-nav{flex-direction:row;flex-wrap:wrap}
.hero-stats{flex-wrap:wrap}
.stat{min-width:50%}
}
</style>`;
}
function header(dateStr) {
const now = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' });
return `<header class="site-header">
<h1>๐ญ Web3Watch HK ๆ
ๆฅ็ณป็ป</h1>
<div class="header-meta">ๆๅๆดๆฐ๏ผ${now}</div>
<nav>
<a class="header-nav" href="https://github.com/Beltran12138/Web3Watch-HK" target="_blank" rel="noopener">GitHub</a>
</nav>
</header>`;
}
function footer() {
return `<footer class="site-footer">
Web3Watch HK ยท ไบงๅ้จ่ก็ ็ป ยท
<a href="https://github.com/Beltran12138/Web3Watch-HK" target="_blank" rel="noopener">GitHub</a>
ยท ๆฐๆฎ็ฑ DeepSeek AI ๅๆ ยท ๆฏๆฅ 18:00 BJ ๆดๆฐ
</footer>`;
}
// โโ ไธปๆต็จ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
(async () => {
console.log(`[Pages] Fetching last ${DAYS} days from Supabaseโฆ`);
const news = await fetchRecentNews(DAYS);
console.log(`[Pages] ${news.length} items fetched`);
// ๆๆฅๆๅๆกถ
const byDate = {};
for (const item of news) {
const d = bjDate(item.timestamp);
if (!byDate[d]) byDate[d] = [];
byDate[d].push(item);
}
const allDates = Object.keys(byDate).sort().reverse();
const today = allDates[0] || bjDate(Date.now());
// ็ป่ฎก
const stats = {
sources: new Set(news.map(n => n.source)).size,
total30d: news.length,
important30d: news.filter(n => n.is_important || n.alpha_score >= 75).length,
};
// ็กฎไฟ็ฎๅฝๅญๅจ
fs.mkdirSync(DOCS, { recursive: true });
fs.mkdirSync(REPORTS, { recursive: true });
// ็ๆๆฏๆฅๅญๆกฃ้กต
for (const [date, items] of Object.entries(byDate)) {
const html = buildDayPage(date, items, allDates);
fs.writeFileSync(path.join(REPORTS, `${date}.html`), html, 'utf8');
console.log(`[Pages] reports/${date}.html (${items.length} items)`);
}
// ็ๆ้ฆ้กต
const todayItems = byDate[today] || [];
const indexHtml = buildIndexPage(today, todayItems, allDates, stats);
fs.writeFileSync(path.join(DOCS, 'index.html'), indexHtml, 'utf8');
console.log(`[Pages] docs/index.html โ today=${today}, ${todayItems.length} items`);
// .nojekyll ้ปๆญข GitHub Pages ็ Jekyll ๅค็
fs.writeFileSync(path.join(DOCS, '.nojekyll'), '', 'utf8');
console.log(`[Pages] Done. ${allDates.length} day pages + index.`);
})().catch(err => {
console.error('[Pages] Fatal:', err.message);
process.exit(1);
});