codeyear 0.2.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codeyear/__init__.py +3 -0
- codeyear/__main__.py +6 -0
- codeyear/card.py +720 -0
- codeyear/cli.py +450 -0
- codeyear/config.py +114 -0
- codeyear/github_public.py +590 -0
- codeyear/gui.py +960 -0
- codeyear/html_report.py +1663 -0
- codeyear/i18n.py +345 -0
- codeyear/keywords.py +98 -0
- codeyear/languages.py +132 -0
- codeyear/personas.py +171 -0
- codeyear/poster.py +992 -0
- codeyear/profile.py +180 -0
- codeyear/report_theme.py +890 -0
- codeyear/runner.py +304 -0
- codeyear/scanner.py +491 -0
- codeyear/server.py +293 -0
- codeyear/stats.py +736 -0
- codeyear/updater.py +238 -0
- codeyear/wizard.py +221 -0
- codeyear-0.2.14.dist-info/METADATA +559 -0
- codeyear-0.2.14.dist-info/RECORD +27 -0
- codeyear-0.2.14.dist-info/WHEEL +5 -0
- codeyear-0.2.14.dist-info/entry_points.txt +5 -0
- codeyear-0.2.14.dist-info/licenses/LICENSE +21 -0
- codeyear-0.2.14.dist-info/top_level.txt +1 -0
codeyear/report_theme.py
ADDED
|
@@ -0,0 +1,890 @@
|
|
|
1
|
+
"""New editorial theme and English edition for the CodeYear report."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import html as htmlmod
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
from .stats import ReportStats
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _human(n: int) -> str:
|
|
12
|
+
if n >= 10000:
|
|
13
|
+
return f"{n / 10000:.1f} 万"
|
|
14
|
+
return f"{n:,}"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _en_human(n: int) -> str:
|
|
18
|
+
if n >= 10000:
|
|
19
|
+
return f"{n / 1000:.0f}k"
|
|
20
|
+
return f"{n:,}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _comma(n: int) -> str:
|
|
24
|
+
return f"{n:,}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
CSS = r"""
|
|
28
|
+
<style id="v2">
|
|
29
|
+
:root{
|
|
30
|
+
--paper:#f5f2e9; --paper2:#ece8dc; --ink:#141413; --ink2:#3d3d3a;
|
|
31
|
+
--muted:#6f6a5e; --line:#d8d2c2; --line2:#c8c2b2;
|
|
32
|
+
--acc:#c8552f; --acc2:#a8431f;
|
|
33
|
+
--serif:Georgia,"Songti SC","SimSun","Noto Serif CJK SC",serif;
|
|
34
|
+
--sans:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei","PingFang SC",sans-serif;
|
|
35
|
+
--mono:"Cascadia Mono",Consolas,"SFMono-Regular",Menlo,monospace;
|
|
36
|
+
}
|
|
37
|
+
body{background:var(--paper);font-size:15.5px;line-height:1.8}
|
|
38
|
+
.skip{position:absolute;left:-9999px;top:0;background:var(--ink);color:var(--paper);
|
|
39
|
+
padding:10px 16px;z-index:100;font-family:var(--sans);font-size:13px;
|
|
40
|
+
text-decoration:none}
|
|
41
|
+
.skip:focus{left:16px;top:16px}
|
|
42
|
+
a:focus-visible,button:focus-visible,input:focus-visible,select:focus-visible{
|
|
43
|
+
outline:2px solid var(--acc);outline-offset:3px}
|
|
44
|
+
body::before,body::after{display:none!important}
|
|
45
|
+
#progress,.ticker,.nav-meta,.scroll-hint,.sec-index,.sec-sub,.sec-line,.kicker{display:none!important}
|
|
46
|
+
::selection{background:var(--acc);color:var(--paper)}
|
|
47
|
+
|
|
48
|
+
body{padding-left:220px}
|
|
49
|
+
.rail{position:fixed;left:0;top:0;bottom:0;width:220px;padding:38px 26px 26px;
|
|
50
|
+
display:flex;flex-direction:column;justify-content:space-between;
|
|
51
|
+
border-right:1px solid var(--line);background:var(--paper);z-index:20}
|
|
52
|
+
.rail-brand{display:flex;align-items:center;gap:8px;font-family:var(--serif);
|
|
53
|
+
font-size:22px;letter-spacing:-.01em}
|
|
54
|
+
.rail-brand i{width:7px;height:7px;background:var(--acc);display:block}
|
|
55
|
+
.rail-year{font-size:12px;color:var(--muted);margin-top:8px}
|
|
56
|
+
.rail-nav{display:flex;flex-direction:column;gap:14px;margin-top:52px;
|
|
57
|
+
border-top:1px solid var(--line);padding-top:22px}
|
|
58
|
+
.rail-nav a{font-size:13px;color:var(--muted);text-decoration:none;position:relative}
|
|
59
|
+
.rail-nav a:hover{color:var(--ink)}
|
|
60
|
+
.rail-nav a.active{color:var(--ink)}
|
|
61
|
+
.rail-nav a.active::before{content:"";position:absolute;left:-14px;top:50%;
|
|
62
|
+
width:4px;height:4px;background:var(--acc);transform:translateY(-50%)}
|
|
63
|
+
|
|
64
|
+
.next-link{display:flex;align-items:baseline;justify-content:flex-end;gap:10px;
|
|
65
|
+
margin-top:52px;font-size:12px;color:var(--muted);text-decoration:none}
|
|
66
|
+
.next-link .next-kicker{letter-spacing:.04em}
|
|
67
|
+
.next-link .name{font-family:var(--serif);font-size:18px;color:var(--ink)}
|
|
68
|
+
.next-link .name i{font-style:normal}
|
|
69
|
+
.next-link:hover .name{color:var(--acc)}
|
|
70
|
+
.rail-foot .lang{display:block;font-size:12px;color:var(--muted);
|
|
71
|
+
text-decoration:none;margin-bottom:12px}
|
|
72
|
+
.rail-foot .top{display:flex;justify-content:space-between;border-top:1px solid var(--line);
|
|
73
|
+
padding-top:14px;font-size:12px;color:var(--ink);text-decoration:none}
|
|
74
|
+
|
|
75
|
+
.wrap{max-width:1040px;padding:0 56px}
|
|
76
|
+
.hero{display:block;padding:100px 0 0}
|
|
77
|
+
.persona-block{display:grid;grid-template-columns:1fr auto;gap:36px;
|
|
78
|
+
align-items:start;border-top:1px solid var(--line);margin-top:42px;
|
|
79
|
+
padding:26px 0 2px}
|
|
80
|
+
.persona-kicker{font-family:var(--mono);font-size:10px;letter-spacing:.16em;
|
|
81
|
+
color:var(--acc)}
|
|
82
|
+
.persona-name{font-family:var(--serif);font-weight:400;font-size:42px;
|
|
83
|
+
line-height:1.1;letter-spacing:-.02em;margin:10px 0 0}
|
|
84
|
+
.persona-summary{font-family:var(--sans);font-size:14.5px;color:var(--ink2);
|
|
85
|
+
max-width:720px;margin:12px 0 0;line-height:1.8}
|
|
86
|
+
.persona-badges{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end;
|
|
87
|
+
max-width:360px}
|
|
88
|
+
.persona-badges span{border:1px solid var(--line);padding:5px 10px;
|
|
89
|
+
font-family:var(--sans);font-size:12px;color:var(--ink2);white-space:nowrap}
|
|
90
|
+
@media(max-width:640px){
|
|
91
|
+
.persona-block{grid-template-columns:1fr;gap:18px}
|
|
92
|
+
.persona-badges{justify-content:flex-start}
|
|
93
|
+
.persona-name{font-size:34px}
|
|
94
|
+
}
|
|
95
|
+
.cover-kicker{font-size:12px;letter-spacing:.16em;color:var(--acc);margin-bottom:18px}
|
|
96
|
+
.cover-year{font-family:var(--serif);font-size:clamp(120px,15vw,180px);line-height:.82;
|
|
97
|
+
letter-spacing:-.05em;color:var(--ink);margin-left:-6px}
|
|
98
|
+
.scan-roots{margin:14px 0 0;font-family:var(--sans);font-size:13px;
|
|
99
|
+
color:var(--muted);line-height:1.6;word-break:break-all}
|
|
100
|
+
.compare-line{margin:16px 0 0;font-family:var(--sans);font-size:13px;
|
|
101
|
+
color:var(--muted);line-height:1.6}
|
|
102
|
+
h1{font-family:var(--serif);font-weight:400;font-size:46px;line-height:1.15;
|
|
103
|
+
letter-spacing:-.02em;color:var(--ink);margin:24px 0 0}
|
|
104
|
+
h1 em{font-style:normal;color:var(--acc)}
|
|
105
|
+
.lede{margin:22px 0 0;max-width:640px;font-size:18px;line-height:1.8;color:var(--ink2)}
|
|
106
|
+
|
|
107
|
+
.to-top{position:fixed;right:26px;bottom:26px;z-index:30;display:inline-flex;
|
|
108
|
+
align-items:center;gap:6px;background:var(--paper);border:1px solid var(--ink);
|
|
109
|
+
padding:10px 14px;font-family:var(--sans);font-size:12px;color:var(--ink);
|
|
110
|
+
text-decoration:none;opacity:0;pointer-events:none;transition:opacity .2s}
|
|
111
|
+
.to-top.show{opacity:1;pointer-events:auto}
|
|
112
|
+
.to-top:hover{background:var(--ink);color:var(--paper)}
|
|
113
|
+
|
|
114
|
+
.hero-stats{display:grid;grid-template-columns:repeat(4,1fr);background:transparent;
|
|
115
|
+
border:1px solid var(--ink);margin-top:48px;padding:0}
|
|
116
|
+
.hero-stats .hs{padding:22px 24px;border:0;border-left:1px solid var(--line);
|
|
117
|
+
text-align:left}
|
|
118
|
+
.hero-stats .hs:first-child{border-left:0}
|
|
119
|
+
.hs b{display:block;font-family:var(--serif);font-size:40px;line-height:1.1;
|
|
120
|
+
font-weight:400;letter-spacing:-.02em;color:var(--ink)}
|
|
121
|
+
.hs span{font-family:var(--sans);font-size:12px;color:var(--muted);letter-spacing:0}
|
|
122
|
+
|
|
123
|
+
section{padding:88px 0 0;scroll-margin-top:24px}
|
|
124
|
+
.sec-head{border-bottom:2px solid var(--ink);padding-bottom:16px;margin-bottom:0}
|
|
125
|
+
.sec-head h2{font-family:var(--serif);font-size:36px;font-weight:400;letter-spacing:-.01em}
|
|
126
|
+
|
|
127
|
+
/* records: no boxes, just a quiet table */
|
|
128
|
+
.records{grid-template-columns:repeat(3,1fr);border:0;margin-top:0;column-gap:56px}
|
|
129
|
+
.record{border:0;padding:24px 0;min-height:auto}
|
|
130
|
+
.record:nth-child(n+4){border-top:1px solid var(--line)}
|
|
131
|
+
.record .k{font-family:var(--sans);font-size:12px;letter-spacing:0;color:var(--muted)}
|
|
132
|
+
.record .v{font-family:var(--serif);font-size:33px;font-weight:400;letter-spacing:-.01em;
|
|
133
|
+
margin:8px 0 4px}
|
|
134
|
+
.record .v small{font-family:var(--sans);font-size:13px}
|
|
135
|
+
.record .s{font-family:var(--sans);font-size:12px;color:var(--muted)}
|
|
136
|
+
|
|
137
|
+
/* repo archive: data plates, not cards */
|
|
138
|
+
.archive{border-top:1px solid var(--ink);border-bottom:1px solid var(--line);padding:28px 0 38px;gap:56px}
|
|
139
|
+
.plate{border:0;background:transparent;padding:0}
|
|
140
|
+
.plate .big b{font-family:var(--serif);font-size:32px;font-weight:400;letter-spacing:-.01em}
|
|
141
|
+
.plate .big span{font-family:var(--sans);font-size:12px;color:var(--muted)}
|
|
142
|
+
.plate .langs{gap:0;margin:14px 0 6px}
|
|
143
|
+
.plate .langs span{border:0;background:transparent;padding:0 12px 0 0;
|
|
144
|
+
font-family:var(--sans);font-size:12.5px;color:var(--muted)}
|
|
145
|
+
.plate .rec{font-family:var(--sans);font-size:12.5px;line-height:1.8;color:var(--ink2)}
|
|
146
|
+
.plate .rec b{font-family:var(--sans);font-size:11px;color:var(--acc)}
|
|
147
|
+
.plate .rec div{border-top:1px solid var(--line);padding:7px 0}
|
|
148
|
+
.case-no{display:none}
|
|
149
|
+
.stamp{border:0;padding:0;font-family:var(--sans);font-size:12px;letter-spacing:0;
|
|
150
|
+
color:var(--muted)}
|
|
151
|
+
.archive h3{font-family:var(--serif);font-size:32px;font-weight:400}
|
|
152
|
+
.readme-quote{font-family:var(--serif);font-size:16px;color:var(--ink2);
|
|
153
|
+
border-left:2px solid var(--acc);padding-left:14px}
|
|
154
|
+
.how{font-family:var(--sans);font-size:13.5px;line-height:1.8}
|
|
155
|
+
.how li{border-top:1px solid var(--line);padding:9px 0 9px 18px}
|
|
156
|
+
.how li::before{content:"·";color:var(--acc);left:2px}
|
|
157
|
+
.case-link{font-family:var(--sans);font-size:12px;letter-spacing:0;color:var(--ink2)}
|
|
158
|
+
|
|
159
|
+
/* index */
|
|
160
|
+
.filters{margin:26px 0 8px;gap:24px}
|
|
161
|
+
.filter{border:0;padding:4px 0;font-family:var(--sans);font-size:13px;color:var(--muted);
|
|
162
|
+
border-bottom:1px solid transparent}
|
|
163
|
+
.filter.on{background:transparent;color:var(--ink);border-bottom-color:var(--ink)}
|
|
164
|
+
.filter.on span{color:var(--muted)}
|
|
165
|
+
.filter:hover:not(.on){background:transparent;color:var(--ink)}
|
|
166
|
+
.index-table th{font-family:var(--sans);font-size:12px;letter-spacing:0;color:var(--muted);
|
|
167
|
+
border-bottom:1px solid var(--ink);padding:10px 8px;white-space:nowrap}
|
|
168
|
+
.index-table td{border-bottom:1px solid var(--line);padding:12px 8px;font-size:14px}
|
|
169
|
+
.index-table tbody tr:hover{background:transparent}
|
|
170
|
+
.t-name{font-weight:500}
|
|
171
|
+
.t-stack,.t-loc,.t-status,.t-no{font-family:var(--mono);font-size:11.5px}
|
|
172
|
+
.index-note{font-family:var(--sans);font-size:12px}
|
|
173
|
+
|
|
174
|
+
/* numbers: captions above charts, no cards */
|
|
175
|
+
.num-grid{gap:56px 64px;margin-top:52px}
|
|
176
|
+
.num-panel{border:0;background:transparent;padding:0;
|
|
177
|
+
border-top:1px solid var(--ink);padding-top:18px}
|
|
178
|
+
.num-grid > .num-panel:first-child{border-top:0;padding-top:0}
|
|
179
|
+
.num-panel h3{font-family:var(--sans);font-size:13px;letter-spacing:0;color:var(--ink);
|
|
180
|
+
font-weight:600;margin-bottom:20px}
|
|
181
|
+
.num-panel h3 b{font-weight:400;color:var(--muted)}
|
|
182
|
+
.stack{border:0;height:12px}
|
|
183
|
+
.lang-bar{border:0;height:22px}
|
|
184
|
+
.lang-bar i+i{border-left:2px solid var(--paper)}
|
|
185
|
+
.bar-track{border:0;height:7px;background:var(--paper2)}
|
|
186
|
+
.bar-track i{background:var(--ink)}
|
|
187
|
+
.bar-name{font-family:var(--sans);font-size:13px;width:170px}
|
|
188
|
+
.bar-val{font-family:var(--mono)}
|
|
189
|
+
.lang-legend div{font-family:var(--sans);font-size:12.5px}
|
|
190
|
+
.hour-chart{height:132px}
|
|
191
|
+
.hour-bar{background:var(--ink)}
|
|
192
|
+
.hour-bar.peak{background:var(--acc)}
|
|
193
|
+
.heat-panel{margin-top:32px}
|
|
194
|
+
.heat-wrap{border:0;background:transparent;padding:0}
|
|
195
|
+
.cell{background:var(--paper2)}
|
|
196
|
+
.clock .c{background:var(--paper2)}
|
|
197
|
+
.month-col i{background:var(--ink)}
|
|
198
|
+
.month-col.peak i{background:var(--acc)}
|
|
199
|
+
.clock .c.l1,.cell.l1{background:#ddd6c4}
|
|
200
|
+
.clock .c.l2,.cell.l2{background:#a89f88}
|
|
201
|
+
.clock .c.l3,.cell.l3{background:#5c554a}
|
|
202
|
+
.clock .c.l4,.cell.l4{background:var(--ink)}
|
|
203
|
+
.lc-track{border:0;background:var(--paper2)}
|
|
204
|
+
.chips-cloud span{border:0;background:transparent;padding:0 14px 0 0;
|
|
205
|
+
font-family:var(--sans);font-size:13px;color:var(--ink2)}
|
|
206
|
+
.chips-cloud b{font-weight:400;color:var(--muted)}
|
|
207
|
+
.pair{border:0;height:12px}
|
|
208
|
+
.q-stack{border:0}
|
|
209
|
+
.mini-stats b{font-family:var(--serif);font-size:28px;font-weight:400}
|
|
210
|
+
.mini-stats span{font-family:var(--sans);font-size:12px}
|
|
211
|
+
|
|
212
|
+
/* year over year */
|
|
213
|
+
.cmp-panel{margin-bottom:8px}
|
|
214
|
+
.cmp-row{display:grid;grid-template-columns:1.5fr .8fr .8fr 1.1fr;gap:14px;
|
|
215
|
+
align-items:baseline;border-top:1px solid var(--line);padding:10px 0;
|
|
216
|
+
font-family:var(--sans);font-size:13px}
|
|
217
|
+
.cmp-row.cmp-head{border-top:1px solid var(--line);padding:14px 0 8px;
|
|
218
|
+
margin-top:18px;color:var(--muted);font-size:11px;letter-spacing:.08em}
|
|
219
|
+
.cmp-k{color:var(--ink2)}
|
|
220
|
+
.cmp-head .cmp-k{color:var(--muted)}
|
|
221
|
+
.cmp-v{font-family:var(--mono);font-size:12.5px;color:var(--muted);
|
|
222
|
+
text-align:right}
|
|
223
|
+
.cmp-v.cur{color:var(--ink)}
|
|
224
|
+
.cmp-d{font-family:var(--mono);font-size:12.5px;color:var(--ink);
|
|
225
|
+
text-align:right}
|
|
226
|
+
.cmp-d.zero{color:var(--muted)}
|
|
227
|
+
.cmp-chart{margin-top:30px}
|
|
228
|
+
.cmp-cols{display:grid;grid-template-columns:repeat(12,1fr);gap:10px;
|
|
229
|
+
align-items:end}
|
|
230
|
+
.cmp-col{display:flex;flex-direction:column;gap:8px}
|
|
231
|
+
.cmp-bars{display:flex;align-items:flex-end;gap:3px;height:132px;
|
|
232
|
+
padding-top:16px;border-bottom:1px solid var(--line)}
|
|
233
|
+
.cmp-bar{position:relative;flex:1;height:100%;display:flex;
|
|
234
|
+
align-items:flex-end}
|
|
235
|
+
.cmp-bar i{width:100%;display:block;min-height:0}
|
|
236
|
+
.cmp-bar.prev i{background:var(--line2)}
|
|
237
|
+
.cmp-bar.cur i{background:var(--ink)}
|
|
238
|
+
.cmp-bar b{position:absolute;left:-4px;right:-4px;text-align:center;
|
|
239
|
+
font-family:var(--mono);font-size:9px;font-weight:400;line-height:1;
|
|
240
|
+
color:var(--muted);pointer-events:none}
|
|
241
|
+
.cmp-bar.cur b{color:var(--ink)}
|
|
242
|
+
.cmp-col span{font-family:var(--mono);font-size:10px;color:var(--muted);
|
|
243
|
+
text-align:center}
|
|
244
|
+
.cmp-legend{display:flex;gap:18px;margin-top:12px;font-family:var(--sans);
|
|
245
|
+
font-size:12px;color:var(--muted)}
|
|
246
|
+
.cmp-legend i{display:inline-block;width:9px;height:9px;margin-right:6px}
|
|
247
|
+
.cmp-legend i.prev{background:var(--line2)}
|
|
248
|
+
.cmp-legend i.cur{background:var(--ink)}
|
|
249
|
+
.cmp-note{display:flex;gap:22px;flex-wrap:wrap;margin-top:14px;
|
|
250
|
+
font-family:var(--sans);font-size:12px;color:var(--muted)}
|
|
251
|
+
.cmp-hint{margin:8px 0 0;font-family:var(--sans);font-size:12.5px;
|
|
252
|
+
color:var(--muted)}
|
|
253
|
+
.cmp-hint code{font-family:var(--mono);font-size:12px;color:var(--ink)}
|
|
254
|
+
.file-line{border-top:1px solid var(--line)}
|
|
255
|
+
.file-path{font-size:12px}
|
|
256
|
+
.sub-head{font-family:var(--sans);font-size:12px;letter-spacing:0}
|
|
257
|
+
.year-span{font-family:var(--sans);font-size:12px}
|
|
258
|
+
|
|
259
|
+
/* about + footer */
|
|
260
|
+
.about{border:0;background:transparent;padding:0}
|
|
261
|
+
.about ul{font-family:var(--sans);font-size:14px}
|
|
262
|
+
.about li{border-top:1px solid var(--line);padding:10px 0 10px 18px}
|
|
263
|
+
.about li::before{content:"·";color:var(--acc);left:2px}
|
|
264
|
+
.quote{font-family:var(--serif);font-size:28px;border-left:2px solid var(--acc)}
|
|
265
|
+
footer{border-top:1px solid var(--line);margin-top:88px;padding:24px 0 44px}
|
|
266
|
+
.foot-in{max-width:1040px;padding:0 56px;font-family:var(--sans);font-size:12px}
|
|
267
|
+
|
|
268
|
+
/* one quiet load fade; everything else stays still like print */
|
|
269
|
+
@keyframes cy-fade{from{opacity:0}to{opacity:1}}
|
|
270
|
+
main{animation:cy-fade .24s ease both}
|
|
271
|
+
.rail-nav a,.next-link .name{transition:color .18s ease}
|
|
272
|
+
.repo-search{margin-left:auto;background:transparent;border:0;
|
|
273
|
+
border-bottom:1px solid var(--line);font-family:var(--sans);font-size:13px;
|
|
274
|
+
padding:4px 2px;color:var(--ink);outline:none;min-width:200px}
|
|
275
|
+
.repo-search::placeholder{color:var(--muted)}
|
|
276
|
+
.rv,.rv-line{opacity:1!important;transform:none!important;transition:none!important}
|
|
277
|
+
.sec-line,.bar-track i,.hour-bar,.month-col i{transform:none!important;opacity:1!important}
|
|
278
|
+
@media (prefers-reduced-motion: reduce){
|
|
279
|
+
main{animation:none}
|
|
280
|
+
}
|
|
281
|
+
@media print{
|
|
282
|
+
.rail,.to-top,.next-link,.filters,.repo-search{display:none!important}
|
|
283
|
+
body{padding-left:0;background:#fff;color:#000;
|
|
284
|
+
-webkit-print-color-adjust:exact;print-color-adjust:exact}
|
|
285
|
+
main{animation:none!important}
|
|
286
|
+
.wrap{max-width:none;padding:0}
|
|
287
|
+
.hero{padding-top:0}
|
|
288
|
+
#records,#archives,#index,#numbers,#about{break-before:page}
|
|
289
|
+
.sec-head{border-color:#000}
|
|
290
|
+
a{color:inherit;text-decoration:none}
|
|
291
|
+
}
|
|
292
|
+
@page{margin:16mm}
|
|
293
|
+
#tip{border:1px solid var(--line);box-shadow:none;background:var(--paper);
|
|
294
|
+
font-family:var(--sans);font-size:12px}
|
|
295
|
+
|
|
296
|
+
@media(max-width:900px){
|
|
297
|
+
body{padding-left:0}
|
|
298
|
+
.rail{position:sticky;width:auto;height:auto;flex-direction:row;align-items:center;
|
|
299
|
+
justify-content:space-between;padding:16px 22px;border-right:0;
|
|
300
|
+
border-bottom:1px solid var(--line)}
|
|
301
|
+
.rail-nav,.rail-foot,.rail-year{display:none}
|
|
302
|
+
.wrap{max-width:100%;padding:0 22px}
|
|
303
|
+
.hero{padding:56px 0 0}
|
|
304
|
+
.cover-year{font-size:clamp(96px,22vw,140px)}
|
|
305
|
+
h1{font-size:38px}
|
|
306
|
+
.hero-stats{grid-template-columns:1fr 1fr}
|
|
307
|
+
.foot-in{max-width:100%;padding:0 22px}
|
|
308
|
+
.records{grid-template-columns:repeat(2,1fr);column-gap:32px}
|
|
309
|
+
}
|
|
310
|
+
@media(max-width:640px){
|
|
311
|
+
.wrap,.nav,.foot-in{padding-left:22px;padding-right:22px}
|
|
312
|
+
.nav-links{display:none}
|
|
313
|
+
h1{font-size:44px}
|
|
314
|
+
.hero-stats{grid-template-columns:1fr 1fr;padding:0 20px}
|
|
315
|
+
.records{grid-template-columns:1fr}
|
|
316
|
+
.cmp-row{grid-template-columns:1.2fr .7fr .7fr 1fr;gap:8px}
|
|
317
|
+
.cmp-cols{gap:4px}
|
|
318
|
+
.cmp-bars{height:88px}
|
|
319
|
+
}
|
|
320
|
+
</style>
|
|
321
|
+
"""
|
|
322
|
+
|
|
323
|
+
# ---- English edition -------------------------------------------------
|
|
324
|
+
EN_MAP = {
|
|
325
|
+
"代码手账": "CodeYear",
|
|
326
|
+
"年度代码报告": "Annual Code Report",
|
|
327
|
+
"2026 年度代码报告": "2026 Annual Code Report",
|
|
328
|
+
"回到顶部": "Back to top",
|
|
329
|
+
"跳到主要内容": "Skip to main content",
|
|
330
|
+
"主导航": "Main navigation",
|
|
331
|
+
"报告目录": "Report contents",
|
|
332
|
+
"月度提交次数": "Monthly commit counts",
|
|
333
|
+
"全年提交热力图": "Full-year commit heatmap",
|
|
334
|
+
"语言栈季度变化": "Quarterly language mix",
|
|
335
|
+
"月度同比柱状图": "Monthly year-over-year bars",
|
|
336
|
+
"下一节": "Next",
|
|
337
|
+
"顶部": "Top",
|
|
338
|
+
"「git 不会说谎——": '"Git never lies —',
|
|
339
|
+
"尤其是加了 --no-merges 的时候。": " especially with --no-merges.",
|
|
340
|
+
"」": '"',
|
|
341
|
+
"包括休眠的和没写 README 的": "Including dormant repos and those without a README",
|
|
342
|
+
"git 里能查到的,不靠形容词": "What git can prove, without adjectives",
|
|
343
|
+
"CodeYear · 代码手账": "CodeYear · Code Yearbook",
|
|
344
|
+
"2026 年度代码报告 ·": "2026 Annual Code Report ·",
|
|
345
|
+
"年度之最": "Yearly records",
|
|
346
|
+
"仓库档案": "Repository profiles",
|
|
347
|
+
"仓库索引": "Repository index",
|
|
348
|
+
"全部仓库索引": "Full repository index",
|
|
349
|
+
"数字": "Numbers",
|
|
350
|
+
"数据分析": "Data analysis",
|
|
351
|
+
"同比去年": "Year over year",
|
|
352
|
+
"指标": "Metric",
|
|
353
|
+
"变化": "Change",
|
|
354
|
+
"提交": "Commits",
|
|
355
|
+
"代码行变更": "Lines changed",
|
|
356
|
+
"新增行": "Added lines",
|
|
357
|
+
"删除行": "Deleted lines",
|
|
358
|
+
"活跃日": "Active days",
|
|
359
|
+
"涉及仓库": "Repositories",
|
|
360
|
+
"最长连续(天)": "Longest streak (days)",
|
|
361
|
+
"平均提交信息(字符)": "Avg. message (chars)",
|
|
362
|
+
"周末占比": "Weekend share",
|
|
363
|
+
"深夜占比": "Night share",
|
|
364
|
+
"搜索仓库 / 语言 / 简介": "Search repos / languages / descriptions",
|
|
365
|
+
"如果当时用过其他邮箱或名字,可以用":
|
|
366
|
+
"If you used another email or name, add",
|
|
367
|
+
"把旧身份合并进来后重新生成。":
|
|
368
|
+
"to merge the old identity, then regenerate.",
|
|
369
|
+
"关于": "About",
|
|
370
|
+
"2026 年,": "In 2026,",
|
|
371
|
+
"次提交。": "commits.",
|
|
372
|
+
"38.2 万": "382k",
|
|
373
|
+
"次提交": "commits",
|
|
374
|
+
"行代码变更": "lines changed",
|
|
375
|
+
"个活跃日": "active days",
|
|
376
|
+
"个仓库": "repositories",
|
|
377
|
+
"先看几个最极端的数字": "",
|
|
378
|
+
"最忙的一天": "Busiest day",
|
|
379
|
+
"最忙的一周": "Busiest week",
|
|
380
|
+
"最长连续": "Longest streak",
|
|
381
|
+
"最长空窗": "Longest gap",
|
|
382
|
+
"最大单次提交": "Largest commit",
|
|
383
|
+
"最长的 commit": "Longest message",
|
|
384
|
+
"天": "days",
|
|
385
|
+
"行": "lines",
|
|
386
|
+
"字符": "chars",
|
|
387
|
+
"第一次提交": "First commit",
|
|
388
|
+
"最后一次提交": "Last commit",
|
|
389
|
+
"提交最多的三个仓库 · 时间线与热区": "",
|
|
390
|
+
"种主要语言": "main languages",
|
|
391
|
+
"活跃": "Active",
|
|
392
|
+
"休眠": "Dormant",
|
|
393
|
+
"进行中": "In progress",
|
|
394
|
+
"全部": "All",
|
|
395
|
+
"序号": "#",
|
|
396
|
+
"仓库": "Repository",
|
|
397
|
+
"一句话(README 原文)": "README first line",
|
|
398
|
+
"栈": "Stack",
|
|
399
|
+
"自有代码": "Own code",
|
|
400
|
+
"最近提交": "Latest commit",
|
|
401
|
+
"状态": "Status",
|
|
402
|
+
"(README 没写简介)": "(No README description)",
|
|
403
|
+
"月度节奏": "Monthly rhythm",
|
|
404
|
+
"7×24 提交时钟": "7×24 commit clock",
|
|
405
|
+
"周一": "Mon", "周二": "Tue", "周三": "Wed", "周四": "Thu",
|
|
406
|
+
"周五": "Fri", "周六": "Sat", "周日": "Sun",
|
|
407
|
+
"周末占 40%,深夜(22:00–05:00)占 44%。":
|
|
408
|
+
"Weekend 40%; late night (22:00–05:00) 44%.",
|
|
409
|
+
"代码构成": "Code composition",
|
|
410
|
+
"语言构成": "Languages",
|
|
411
|
+
"其他": "Other",
|
|
412
|
+
"语言栈变化": "Language mix",
|
|
413
|
+
"无提交": "No commits",
|
|
414
|
+
"提交规模": "Commit size",
|
|
415
|
+
"提交类型": "Commit types",
|
|
416
|
+
"高频词": "Keywords",
|
|
417
|
+
"消息长度": "Message length",
|
|
418
|
+
"增删比": "Add/delete ratio",
|
|
419
|
+
"删除最多的仓库": "Most deletions",
|
|
420
|
+
"编码会话": "Coding sessions",
|
|
421
|
+
"次会话": "sessions",
|
|
422
|
+
"工作节奏": "Coding rhythm",
|
|
423
|
+
"· 会话而不是次数": "· sessions, not commit counts",
|
|
424
|
+
"次编码会话": "coding sessions",
|
|
425
|
+
"最长一次连续编码": "Longest continuous session",
|
|
426
|
+
"最长会话里的提交": "Commits in longest session",
|
|
427
|
+
"平均会话时长": "Average session length",
|
|
428
|
+
"最长一次": "Longest",
|
|
429
|
+
"最长一次里的提交": "Commits in longest",
|
|
430
|
+
"平均一次": "Average",
|
|
431
|
+
"仓库生命周期": "Repository lifecycle",
|
|
432
|
+
"首次–最近": "First–latest",
|
|
433
|
+
"首次提交": "First commit",
|
|
434
|
+
"仓库墓园": "Repo graveyard",
|
|
435
|
+
"· 30 天没动": "· untouched for 30 days",
|
|
436
|
+
"没有休眠超过 30 天的仓库。":
|
|
437
|
+
"No repositories have been dormant for more than 30 days.",
|
|
438
|
+
"未知": "Unknown",
|
|
439
|
+
"(这个仓库的 README 还没写简介)": "(No README description)",
|
|
440
|
+
"(最近没有提交)": "(No recent commits)",
|
|
441
|
+
"没有识别到 Conventional Commits 类型。":
|
|
442
|
+
"No Conventional Commits types found.",
|
|
443
|
+
"提交信息太短,没有提取到关键词。":
|
|
444
|
+
"Commit messages are too short to extract keywords.",
|
|
445
|
+
"没有足够的提交时间数据。": "Not enough commit time data.",
|
|
446
|
+
"没有足够数据。": "Not enough data.",
|
|
447
|
+
"没有可统计的代码文件。": "No code files to analyze.",
|
|
448
|
+
"未检测到 git 身份,统计了所有作者的提交(可用 --all-authors 显式开启)。":
|
|
449
|
+
"No git identity detected; all authors were counted "
|
|
450
|
+
"(use --all-authors explicitly).",
|
|
451
|
+
"· 约定式提交": "· conventional commits",
|
|
452
|
+
"· 口头禅": "· catchphrases",
|
|
453
|
+
"最常改的文件": "Most edited files",
|
|
454
|
+
"最晚的一次熬夜": "Latest night commit",
|
|
455
|
+
"文件级重构榜": "Most refactored files",
|
|
456
|
+
"· 删除行数最多的文件": "· by lines deleted",
|
|
457
|
+
"2026 活跃热力图": "2026 activity",
|
|
458
|
+
"少 → 多 · 框出今天": "Less → more · today outlined",
|
|
459
|
+
"关于本报告": "About this report",
|
|
460
|
+
"GitHub 主页卡片": "GitHub profile card",
|
|
461
|
+
"将生成的 SVG 卡片放入你的同名 Profile 仓库,粘贴以下代码到 README.md:":
|
|
462
|
+
"Place the SVG cards in your profile repository and paste this into README.md:",
|
|
463
|
+
"复制嵌入代码": "Copy embed snippet",
|
|
464
|
+
"口径与方法": "Method",
|
|
465
|
+
"这份报告由 CodeYear 在你的电脑上生成,代码从未离开这台机器。":
|
|
466
|
+
"Generated by CodeYear on your computer. Your code never leaves it.",
|
|
467
|
+
"这份报告根据公开 GitHub 数据生成;没有读取或上传本机代码。":
|
|
468
|
+
"Generated from public GitHub data; no local code was read or uploaded.",
|
|
469
|
+
"只统计该账号名下的公开仓库,以及 GitHub 能关联到该账号的提交;不读取私有仓库。":
|
|
470
|
+
"Counts only public repositories owned by the account and commits GitHub "
|
|
471
|
+
"associates with it; private repositories are not read.",
|
|
472
|
+
"尤其是只读公开数据的时候。":
|
|
473
|
+
"especially when reading public data only.",
|
|
474
|
+
"PUBLIC DATA · 来自 GitHub": "PUBLIC DATA · from GitHub",
|
|
475
|
+
"下面每个数字都来自公开 GitHub 数据——":
|
|
476
|
+
"Every number below comes from public GitHub data —",
|
|
477
|
+
"下面每个数字都来自本机 git——":
|
|
478
|
+
"Every number below comes from local git —",
|
|
479
|
+
"没有读取或上传本地代码": "no local code was read or uploaded",
|
|
480
|
+
"这份报告没有上传任何东西": "this report uploaded nothing",
|
|
481
|
+
"只统计 2026 年的提交;合并提交(--no-merges)不计入。":
|
|
482
|
+
"Only commits from 2026 are counted; merge commits (--no-merges) are excluded.",
|
|
483
|
+
"同一项目出现在多个目录时只保留提交最多的一个;同一 commit 只计一次。":
|
|
484
|
+
"Copies of the same project collapse into one; each commit is counted once.",
|
|
485
|
+
"时间取 author date;跨时区协作时以提交者本地时间为准。":
|
|
486
|
+
"Dates use author date, i.e. the author's local time.",
|
|
487
|
+
"「自有代码」= 非空行;已剔除第三方库、生成工程与二进制。":
|
|
488
|
+
"“Own code” means non-empty lines, excluding third-party libraries, generated projects, and binaries.",
|
|
489
|
+
"CODEYEAR · 代码手账 2026": "CODEYEAR · 2026",
|
|
490
|
+
"0–10 行": "0–10 lines",
|
|
491
|
+
"10–100 行": "10–100 lines",
|
|
492
|
+
"100–500 行": "100–500 lines",
|
|
493
|
+
"500–2k 行": "500–2k lines",
|
|
494
|
+
"2k+ 行": "2k+ lines",
|
|
495
|
+
"0–20 字符": "0–20 chars",
|
|
496
|
+
"20–40 字符": "20–40 chars",
|
|
497
|
+
"40–80 字符": "40–80 chars",
|
|
498
|
+
"80–160 字符": "80–160 chars",
|
|
499
|
+
"160+ 字符": "160+ chars",
|
|
500
|
+
"· 每个月的提交次数": "· commits per month",
|
|
501
|
+
"· 星期几、几点提交最多": "· busiest weekday and hour",
|
|
502
|
+
"· 哪些仓库写的代码最多": "· repos with the most code",
|
|
503
|
+
"· 各种语言占了多少行": "· lines by language",
|
|
504
|
+
"· 每个季度的语言占比": "· share by quarter",
|
|
505
|
+
"· 每次提交改了多少行": "· lines changed per commit",
|
|
506
|
+
"· 哪种类型的提交最多": "· which type appears most",
|
|
507
|
+
"· 提交说明里最常出现的词": "· words in commit messages",
|
|
508
|
+
"· 提交说明一般写多长": "· how long commit messages are",
|
|
509
|
+
"· 写了多少、删了多少": "· lines added vs deleted",
|
|
510
|
+
"· 每个仓库今年活跃的时间段": "· active span per repo",
|
|
511
|
+
"· 超过 30 天没动的仓库": "· repos untouched for 30+ days",
|
|
512
|
+
"· 每个文件改了多少行": "· changed lines per file",
|
|
513
|
+
"· 哪天有提交": "· days with commits",
|
|
514
|
+
"· 一次连续写多久": "· how long one sitting lasts",
|
|
515
|
+
"· 峰值 23:00": "· peak 23:00",
|
|
516
|
+
"· 头部集中度(按行数)": "· concentration by lines",
|
|
517
|
+
"· 按行变更估算": "· estimated by lines changed",
|
|
518
|
+
"· 按季度占比": "· share by quarter",
|
|
519
|
+
"· 小步快跑还是大爆炸": "· small steps or big bangs",
|
|
520
|
+
"· commit message 里的口头禅": "· phrases in commit messages",
|
|
521
|
+
"· 建设 vs 重构": "· building vs refactoring",
|
|
522
|
+
"· 2026 活跃区间": "· 2026 active span",
|
|
523
|
+
"· 改动热区(完整路径)": "· full paths",
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
EN_PATTERNS = [
|
|
527
|
+
(r"(\d{4}) 年度代码报告", r"\1 Annual Code Report"),
|
|
528
|
+
(r"(\d{4}) 年度代码报告 ·", r"\1 Annual Code Report ·"),
|
|
529
|
+
(r"CODEYEAR · 代码手账 (\d{4})", r"CODEYEAR · \1"),
|
|
530
|
+
(r"(\d{4}) 活跃热力图", r"\1 activity"),
|
|
531
|
+
(r"· (\d{4}) 活跃区间", r"· \1 active span"),
|
|
532
|
+
(r"同比 (\d{4})(去年 0 次提交):提交 (.*?) · 行数 (.*?) · 活跃 (.*?) 天 · 仓库 (.*)",
|
|
533
|
+
r"vs \1 (no commits last year): commits \2 · lines \3 · active \4 days · repos \5"),
|
|
534
|
+
(r"同比 (\d{4}):提交 (.*?) · 行数 (.*?) · 活跃 (.*?) 天 · 仓库 (.*)",
|
|
535
|
+
r"vs \1: commits \2 · lines \3 · active \4 days · repos \5"),
|
|
536
|
+
(r"同比 (\d{4}):去年没有提交,无法对比",
|
|
537
|
+
r"vs \1: no commits last year"),
|
|
538
|
+
(r"(\d{4}) 年在扫描范围内没有提交,以下按 0 计算。",
|
|
539
|
+
r"No commits in \1 within the scanned roots; the comparison below uses 0."),
|
|
540
|
+
(r"(\d{4}) 年在扫描范围内没有提交,无法生成有效的同比。",
|
|
541
|
+
r"No commits in \1 within the scanned roots, so year-over-year "
|
|
542
|
+
r"comparison is unavailable."),
|
|
543
|
+
(r"今年峰值 (\d+) 月 · ([\d,]+) 次", r"This year peaks in month \1 · \2 commits"),
|
|
544
|
+
(r"去年峰值 (\d+) 月 · ([\d,]+) 次", r"Last year peaks in month \1 · \2 commits"),
|
|
545
|
+
(r"([+-]?\d+) 个百分点", r"\1 pp"),
|
|
546
|
+
(r"数据来源:(.*) · (\d+) 个仓库", r"Source: \1 · \2 repositories"),
|
|
547
|
+
(r"只统计 (\d{4}) 年的提交;合并提交不计入。",
|
|
548
|
+
r"Only \1 commits are counted; merge commits are excluded."),
|
|
549
|
+
(r"扫描目录:(.*) · (\d+) 个仓库", r"Scan roots: \1 · \2 repositories"),
|
|
550
|
+
(r"38\.2\s*万\s*行代码,53 个活跃日,10 个仓库。",
|
|
551
|
+
r"382k lines of code, 53 active days, 10 repositories."),
|
|
552
|
+
(r"(\d[\d,]*) 次提交", r"\1 commits"),
|
|
553
|
+
(r"当前连续 (\d+) 天", r"Current streak: \1 days"),
|
|
554
|
+
(r"(\d{4}-W\d+) · 起于 (\d{4}\.\d{2}\.\d{2})", r"\1 · from \2"),
|
|
555
|
+
(r"首次提交 (.*) → 最近提交 (.*)", r"First \1 → latest \2"),
|
|
556
|
+
(r"语言:(.*)", r"Languages: \1"),
|
|
557
|
+
(r"最常改的文件:(.*)((.*) 行变更)", r"Most edited: \1 (\2 lines changed)"),
|
|
558
|
+
(r"提交 (\d+) 次(已按 hash 去重)", r"\1 commits (deduplicated by hash)"),
|
|
559
|
+
(r"· 峰值 (\d+) 月 · (\d+) 次", r"· peak month \1 · \2 commits"),
|
|
560
|
+
(r"· 约定式占 (\d+)%", r"· \1% conventional"),
|
|
561
|
+
(r"· 平均 (\d+) 字符", r"· average \1 chars"),
|
|
562
|
+
(r"· (\d+) 个仓库超过 30 天没动", r"· \1 repos untouched for 30+ days"),
|
|
563
|
+
(r"· (\d+) 个活跃日", r"· \1 active days"),
|
|
564
|
+
(r"其余 (\d+) 个仓库 · (.*)", r"Other \1 repos · \2"),
|
|
565
|
+
(r"新增 (.*) 行", r"Added \1 lines"),
|
|
566
|
+
(r"删除 (.*) 行", r"Deleted \1 lines"),
|
|
567
|
+
(r"删除 / 新增 = (\d+)%。最大的一次删除 (.*) 行((.*),(.*))。",
|
|
568
|
+
r"Deletions / additions = \1%. Largest deletion: \2 lines (\3, \4)."),
|
|
569
|
+
(r"平均每条 (\d+) 字符。", r"Average \1 characters."),
|
|
570
|
+
(r"最长的一条见「年度之最」。", 'Longest message in "Yearly records".'),
|
|
571
|
+
(r"16 小时 01 分", r"16h 01m"),
|
|
572
|
+
(r"(\d+) 分钟", r"\1 min"),
|
|
573
|
+
(r"最后提交 (.*)", r"Last commit \1"),
|
|
574
|
+
(r"(\d+) 天", r"\1 days"),
|
|
575
|
+
(r"扫描范围 (.*) · (.*)", r"Scanned \1 · \2"),
|
|
576
|
+
(r"由 CodeYear 根据公开 GitHub 数据生成 · (.*) · 没有读取或上传本地代码",
|
|
577
|
+
r"Generated from public GitHub data by CodeYear · \1 · no local code was read or uploaded"),
|
|
578
|
+
(r"由 CodeYear 在本机生成 · (.*) · 代码从未离开这台电脑",
|
|
579
|
+
r"Generated locally by CodeYear · \1 · your code never left this machine"),
|
|
580
|
+
(r"只统计你本人作者的提交((.*));已过滤 (\d+) 次他人提交。",
|
|
581
|
+
r"Only your commits (\1); \2 commits by others filtered out."),
|
|
582
|
+
(r"间隔 ≤ 2 小时算同一会话。最长一次:(.*) → (.*)。",
|
|
583
|
+
r"Commits within 2 hours count as one session. Longest: \1 → \2."),
|
|
584
|
+
(r"周末占 (\d+)%,深夜(22:00–05:00)占 (\d+)%。",
|
|
585
|
+
r"Weekend \1%; late night (22:00–05:00) \2%."),
|
|
586
|
+
]
|
|
587
|
+
|
|
588
|
+
_block_re = re.compile(
|
|
589
|
+
r"<(style|script)\b.*?</\1>|<([a-z0-9]+)\b[^>]*\bdata-raw\b[^>]*>.*?</\2>",
|
|
590
|
+
re.S | re.I,
|
|
591
|
+
)
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
def _translate_core(core: str) -> str | None:
|
|
595
|
+
if core in EN_MAP:
|
|
596
|
+
return EN_MAP[core]
|
|
597
|
+
for pattern, repl in EN_PATTERNS:
|
|
598
|
+
m = re.fullmatch(pattern, core)
|
|
599
|
+
if m:
|
|
600
|
+
return m.expand(repl)
|
|
601
|
+
return None
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def _wan_convert(text: str) -> str:
|
|
605
|
+
def repl(m):
|
|
606
|
+
value = float(m.group(1)) * 10
|
|
607
|
+
if value >= 100:
|
|
608
|
+
return f"{value:.0f}k"
|
|
609
|
+
return f"{value:g}k"
|
|
610
|
+
return re.sub(r"(\d+(?:\.\d+)?)\s*万", repl, text)
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
def _translate_node(value: str) -> str:
|
|
614
|
+
lead = value[: len(value) - len(value.lstrip())]
|
|
615
|
+
trail = value[len(value.rstrip()):]
|
|
616
|
+
core = value.strip()
|
|
617
|
+
if not core:
|
|
618
|
+
return value
|
|
619
|
+
en = _translate_core(core)
|
|
620
|
+
en = _wan_convert(core) if en is None else _wan_convert(en)
|
|
621
|
+
return lead + en + trail
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
WEEK = {"周一": "Mon", "周二": "Tue", "周三": "Wed", "周四": "Thu",
|
|
625
|
+
"周五": "Fri", "周六": "Sat", "周日": "Sun"}
|
|
626
|
+
MONTH = {i: m for i, m in enumerate(
|
|
627
|
+
["Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
628
|
+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], 1)}
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
def _translate_tip(value: str) -> str:
|
|
632
|
+
v = _wan_convert(htmlmod.unescape(value))
|
|
633
|
+
core = v.strip()
|
|
634
|
+
if core in EN_MAP:
|
|
635
|
+
return EN_MAP[core]
|
|
636
|
+
v = re.sub(r"(周[一二三四五六日])\s*(\d{2}:\d{2}) · (\d+) 次提交",
|
|
637
|
+
lambda m: f"{WEEK[m.group(1)]} {m.group(2)} · {m.group(3)} commits", v)
|
|
638
|
+
v = re.sub(r"(\d+) 月 · (\d+) 次提交",
|
|
639
|
+
lambda m: f"{MONTH[int(m.group(1))]} · {m.group(2)} commits", v)
|
|
640
|
+
v = re.sub(r"(\d{4}-\d{2}-\d{2}) · (\d+) 次提交",
|
|
641
|
+
lambda m: f"{m.group(1)} · {m.group(2)} commits", v)
|
|
642
|
+
v = re.sub(r"(.*?) · (\d+)% · ([\d.,k]+) 行",
|
|
643
|
+
lambda m: f"{m.group(1)} · {m.group(2)}% · {m.group(3)} lines", v)
|
|
644
|
+
v = re.sub(r"(.*?) · ([\d.,k]+) 行变更",
|
|
645
|
+
lambda m: f"{m.group(1)} · {m.group(2)} lines changed", v)
|
|
646
|
+
v = re.sub(r"(.*?) · (\d+) 次提交",
|
|
647
|
+
lambda m: f"{m.group(1)} · {m.group(2)} commits", v)
|
|
648
|
+
v = re.sub(r"(\d+) 次提交", lambda m: f"{m.group(1)} commits", v)
|
|
649
|
+
v = re.sub(r"([\d.,k]+) 行变更", lambda m: f"{m.group(1)} lines changed", v)
|
|
650
|
+
v = re.sub(r"([\d.,k]+) 行", lambda m: f"{m.group(1)} lines", v)
|
|
651
|
+
v = re.sub(r"(\d+) 个活跃日", lambda m: f"{m.group(1)} active days", v)
|
|
652
|
+
v = re.sub(r"(\d+) 次", lambda m: f"{m.group(1)} times", v)
|
|
653
|
+
v = v.replace("没有提交", "No commits").replace("无提交", "No commits")
|
|
654
|
+
v = v.replace("最近的真实提交记录", "Recent real commits")
|
|
655
|
+
v = v.replace("搜索仓库", "Search repositories")
|
|
656
|
+
v = v.replace("其他", "Other")
|
|
657
|
+
return v
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
def translate_html(source: str) -> str:
|
|
661
|
+
blocks = []
|
|
662
|
+
|
|
663
|
+
def stash(m):
|
|
664
|
+
blocks.append(m.group(0))
|
|
665
|
+
return f"@@BLOCK{len(blocks) - 1}@@"
|
|
666
|
+
|
|
667
|
+
text = _block_re.sub(stash, source)
|
|
668
|
+
text = re.sub(r">([^<>]+)<",
|
|
669
|
+
lambda m: ">" + _translate_node(m.group(1)) + "<", text)
|
|
670
|
+
text = re.sub(r"@@BLOCK(\d+)@@", lambda m: blocks[int(m.group(1))], text)
|
|
671
|
+
text = re.sub(r'(data-tip|aria-label)="([^"]*)"',
|
|
672
|
+
lambda m: f'{m.group(1)}="{htmlmod.escape(_translate_tip(m.group(2)), quote=True)}"',
|
|
673
|
+
text)
|
|
674
|
+
text = re.sub(r'placeholder="([^"]*)"',
|
|
675
|
+
lambda m: f'placeholder="{htmlmod.escape(_translate_node(m.group(1)), quote=True)}"',
|
|
676
|
+
text)
|
|
677
|
+
text = text.replace('<html lang="zh-CN">', '<html lang="en">')
|
|
678
|
+
text = re.sub(r'<meta name="description" content="[^"]*">',
|
|
679
|
+
'<meta name="description" content="CodeYear annual code report - a local-first year in review.">',
|
|
680
|
+
text)
|
|
681
|
+
text = text.replace('aria-label="回到顶部"', 'aria-label="Back to top"')
|
|
682
|
+
return text
|
|
683
|
+
|
|
684
|
+
CAPTIONS = [
|
|
685
|
+
(r"· 峰值 \d+ 月 · \d+ 次", "· 每个月的提交次数"),
|
|
686
|
+
(r"· 峰值 \d{2}:\d{2}", "· 星期几、几点提交最多"),
|
|
687
|
+
("· 头部集中度(按行数)", "· 哪些仓库写的代码最多"),
|
|
688
|
+
("· 按行变更估算", "· 各种语言占了多少行"),
|
|
689
|
+
("· 按季度占比", "· 每个季度的语言占比"),
|
|
690
|
+
("· 小步快跑还是大爆炸", "· 每次提交改了多少行"),
|
|
691
|
+
(r"· 约定式占 \d+%", "· 哪种类型的提交最多"),
|
|
692
|
+
("· commit message 里的口头禅", "· 提交说明里最常出现的词"),
|
|
693
|
+
(r"· 平均 \d+ 字符", "· 提交说明一般写多长"),
|
|
694
|
+
("· 建设 vs 重构", "· 写了多少、删了多少"),
|
|
695
|
+
(r"· \d{4} 活跃区间", "· 每个仓库今年活跃的时间段"),
|
|
696
|
+
(r"· \d+ 个仓库超过 30 天没动", "· 超过 30 天没动的仓库"),
|
|
697
|
+
("· 改动热区(完整路径)", "· 每个文件改了多少行"),
|
|
698
|
+
(r"· \d+ 个活跃日", "· 哪天有提交"),
|
|
699
|
+
]
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
def _fix_h3(m):
|
|
703
|
+
inner = m.group(1)
|
|
704
|
+
for pattern, repl in CAPTIONS:
|
|
705
|
+
inner = re.sub(pattern, repl, inner)
|
|
706
|
+
return f"<h3>{inner}</h3>"
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
def decorate(source: str, stats: ReportStats) -> str:
|
|
710
|
+
year = stats.year
|
|
711
|
+
commits = stats.commit_count
|
|
712
|
+
lines = stats.lines_changed
|
|
713
|
+
active = stats.active_days
|
|
714
|
+
repos = stats.repo_count
|
|
715
|
+
html = source
|
|
716
|
+
|
|
717
|
+
source_label = "数据来源" if stats.public_source else "扫描目录"
|
|
718
|
+
cover = (
|
|
719
|
+
f'<div class="cover-year">{year}</div>'
|
|
720
|
+
f'<p class="scan-roots">{source_label}:{htmlmod.escape(stats.root)}'
|
|
721
|
+
f' · {repos} 个仓库</p>'
|
|
722
|
+
f'<h1><em>{_comma(commits)}</em> 次提交。</h1>'
|
|
723
|
+
)
|
|
724
|
+
html = re.sub(
|
|
725
|
+
r'<h1 class="rv-line">.*?</h1>',
|
|
726
|
+
lambda _match: cover,
|
|
727
|
+
html, count=1, flags=re.S,
|
|
728
|
+
)
|
|
729
|
+
html = re.sub(
|
|
730
|
+
r'<p class="lede rv"[^>]*>.*?</p>',
|
|
731
|
+
f'<p class="lede">{_human(lines)} 行代码,{active} 个活跃日,'
|
|
732
|
+
f'{repos} 个仓库。</p>',
|
|
733
|
+
html, count=1, flags=re.S,
|
|
734
|
+
)
|
|
735
|
+
hero_stats = f"""
|
|
736
|
+
<div class="hero-stats">
|
|
737
|
+
<div class="hs"><b>{_comma(commits)}</b><span>次提交</span></div>
|
|
738
|
+
<div class="hs"><b>{_human(lines)}</b><span>行代码变更</span></div>
|
|
739
|
+
<div class="hs"><b>{active}</b><span>个活跃日</span></div>
|
|
740
|
+
<div class="hs"><b>{repos}</b><span>个仓库</span></div>
|
|
741
|
+
</div>"""
|
|
742
|
+
compare_html = ""
|
|
743
|
+
previous = stats.previous
|
|
744
|
+
if previous:
|
|
745
|
+
prev_commits = previous.get("previous_commits")
|
|
746
|
+
if prev_commits is None: # older JSON: derive from the delta
|
|
747
|
+
prev_commits = stats.commit_count - previous.get("commits", 0)
|
|
748
|
+
|
|
749
|
+
def _delta(value: int, pct: float | None) -> str:
|
|
750
|
+
text = f"{value:+,}" if value else "0"
|
|
751
|
+
if pct is not None:
|
|
752
|
+
text += f"({pct:+.0%})"
|
|
753
|
+
return text
|
|
754
|
+
|
|
755
|
+
basis = "(去年 0 次提交)" if prev_commits == 0 else ""
|
|
756
|
+
compare_html = (
|
|
757
|
+
f'<p class="compare-line">同比 {previous["year"]}{basis}:'
|
|
758
|
+
f'提交 {_delta(previous["commits"], previous["commits_pct"])} · '
|
|
759
|
+
f'行数 {_delta(previous["lines"], previous["lines_pct"])} · '
|
|
760
|
+
f'活跃 {_delta(previous["active_days"], None)} 天 · '
|
|
761
|
+
f'仓库 {_delta(previous["repos"], None)}'
|
|
762
|
+
"</p>"
|
|
763
|
+
)
|
|
764
|
+
html = re.sub(
|
|
765
|
+
r'<div class="hero-stats">.*?<p class="scroll-hint[^>]*>.*?</p>',
|
|
766
|
+
hero_stats + compare_html, html, count=1, flags=re.S,
|
|
767
|
+
)
|
|
768
|
+
rail = f"""<aside class="rail" aria-label="报告目录">
|
|
769
|
+
<div>
|
|
770
|
+
<div class="rail-brand"><i></i>代码手账</div>
|
|
771
|
+
<div class="rail-year">{year} 年度代码报告</div>
|
|
772
|
+
<nav class="rail-nav">
|
|
773
|
+
<a href="#records">年度之最</a>
|
|
774
|
+
<a href="#archives">仓库档案</a>
|
|
775
|
+
<a href="#index">仓库索引</a>
|
|
776
|
+
<a href="#numbers">数据分析</a>
|
|
777
|
+
<a href="#about">关于</a>
|
|
778
|
+
</nav>
|
|
779
|
+
</div>
|
|
780
|
+
<div class="rail-foot">
|
|
781
|
+
<a class="lang" href="codeyear-{year}-en.html">English</a>
|
|
782
|
+
<a class="top" href="#top">回到顶部 <span>↑</span></a>
|
|
783
|
+
</div>
|
|
784
|
+
</aside>"""
|
|
785
|
+
html = re.sub(r'<header>.*?</header>', '', html, count=1, flags=re.S)
|
|
786
|
+
html = html.replace('<body>', '<body>\n' + rail, 1)
|
|
787
|
+
|
|
788
|
+
nexts = [
|
|
789
|
+
("records", "archives", "仓库档案", "下一节", "→"),
|
|
790
|
+
("archives", "index", "仓库索引", "下一节", "→"),
|
|
791
|
+
("index", "numbers", "数据分析", "下一节", "→"),
|
|
792
|
+
("numbers", "about", "关于本报告", "下一节", "→"),
|
|
793
|
+
("about", "top", "回到顶部", "", "↑"),
|
|
794
|
+
]
|
|
795
|
+
for sid, nid, label, kicker, arrow in nexts:
|
|
796
|
+
kick = f'<span class="next-kicker">{kicker}</span>' if kicker else ""
|
|
797
|
+
link = (f'<a class="next-link" href="#{nid}">{kick}'
|
|
798
|
+
f'<span class="name">{label} <i>{arrow}</i></span></a>')
|
|
799
|
+
html = re.sub(
|
|
800
|
+
rf'(<section id="{sid}">)(.*?)(</section>)',
|
|
801
|
+
lambda m, link=link: m.group(1) + m.group(2) + link + m.group(3),
|
|
802
|
+
html, count=1, flags=re.S,
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
html = html.replace(
|
|
806
|
+
'<script>',
|
|
807
|
+
'<a class="to-top" href="#top" aria-label="回到顶部">↑ '
|
|
808
|
+
'<span>顶部</span></a>\n<script>', 1,
|
|
809
|
+
)
|
|
810
|
+
html = html.replace('</body>', """<script>
|
|
811
|
+
(()=>{
|
|
812
|
+
const t=document.querySelector('.to-top');
|
|
813
|
+
const f=()=>t.classList.toggle('show',scrollY>700);
|
|
814
|
+
addEventListener('scroll',f,{passive:true});f();
|
|
815
|
+
const links=[...document.querySelectorAll('.rail-nav a')];
|
|
816
|
+
const byId=new Map(links.map(a=>[a.getAttribute('href').slice(1),a]));
|
|
817
|
+
const spy=new IntersectionObserver(es=>{
|
|
818
|
+
es.forEach(e=>{
|
|
819
|
+
if(!e.isIntersecting)return;
|
|
820
|
+
links.forEach(a=>a.classList.remove('active'));
|
|
821
|
+
const a=byId.get(e.target.id);
|
|
822
|
+
if(a)a.classList.add('active');
|
|
823
|
+
});
|
|
824
|
+
},{rootMargin:'-25% 0px -65% 0px'});
|
|
825
|
+
document.querySelectorAll('section[id]').forEach(s=>spy.observe(s));
|
|
826
|
+
})();
|
|
827
|
+
</script>
|
|
828
|
+
</body>""")
|
|
829
|
+
html = re.sub(r"<h3>(.*?)</h3>", _fix_h3, html, flags=re.S)
|
|
830
|
+
return html.replace('</head>', CSS + '</head>')
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
def to_english(source: str, stats: ReportStats) -> str:
|
|
834
|
+
from .html_report import build_card_preview_widget
|
|
835
|
+
|
|
836
|
+
year = stats.year
|
|
837
|
+
placeholder = "<!--__CODEYEAR_CARD_WIDGET_EN__-->"
|
|
838
|
+
has_widget = "<!--CARD_WIDGET_START-->" in source
|
|
839
|
+
if has_widget:
|
|
840
|
+
source = re.sub(
|
|
841
|
+
r"<!--CARD_WIDGET_START-->.*?<!--CARD_WIDGET_END-->",
|
|
842
|
+
placeholder,
|
|
843
|
+
source,
|
|
844
|
+
count=1,
|
|
845
|
+
flags=re.S,
|
|
846
|
+
)
|
|
847
|
+
html = re.sub(
|
|
848
|
+
r'<p class="lede">.*?</p>',
|
|
849
|
+
f'<p class="lede">{_en_human(stats.lines_changed)} lines of code, '
|
|
850
|
+
f'{stats.active_days} active days, {stats.repo_count} repositories.</p>',
|
|
851
|
+
source, count=1, flags=re.S,
|
|
852
|
+
)
|
|
853
|
+
html = html.replace(
|
|
854
|
+
f'href="codeyear-{year}-en.html">English<',
|
|
855
|
+
f'href="codeyear-{year}.html">中文<',
|
|
856
|
+
)
|
|
857
|
+
html = re.sub(r'<meta name="description" content="[^"]*">',
|
|
858
|
+
'<meta name="description" content="CodeYear annual code report '
|
|
859
|
+
'- a local-first year in review.">', html)
|
|
860
|
+
html = translate_html(html)
|
|
861
|
+
if has_widget:
|
|
862
|
+
html = html.replace(
|
|
863
|
+
placeholder, build_card_preview_widget(stats, lang="en"), 1
|
|
864
|
+
)
|
|
865
|
+
persona = stats.persona
|
|
866
|
+
title_en = getattr(persona, "title_en", persona.title)
|
|
867
|
+
summary_en = getattr(persona, "summary_en", persona.subtitle)
|
|
868
|
+
badges_en = getattr(persona, "badges_en", persona.badges)
|
|
869
|
+
html = re.sub(
|
|
870
|
+
r'(<h2 class="persona-name"[^>]*>).*?(</h2>)',
|
|
871
|
+
lambda m: m.group(1) + htmlmod.escape(title_en) + m.group(2),
|
|
872
|
+
html, count=1, flags=re.S,
|
|
873
|
+
)
|
|
874
|
+
badges = "".join(
|
|
875
|
+
f"<span>{htmlmod.escape(badge)}</span>" for badge in badges_en
|
|
876
|
+
)
|
|
877
|
+
html = re.sub(
|
|
878
|
+
r'(<div class="persona-badges"[^>]*>).*?(</div>)',
|
|
879
|
+
lambda m: m.group(1) + badges + m.group(2),
|
|
880
|
+
html, count=1, flags=re.S,
|
|
881
|
+
)
|
|
882
|
+
html = re.sub(
|
|
883
|
+
r'(<p class="persona-summary"[^>]*>).*?(</p>)',
|
|
884
|
+
lambda m: m.group(1) + htmlmod.escape(summary_en) + m.group(2),
|
|
885
|
+
html, count=1, flags=re.S,
|
|
886
|
+
)
|
|
887
|
+
html = re.sub(r'<title>.*?</title>',
|
|
888
|
+
f'<title>CodeYear {year} · Annual Code Report</title>',
|
|
889
|
+
html, count=1, flags=re.S)
|
|
890
|
+
return html
|