-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathrender.ts
More file actions
1538 lines (1448 loc) · 49.4 KB
/
Copy pathrender.ts
File metadata and controls
1538 lines (1448 loc) · 49.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
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
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type {
ArticleInput,
BriefItem,
DailyReport,
TradingSection,
} from "../ai/pipeline";
import type { WatchlistPick } from "../ai/trading-commentary";
import { REPORT_LOCALE } from "../sources/registry";
import { getReportTz } from "../utils";
import type { Category, SourceDef } from "../sources/types";
import { V2EX_OFF_TOPIC_RE } from "../sources/v2ex";
import type { TickerAnalysis } from "../trading/signals";
import {
getAssetGroupLabels,
ASSET_GROUP_ORDER,
type AssetGroup,
} from "../trading/watchlist";
// ----- i18n -----
/**
* Localized UI strings. `t` resolves to TEXTS_ZH or TEXTS_EN at module
* init based on REPORT_LOCALE. All hardcoded display text routes through
* this object so adding a third locale = adding one more table.
*/
const TEXTS_ZH = {
siteTitle: "每日简报",
catTech: "技术动态",
catFinance: "财经要点",
catPolitics: "时政观察",
catTrading: "市场行情",
catCommunity: "社区讨论",
subAiNews: "AI 媒体",
subTrendingPapers: "热门论文",
subXViral: "X 推文",
subBlogWeekly: "博客周刊",
subCnCommunity: "中文社区",
subOverseasCommunity: "海外社区",
subFinanceNews: "财经新闻",
subFinanceCommunity: "社区讨论",
subWorld: "国际要闻",
subOverseasNews: "海外科技",
subOverseas: "海外",
emptySource: "该源今日无内容。",
emptyCategory: "该分类今日无内容。",
emptyGroup: "该组今日无数据。",
footer: "内容均来自原媒体,本站仅作摘要整理与回链。",
summaryLabelNews: "中文摘要",
summaryLabelIntro: "中文介绍",
tradingMarketOverview: "市场总览",
tradingTodayFocus: "今日关注",
tradingAllAssets: "全部资产",
tradingRiskCaveat: "风险提示",
widgetCryptoFearGreed: "加密恐慌贪婪",
widgetCryptoCap: "加密总市值",
widgetBtcDom: "BTC 主导率",
widgetVolume24h: "24h 成交量",
widgetActiveCoins: "活跃币",
ticker5d: "5 日",
tickerVs52wHigh: "距 52w 高",
tickerTrend: "趋势",
tickerMacd: "MACD / 信号",
signalToday: "今天",
signalDaysAgoSuffix: "天前",
trendBullish: "多头",
trendBearish: "空头",
trendNeutral: "中性",
mdTodayOverview: "今日总览",
mdEditorNote: "编辑短评",
mdTodayKeywords: "今日关键词",
mdImportance: "重要度",
archiveLink: "← 历史归档",
};
const TEXTS_EN: typeof TEXTS_ZH = {
siteTitle: "Daily Brief",
catTech: "Tech",
catFinance: "Finance",
catPolitics: "World",
catTrading: "Markets",
catCommunity: "Community",
subAiNews: "AI Media",
subTrendingPapers: "Trending Papers",
subXViral: "X Viral",
subBlogWeekly: "Blog Weekly",
subCnCommunity: "Chinese Community",
subOverseasCommunity: "Overseas Community",
subFinanceNews: "Finance News",
subFinanceCommunity: "Community",
subWorld: "World News",
subOverseasNews: "Overseas Tech",
subOverseas: "Overseas",
emptySource: "No content from this source today.",
emptyCategory: "No content in this category today.",
emptyGroup: "No data for this group today.",
footer:
"Content sourced from original publishers; this site provides summary and backlinks only.",
summaryLabelNews: "Summary",
summaryLabelIntro: "Summary",
tradingMarketOverview: "Market Overview",
tradingTodayFocus: "Today's Focus",
tradingAllAssets: "All Assets",
tradingRiskCaveat: "Risk Disclaimer",
widgetCryptoFearGreed: "Crypto Fear/Greed",
widgetCryptoCap: "Crypto Market Cap",
widgetBtcDom: "BTC Dominance",
widgetVolume24h: "24h Volume",
widgetActiveCoins: "Active coins",
ticker5d: "5d",
tickerVs52wHigh: "vs 52w High",
tickerTrend: "Trend",
tickerMacd: "MACD / Signal",
signalToday: "today",
signalDaysAgoSuffix: "d ago",
trendBullish: "Bullish",
trendBearish: "Bearish",
trendNeutral: "Neutral",
mdTodayOverview: "Today's Overview",
mdEditorNote: "Editor's Note",
mdTodayKeywords: "Keywords",
mdImportance: "Importance",
archiveLink: "← Archive",
};
const STR = REPORT_LOCALE === "en" ? TEXTS_EN : TEXTS_ZH;
const ASSET_GROUP_LABELS_LOCALIZED = getAssetGroupLabels(REPORT_LOCALE);
// ----- types -----
export type SourceGroup = {
sourceId: string;
sourceName: string;
items: ArticleInput[];
/**
* When true, items come from multiple merged sources and the renderer
* should label each article with `a.source` since the source-tab row
* is suppressed (only one synthetic group).
*/
merged?: boolean;
};
export type SubGroup = {
id: string;
name: string;
sources: SourceGroup[];
};
export type RawByCategory = Record<Category, SubGroup[]>;
// ----- labels & ordering -----
const CATEGORY_LABELS: Record<Category, string> = {
tech: STR.catTech,
finance: STR.catFinance,
politics: STR.catPolitics,
};
const CATEGORY_DIGEST_LABELS: Record<Category, string> = {
tech: STR.catTech,
finance: STR.catFinance,
politics: STR.catPolitics,
};
/**
* L2 ordering per category. Categories not listed render flat (no L2 tabs).
*/
const SUBCATEGORY_ORDER: Partial<Record<Category, string[]>> = {
// cn-community + overseas-community are listed last so the L1 "community"
// panel (rendered separately via TECH_COMMUNITY_SUBS) can extract them.
// Within the "tech" L1 panel itself, COMMUNITY_SUBS is filtered out.
// Locale filtering at registry level decides which actually appears:
// zh mode keeps cn-community (V2EX / LinuxDo); en mode keeps
// overseas-community (Hacker News / r/stocks).
tech: ["github-trending", "trending-papers", "x-viral", "ai-news", "cn-community", "overseas-community"],
finance: ["news"],
politics: ["world"],
};
const TECH_MAIN_SUBS = new Set(["github-trending", "trending-papers", "x-viral", "ai-news"]);
const TECH_COMMUNITY_SUBS = new Set(["cn-community", "overseas-community"]);
const SUBCATEGORY_LABELS: Record<string, string> = {
"github-trending": "GitHub Trending",
"trending-papers": STR.subTrendingPapers,
"cn-community": STR.subCnCommunity,
"overseas-community": STR.subOverseasCommunity,
"ai-news": STR.subAiNews,
"x-viral": STR.subXViral,
"blog-weekly": STR.subBlogWeekly,
news: STR.subFinanceNews,
world: STR.subWorld,
};
/**
* Per-source item caps in the raw display, keyed by "category:subcategory".
* Each source inside the subcategory shows up to N items. Missing keys = no cap.
*
* Default 20 across all L3-tabbed subcategories keeps each tab a single
* comfortable scroll instead of 25-30 items. Merged subgroups (blog-weekly,
* finance:news, politics:world) ignore this — they use MERGED_SUBGROUP_LIMITS.
*/
const SOURCE_DISPLAY_LIMITS: Record<string, number> = {
"tech:github-trending": 20,
"tech:cn-community": 10,
"tech:x-viral": 20,
"tech:trending-papers": 20,
};
/**
* Sources whose fetcher returns items already sorted by an engagement/heat
* algorithm we want to preserve. groupRaw skips its default date-desc sort
* for these so the final render reflects the source's own ranking.
*/
const PRESERVE_FETCH_ORDER_SOURCES = new Set([
"attentionvc-ai",
"huggingface-papers",
]);
function displayLimitFor(
category: Category,
subId: string | undefined,
): number | undefined {
if (!subId) return undefined;
return SOURCE_DISPLAY_LIMITS[`${category}:${subId}`];
}
/**
* Subcategories that should collapse their sources into a single flat
* time-sorted list (no L3 source tabs), keyed by "category:subcategory".
* Value = number of items kept after merging. Each rendered article
* will display its `source` label inline since the per-source tab row
* is suppressed.
*
* Used when:
* - sources are heterogeneous but each publishes few items (blog-weekly)
* - the user explicitly wants a curated time-sorted feed rather than
* per-source browsing (finance:news, only authoritative sources)
*
* Exported so daily.ts can read the cap to keep enrichment in sync.
*/
export const MERGED_SUBGROUP_LIMITS: Record<string, number> = {
"tech:ai-news": 15,
"finance:news": 12,
"politics:world": 15,
};
/**
* Politics sources (especially Al Jazeera / BBC / The Diplomat) regularly
* mix in World Cup / Olympic / football coverage. Filter at the title level
* so the merged "国际要闻" stream stays politics-only.
*
* Pattern is intentionally specific — avoid generic words like "team" or
* "match" that overlap with diplomacy headlines.
*/
const POLITICS_SPORTS_RE =
/\b(World\s*Cup|Olympics?|UEFA|FIFA|NBA|NFL|NHL|MLB|ATP|WTA|Premier\s*League|Bundesliga|La\s*Liga|Serie\s*A|Champions\s*League|Eurovision|Wimbledon|Grand\s*Slam|F1|Formula\s*1|Ronaldo|Messi|Mbappe|Beckham|Lukaku|Mitoma|sportsman|footballer|squad)\b|世界杯|奥运|残奥|冬奥|欧冠|英超|西甲|意甲|德甲|网球|足球|篮球|高尔夫|棒球|板球|橄榄球/i;
export function isSportsArticle(title: string): boolean {
return POLITICS_SPORTS_RE.test(title);
}
function mergedLimitFor(
category: Category,
subId: string,
): number | undefined {
return MERGED_SUBGROUP_LIMITS[`${category}:${subId}`];
}
// ----- grouping -----
export function groupRaw(
articles: ArticleInput[],
registry: SourceDef[],
): RawByCategory {
const subcatOf = new Map<string, string | undefined>();
for (const s of registry) subcatOf.set(s.id, s.subcategory);
// Drop articles from sources that have since been disabled — important
// when scripts/render.ts re-renders against a stale sidecar that still
// contains the disabled sources' fetched data.
const enabledIds = new Set(
registry.filter((s) => s.enabled !== false).map((s) => s.id),
);
type Bucket = { sourceName: string; items: ArticleInput[] };
const buckets: Record<Category, Map<string, Bucket>> = {
tech: new Map(),
finance: new Map(),
politics: new Map(),
};
// Pre-seed empty buckets for every enabled source so per-source-tabbed
// subcategories (e.g. cn-community) still render a tab for sources that
// returned 0 items today. Without this, a transient LinuxDo Cloudflare
// block would silently collapse the L3 tab nav, making users wonder
// whether the other forum even exists.
for (const s of registry) {
if (s.enabled === false) continue;
if (!buckets[s.category].has(s.id)) {
buckets[s.category].set(s.id, { sourceName: s.name, items: [] });
}
}
for (const a of articles) {
if (!enabledIds.has(a.sourceId)) continue;
if (a.category === "politics" && isSportsArticle(a.title)) continue;
if (
(a.sourceId === "v2ex-hot" || a.sourceId === "linuxdo") &&
V2EX_OFF_TOPIC_RE.test(a.title)
)
continue;
const map = buckets[a.category];
let b = map.get(a.sourceId);
if (!b) {
b = { sourceName: a.source, items: [] };
map.set(a.sourceId, b);
}
b.items.push(a);
}
for (const cat of Object.keys(buckets) as Category[]) {
for (const [id, b] of buckets[cat].entries()) {
if (PRESERVE_FETCH_ORDER_SOURCES.has(id)) continue;
b.items.sort(
(a, b) =>
(b.publishedAt?.getTime() ?? 0) - (a.publishedAt?.getTime() ?? 0),
);
}
}
function toSourceGroup(
sourceId: string,
b: Bucket,
limit: number | undefined,
): SourceGroup {
return {
sourceId,
sourceName: b.sourceName,
items: limit ? b.items.slice(0, limit) : b.items,
};
}
function sortByRegistry(list: SourceGroup[]): SourceGroup[] {
return [...list].sort((a, b) => {
const ia = registry.findIndex((s) => s.id === a.sourceId);
const ib = registry.findIndex((s) => s.id === b.sourceId);
return ia - ib;
});
}
const out: RawByCategory = { tech: [], finance: [], politics: [] };
for (const cat of Object.keys(buckets) as Category[]) {
const order = SUBCATEGORY_ORDER[cat];
if (!order) {
// Flat: one synthetic subgroup with every source.
const sources: SourceGroup[] = [];
for (const [id, b] of buckets[cat].entries()) {
sources.push(toSourceGroup(id, b, undefined));
}
out[cat] = sources.length
? [{ id: "all", name: CATEGORY_LABELS[cat], sources: sortByRegistry(sources) }]
: [];
continue;
}
// Subcategory split: bucket each source under its registered subcategory.
const subs: SubGroup[] = [];
for (const subId of order) {
const mergeLimit = mergedLimitFor(cat, subId);
if (mergeLimit !== undefined) {
// Merge: flatten all sources under this subcategory into a single
// time-sorted SourceGroup. Articles keep their `source` field so
// the renderer can label them.
const flat: ArticleInput[] = [];
for (const [id, b] of buckets[cat].entries()) {
if (subcatOf.get(id) === subId) flat.push(...b.items);
}
if (flat.length === 0) continue;
flat.sort(
(a, b) =>
(b.publishedAt?.getTime() ?? 0) - (a.publishedAt?.getTime() ?? 0),
);
subs.push({
id: subId,
name: SUBCATEGORY_LABELS[subId] ?? subId,
sources: [
{
sourceId: "_merged",
sourceName: SUBCATEGORY_LABELS[subId] ?? subId,
items: flat.slice(0, mergeLimit),
merged: true,
},
],
});
continue;
}
const limit = displayLimitFor(cat, subId);
const sources: SourceGroup[] = [];
for (const [id, b] of buckets[cat].entries()) {
if (subcatOf.get(id) === subId) sources.push(toSourceGroup(id, b, limit));
}
if (sources.length === 0) continue;
subs.push({
id: subId,
name: SUBCATEGORY_LABELS[subId] ?? subId,
sources: sortByRegistry(sources),
});
}
out[cat] = subs;
}
return out;
}
// ----- HTML helpers -----
function escapeHtml(s: string): string {
return s
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function formatDate(d: Date | undefined): string {
if (!d) return "";
try {
// zh: "05/20 16:00" · en: "May 20, 4:00 PM" → keep 24h en-GB style "20/05 16:00"
const localeTag = REPORT_LOCALE === "en" ? "en-GB" : "zh-CN";
return d.toLocaleString(localeTag, {
timeZone: getReportTz(),
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: false,
});
} catch {
return "";
}
}
// ----- raw article renderers -----
function renderArticleHtml(a: ArticleInput, showSource = false): string {
const title = escapeHtml(a.title);
const url = escapeHtml(a.url);
const excerpt = a.excerpt ? escapeHtml(a.excerpt) : "";
// Backwards-compat: old sidecar JSON files may carry `cnSummary` instead.
const summaryText = a.summary ?? (a as unknown as { cnSummary?: string }).cnSummary;
const summary = summaryText ? escapeHtml(summaryText) : "";
const meta = a.meta ? escapeHtml(a.meta) : "";
const time = formatDate(a.publishedAt);
const sourceLabel = showSource && a.source ? escapeHtml(a.source) : "";
const metaLine = [sourceLabel, time].filter(Boolean).join(" · ");
// News-style summary label for finance/politics, project-intro style for GH/tech.
const newsy = a.category === "finance" || a.category === "politics";
const summaryLabel = newsy ? STR.summaryLabelNews : STR.summaryLabelIntro;
return `<article class="article">
<h3 class="article-title"><a href="${url}" target="_blank" rel="noopener noreferrer">${title}</a></h3>
${meta ? `<p class="article-stats">${meta}</p>` : ""}
${metaLine ? `<p class="article-meta">${metaLine}</p>` : ""}
${excerpt ? `<p class="article-excerpt">${excerpt}</p>` : ""}
${summary ? `<p class="article-summary"><span class="summary-label">${summaryLabel}</span> ${summary}</p>` : ""}
</article>`;
}
function renderSourceContent(
category: Category,
subId: string,
source: SourceGroup,
isActive: boolean,
): string {
const showSource = source.merged === true;
return `<div class="source-content${isActive ? " active" : ""}" data-source-content="${escapeHtml(source.sourceId)}" data-sub="${escapeHtml(subId)}" data-cat="${category}">
${source.items.length === 0 ? `<p class="empty">${STR.emptySource}</p>` : source.items.map((a) => renderArticleHtml(a, showSource)).join("\n")}
</div>`;
}
function renderSourceTabs(
category: Category,
subId: string,
sources: SourceGroup[],
): string {
// Single-source L2s (X 推文 / GitHub Trending) skip the L3 row — the L2 tab
// label already identifies the dataset. L3 only earns its row when there
// are ≥2 sources to switch between (e.g. 社区讨论 V2EX vs LinuxDo).
if (sources.length < 2) return "";
return `<nav class="source-tabs">${sources
.map(
(s, i) =>
`<button class="source-tab${i === 0 ? " active" : ""}" data-source="${escapeHtml(s.sourceId)}" data-sub="${escapeHtml(subId)}" data-cat="${category}">${escapeHtml(s.sourceName)}<span class="count">${s.items.length}</span></button>`,
)
.join("")}</nav>`;
}
function renderSubContent(category: Category, sub: SubGroup, isActive: boolean): string {
return `<div class="sub-content${isActive ? " active" : ""}" data-sub-content="${escapeHtml(sub.id)}" data-cat="${category}">
${renderSourceTabs(category, sub.id, sub.sources)}
<div class="source-contents">
${sub.sources.map((s, i) => renderSourceContent(category, sub.id, s, i === 0)).join("\n")}
</div>
</div>`;
}
function renderRawCategoryPanel(
category: Category,
subs: SubGroup[],
): string {
if (subs.length === 0) {
return `<p class="empty">${STR.emptyCategory}</p>`;
}
if (subs.length === 1) {
return renderSubContent(category, subs[0], true);
}
const subTabs = subs
.map((s, i) => {
const count = s.sources.reduce((n, src) => n + src.items.length, 0);
return `<button class="sub-tab${i === 0 ? " active" : ""}" data-sub="${escapeHtml(s.id)}" data-cat="${category}">${escapeHtml(s.name)}<span class="count">${count}</span></button>`;
})
.join("");
const panels = subs
.map((s, i) => renderSubContent(category, s, i === 0))
.join("\n");
return `<nav class="sub-tabs">${subTabs}</nav>\n<div class="sub-contents">${panels}</div>`;
}
// ----- top-level renderer -----
export function renderHtml(
report: DailyReport,
raw: RawByCategory,
date: string,
): string {
const trading = report.trading;
// Split tech raw subgroups: "tech" L1 panel (github-trending + ai-news)
// vs. "community" L1 panel (cn-community). Keeps the registry simple
// (V2EX/LinuxDo still live under category=tech) while exposing the
// forums as their own top-level tab per UX preference.
const techMainSubs = raw.tech.filter((s) => TECH_MAIN_SUBS.has(s.id));
const techCommunitySubs = raw.tech.filter((s) => TECH_COMMUNITY_SUBS.has(s.id));
const sumItems = (subs: SubGroup[]) =>
subs.reduce(
(n, sg) => n + sg.sources.reduce((m, s) => m + s.items.length, 0),
0,
);
const counts = {
tech: sumItems(techMainSubs),
finance: sumItems(raw.finance),
politics: sumItems(raw.politics),
community: sumItems(techCommunitySubs),
};
return `<!doctype html>
<html lang="${REPORT_LOCALE === "en" ? "en" : "zh-CN"}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${STR.siteTitle} · ${date}</title>
<style>
:root {
--bg: #fafaf9;
--bg-elevated: #ffffff;
--fg: #18181b;
--fg-soft: #3f3f46;
--muted: #71717a;
--rule: #e4e4e7;
--card: #f4f4f5;
--link: #1d4ed8;
--accent: #18181b;
--accent-fg: #fafaf9;
--rank-high-bg: #fee2e2;
--rank-high-fg: #991b1b;
--rank-mid-bg: #fef3c7;
--rank-mid-fg: #92400e;
--rank-low-bg: #e0e7ff;
--rank-low-fg: #3730a3;
--hero-grad-from: #fafaf9;
--hero-grad-to: #f4f4f5;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0a0a0a;
--bg-elevated: #18181b;
--fg: #fafafa;
--fg-soft: #d4d4d8;
--muted: #a1a1aa;
--rule: #27272a;
--card: #18181b;
--link: #93c5fd;
--accent: #fafafa;
--accent-fg: #0a0a0a;
--rank-high-bg: rgba(239,68,68,0.18);
--rank-high-fg: #fca5a5;
--rank-mid-bg: rgba(245,158,11,0.18);
--rank-mid-fg: #fcd34d;
--rank-low-bg: rgba(99,102,241,0.18);
--rank-low-fg: #a5b4fc;
--hero-grad-from: #18181b;
--hero-grad-to: #0a0a0a;
}
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--fg);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
line-height: 1.6;
-webkit-font-smoothing: antialiased;
}
main { max-width: 960px; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; }
/* ===== header ===== */
header.report-header { margin-bottom: 1.25rem; }
.eyebrow {
font-size: 0.72rem;
text-transform: uppercase;
letter-spacing: 0.2em;
color: var(--muted);
font-weight: 500;
}
h1.report-title {
font-size: 2.2rem;
font-weight: 700;
margin: 0.4rem 0 1.2rem;
letter-spacing: -0.02em;
line-height: 1.1;
}
.archive-link {
display: inline-block;
margin-bottom: 1rem;
font-size: 0.85rem;
color: var(--muted);
text-decoration: none;
border-bottom: 1px dashed var(--rule);
padding-bottom: 1px;
}
.archive-link:hover { color: var(--accent); border-bottom-style: solid; }
.hero-card {
background: linear-gradient(135deg, var(--hero-grad-from) 0%, var(--hero-grad-to) 100%);
border: 1px solid var(--rule);
border-left: 4px solid var(--accent);
padding: 1rem 1.4rem;
border-radius: 0.6rem;
}
.hero-eyebrow {
font-size: 0.7rem;
letter-spacing: 0.2em;
text-transform: uppercase;
color: var(--muted);
font-weight: 500;
}
.hero-headline {
font-size: 1.25rem;
font-weight: 600;
margin: 0.35rem 0 0;
line-height: 1.45;
color: var(--fg);
}
.overview-card {
margin: 0.7rem 0 0;
padding: 0.7rem 1.1rem;
background: var(--card);
border-radius: 0.5rem;
border-left: 3px solid var(--muted);
}
.overview-card .eyebrow { display: block; margin-bottom: 0.3rem; }
.overview-text {
margin: 0;
font-size: 0.88rem;
line-height: 1.65;
color: var(--fg-soft);
}
/* ===== primary tabs ===== */
.tabs {
display: flex;
gap: 0.25rem;
margin: 1.25rem 0 0.75rem;
border-bottom: 1px solid var(--rule);
flex-wrap: wrap;
}
.tab {
background: none;
border: none;
padding: 0.7rem 1.1rem;
font-size: 0.95rem;
font-weight: 500;
color: var(--muted);
cursor: pointer;
border-bottom: 2px solid transparent;
margin-bottom: -1px;
font-family: inherit;
transition: color 0.15s;
}
.tab:hover { color: var(--fg); }
.tab.active {
color: var(--fg);
border-bottom-color: var(--accent);
}
.tab .count {
font-size: 0.72rem;
color: var(--muted);
margin-left: 0.4rem;
font-weight: 400;
}
.panel { display: none; }
.panel.active { display: block; }
/* ===== digest (AI 简报) — compact ===== */
.digest-category { margin-bottom: 1.1rem; }
.category-header {
display: flex;
align-items: baseline;
gap: 0.55rem;
margin: 0 0 0.55rem;
padding-bottom: 0.35rem;
border-bottom: 1px solid var(--rule);
}
.category-title {
font-size: 0.9rem;
font-weight: 600;
color: var(--fg);
margin: 0;
letter-spacing: 0.05em;
}
.category-count {
font-size: 0.7rem;
color: var(--muted);
background: var(--card);
padding: 0.12rem 0.45rem;
border-radius: 999px;
}
.brief-list {
display: grid;
grid-template-columns: 1fr;
gap: 0.5rem;
}
@media (min-width: 720px) {
.brief-list { grid-template-columns: 1fr 1fr; }
}
.brief {
background: var(--bg-elevated);
border: 1px solid var(--rule);
border-radius: 0.5rem;
padding: 0.7rem 0.95rem;
transition: border-color 0.15s, transform 0.15s;
}
.brief:hover {
border-color: var(--muted);
transform: translateY(-1px);
}
.brief-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.6rem;
margin-bottom: 0.3rem;
}
.brief-source {
font-size: 0.72rem;
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.06em;
font-weight: 500;
}
.brief-rank {
font-size: 0.7rem;
padding: 0.12rem 0.5rem;
border-radius: 999px;
font-weight: 600;
flex-shrink: 0;
}
.brief-rank.high { background: var(--rank-high-bg); color: var(--rank-high-fg); }
.brief-rank.mid { background: var(--rank-mid-bg); color: var(--rank-mid-fg); }
.brief-rank.low { background: var(--rank-low-bg); color: var(--rank-low-fg); }
.brief-title {
font-size: 0.98rem;
font-weight: 600;
margin: 0 0 0.3rem;
line-height: 1.35;
}
.brief-title a { color: var(--fg); text-decoration: none; }
.brief-title a:hover { color: var(--link); text-decoration: underline; }
.brief-summary {
margin: 0;
color: var(--fg-soft);
font-size: 0.86rem;
line-height: 1.55;
}
.editor-card {
background: var(--card);
border-left: 3px solid var(--muted);
border-radius: 0.5rem;
padding: 1rem 1.3rem;
margin: 1.5rem 0 1.2rem;
}
.editor-card .eyebrow { display: block; margin-bottom: 0.4rem; }
.editor-text {
margin: 0;
font-size: 0.95rem;
line-height: 1.7;
color: var(--fg);
}
.keywords { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1.5rem; }
.keyword {
background: var(--card);
color: var(--fg-soft);
padding: 0.25rem 0.7rem;
border-radius: 999px;
font-size: 0.8rem;
}
/* ===== L2 sub-tabs ===== */
.sub-tabs {
display: flex;
flex-wrap: wrap;
gap: 0.4rem;
margin: 1rem 0;
}
.sub-tab {
background: var(--card);
border: 1px solid transparent;
padding: 0.5rem 1.05rem;
border-radius: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: var(--fg-soft);
cursor: pointer;
font-family: inherit;
transition: all 0.15s;
}
.sub-tab:hover { border-color: var(--muted); color: var(--fg); }
.sub-tab.active {
background: var(--accent);
color: var(--accent-fg);
}
.sub-tab .count {
font-size: 0.7rem;
opacity: 0.75;
margin-left: 0.4rem;
font-weight: 400;
}
.sub-content { display: none; }
.sub-content.active { display: block; }
/* ===== L3 source-tabs ===== */
.source-tabs {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
margin: 0.9rem 0 1.3rem;
padding-bottom: 0.7rem;
border-bottom: 1px solid var(--rule);
}
.source-tab {
background: none;
border: 1px solid var(--rule);
padding: 0.35rem 0.85rem;
border-radius: 999px;
font-size: 0.83rem;
color: var(--fg-soft);
cursor: pointer;
font-family: inherit;
transition: all 0.15s;
}
.source-tab:hover { border-color: var(--muted); color: var(--fg); }
.source-tab.active {
background: var(--fg);
color: var(--bg);
border-color: var(--fg);
}
.source-tab .count {
font-size: 0.7rem;
opacity: 0.75;
margin-left: 0.3rem;
}
.source-content { display: none; }
.source-content.active { display: block; }
/* ===== article cards in raw panels ===== */
.article {
padding: 1rem 0;
border-bottom: 1px solid var(--rule);
}
.article:first-child { padding-top: 0; }
.article:last-child { border-bottom: none; }
.article-title {
font-size: 1rem;
margin: 0 0 0.3rem;
font-weight: 500;
line-height: 1.45;
}
.article-title a { color: var(--fg); text-decoration: none; }
.article-title a:hover { color: var(--link); text-decoration: underline; }
.article-meta { color: var(--muted); font-size: 0.76rem; margin: 0 0 0.35rem; }
.article-stats {
color: var(--muted);
font-size: 0.8rem;
margin: 0 0 0.4rem;
font-feature-settings: "tnum";
}
.article-excerpt {
margin: 0;
color: var(--fg-soft);
font-size: 0.9rem;
line-height: 1.6;
}
.article-summary {
margin: 0.55rem 0 0;
padding: 0.6rem 0.85rem;
background: var(--card);
border-left: 2px solid var(--link);
border-radius: 0.3rem;
font-size: 0.9rem;
line-height: 1.6;
color: var(--fg);
}
.summary-label {
display: inline-block;
font-size: 0.68rem;
color: var(--link);
margin-right: 0.4rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.empty {
color: var(--muted);
text-align: center;
padding: 2rem 0;
font-size: 0.9rem;
}
/* ===== trading panel ===== */
.crypto-widgets {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.55rem;
margin: 0.4rem 0 1.2rem;
}
@media (min-width: 720px) {
.crypto-widgets { grid-template-columns: repeat(4, 1fr); }
}
.crypto-widget {
background: var(--bg-elevated);
border: 1px solid var(--rule);
border-radius: 0.5rem;
padding: 0.7rem 0.85rem;
text-align: center;
}
.widget-label {
font-size: 0.7rem;
color: var(--muted);
text-transform: uppercase;
letter-spacing: 0.08em;
margin-bottom: 0.3rem;
}
.widget-value {
font-size: 1.5rem;
font-weight: 700;
font-variant-numeric: tabular-nums;
color: var(--fg);
line-height: 1.1;
}
.widget-sub {
font-size: 0.78rem;
color: var(--muted);
margin-top: 0.25rem;
}
.widget-sub.positive { color: #16a34a; }
.widget-sub.negative { color: #dc2626; }
@media (prefers-color-scheme: dark) {
.widget-sub.positive { color: #4ade80; }
.widget-sub.negative { color: #fca5a5; }
}
.crypto-widget.fg-fear-extreme { border-left: 4px solid #b91c1c; }
.crypto-widget.fg-fear-extreme .widget-value { color: #b91c1c; }
.crypto-widget.fg-fear { border-left: 4px solid #d97706; }
.crypto-widget.fg-fear .widget-value { color: #d97706; }
.crypto-widget.fg-neutral { border-left: 4px solid var(--muted); }
.crypto-widget.fg-greed { border-left: 4px solid #65a30d; }
.crypto-widget.fg-greed .widget-value { color: #65a30d; }
.crypto-widget.fg-greed-extreme { border-left: 4px solid #16a34a; }
.crypto-widget.fg-greed-extreme .widget-value { color: #16a34a; }
@media (prefers-color-scheme: dark) {
.crypto-widget.fg-fear-extreme .widget-value,
.crypto-widget.fg-fear .widget-value { color: #fca5a5; }
.crypto-widget.fg-greed .widget-value,
.crypto-widget.fg-greed-extreme .widget-value { color: #4ade80; }
}
.trading-overview-card {
margin: 0 0 1.5rem;