Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
265 lines (240 loc) · 10.9 KB
/
Copy pathindex.html
File metadata and controls
265 lines (240 loc) · 10.9 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>palukku · Stats</title>
<meta name="description" content="Public GitHub stats for palukku, updated live.">
<style>
:root {
--bg: #f6f7f9;
--card: #ffffff;
--text: #1b1f24;
--muted: #5d6673;
--border: #e1e4e8;
--accent: #2f6feb;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0d1117;
--card: #161b22;
--text: #e6edf3;
--muted: #8b949e;
--border: #30363d;
--accent: #58a6ff;
}
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--text);
font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 860px; margin: 0 auto; padding: 48px 16px; }
header { display: flex; align-items: center; gap: 16px; margin-bottom: 32px; flex-wrap: wrap; }
header img { width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--border); }
h1 { margin: 0; font-size: 1.6rem; }
h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 32px 0 12px; }
a { color: var(--accent); }
.profile-link {
margin-left: auto;
padding: 8px 14px;
border: 1px solid var(--border);
border-radius: 8px;
background: var(--card);
text-decoration: none;
font-weight: 600;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.stat .value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 0.875rem; }
.list { background: var(--card); border: 1px solid var(--border); border-radius: 10px; margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.list .meta { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.list a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
footer { margin-top: 40px; color: var(--muted); font-size: 0.875rem; }
.error { color: #d73a49; }
.orgs { display: flex; flex-wrap: wrap; gap: 10px; }
.org {
display: flex; align-items: center; gap: 8px;
padding: 6px 12px 6px 6px;
background: var(--card); border: 1px solid var(--border); border-radius: 999px;
text-decoration: none; color: var(--text); font-weight: 600;
}
.org img { width: 28px; height: 28px; border-radius: 6px; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-main small { color: var(--muted); }
.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); }
.badge.merged { color: #8250df; border-color: #8250df; }
.badge.open { color: #1a7f37; border-color: #1a7f37; }
.badge.closed { color: var(--muted); }
</style>
</head>
<body>
<main>
<header>
<img id="avatar" alt="" src="https://github.com/palukku.png?size=144">
<div>
<h1 id="name">palukku</h1>
<div id="bio" style="color: var(--muted)"></div>
</div>
<a class="profile-link" href="https://github.com/palukku" rel="noopener">GitHub profile →</a>
</header>
<h2>Recent Open-source contributions</h2>
<div class="grid">
<div class="stat"><div class="value" id="c-merged">–</div><div class="label">Merged pull requests</div></div>
<div class="stat"><div class="value" id="c-prs">–</div><div class="label">Pull requests opened</div></div>
<div class="stat"><div class="value" id="c-issues">–</div><div class="label">Issues opened</div></div>
<div class="stat"><div class="value" id="c-repos">–</div><div class="label">Repos contributed to</div></div>
</div>
<h2>Organizations</h2>
<div class="orgs" id="orgs">Loading…</div>
<h2>Contributions by repository</h2>
<ul class="list" id="by-repo"><li>Loading…</li></ul>
<h2>Recent pull requests</h2>
<ul class="list" id="recent-prs"><li>Loading…</li></ul>
<h2>Own profile</h2>
<div class="grid">
<div class="stat"><div class="value" id="s-repos">–</div><div class="label">Public repos</div></div>
<div class="stat"><div class="value" id="s-stars">–</div><div class="label">Stars received</div></div>
<div class="stat"><div class="value" id="s-followers">–</div><div class="label">Followers</div></div>
<div class="stat"><div class="value" id="s-following">–</div><div class="label">Following</div></div>
</div>
<footer>
Public data from the GitHub API · refreshes every hour ·
<span id="updated">not loaded yet</span>
</footer>
</main>
<script>
const USER = "palukku";
const API = "https://api.github.com";
const REFRESH_MS = 60 * 60 * 1000;
const CACHE_KEY = "gh-stats-v2";
const $ = (id) => document.getElementById(id);
const fmt = new Intl.NumberFormat("en-US");
const date = new Intl.DateTimeFormat("en-US", { dateStyle: "medium" });
async function getJSON(url) {
const res = await fetch(url, { headers: { Accept: "application/vnd.github+json" } });
if (!res.ok) throw new Error(`GitHub API responded with ${res.status}`);
return res.json();
}
async function getAll(path) {
const items = [];
for (let page = 1; page <= 10; page++) {
const sep = path.includes("?") ? "&" : "?";
const data = await getJSON(`${API}${path}${sep}per_page=100&page=${page}`);
const batch = Array.isArray(data) ? data : data.items;
items.push(...batch);
if (batch.length < 100) break;
}
return items;
}
function el(tag, props = {}, ...children) {
const node = Object.assign(document.createElement(tag), props);
node.append(...children);
return node;
}
// "https://api.github.com/repos/owner/name" -> "owner/name"
const repoName = (item) => item.repository_url.split("/repos/")[1];
async function load() {
const external = `-user:${USER}`;
const [user, repos, orgs, prs, issues] = await Promise.all([
getJSON(`${API}/users/${USER}`),
getAll(`/users/${USER}/repos`),
getJSON(`${API}/users/${USER}/orgs`),
getAll(`/search/issues?q=author:${USER}+type:pr+${external}&sort=created&order=desc`),
getAll(`/search/issues?q=author:${USER}+type:issue+${external}&sort=created&order=desc`),
]);
// Keep only the fields the page uses, so the cache stays small.
const slim = (i) => ({
repo: repoName(i), title: i.title, url: i.html_url, state: i.state,
created: i.created_at, merged: i.pull_request ? i.pull_request.merged_at : null,
});
return {
time: Date.now(),
user: { login: user.login, name: user.name, bio: user.bio, avatar: user.avatar_url,
repos: user.public_repos, followers: user.followers, following: user.following },
stars: repos.filter((r) => !r.fork).reduce((s, r) => s + r.stargazers_count, 0),
orgs: orgs.map((o) => ({ login: o.login, avatar: o.avatar_url })),
prs: prs.map(slim),
issues: issues.map(slim),
};
}
function prBadge(pr) {
const kind = pr.merged ? "merged" : pr.state;
return el("span", { className: `badge ${kind}`, textContent: kind });
}
function render(d) {
$("avatar").src = d.user.avatar;
$("name").textContent = d.user.name || d.user.login;
$("bio").textContent = d.user.bio || "";
$("s-repos").textContent = fmt.format(d.user.repos);
$("s-followers").textContent = fmt.format(d.user.followers);
$("s-following").textContent = fmt.format(d.user.following);
$("s-stars").textContent = fmt.format(d.stars);
const merged = d.prs.filter((p) => p.merged);
$("c-merged").textContent = fmt.format(merged.length);
$("c-prs").textContent = fmt.format(d.prs.length);
$("c-issues").textContent = fmt.format(d.issues.length);
// Per-repository breakdown
const byRepo = {};
for (const p of d.prs) {
const r = (byRepo[p.repo] ||= { prs: 0, merged: 0, issues: 0 });
r.prs++;
if (p.merged) r.merged++;
}
for (const i of d.issues) (byRepo[i.repo] ||= { prs: 0, merged: 0, issues: 0 }).issues++;
const rows = Object.entries(byRepo).sort((a, b) =>
b[1].merged - a[1].merged || b[1].prs - a[1].prs || b[1].issues - a[1].issues);
$("c-repos").textContent = fmt.format(rows.length);
$("by-repo").replaceChildren(...(rows.length ? rows.map(([name, r]) => {
const parts = [];
if (r.prs) parts.push(`${r.merged}/${r.prs} PRs merged`);
if (r.issues) parts.push(`${r.issues} ${r.issues === 1 ? "issue" : "issues"}`);
return el("li", {},
el("a", { href: `https://github.com/${name}`, textContent: name, rel: "noopener" }),
el("span", { className: "meta", textContent: parts.join(" · ") }));
}) : [el("li", { textContent: "No public contributions found" })]));
// Organizations (public memberships only)
$("orgs").replaceChildren(...(d.orgs.length ? d.orgs.map((o) =>
el("a", { className: "org", href: `https://github.com/${o.login}`, rel: "noopener" },
el("img", { src: o.avatar, alt: "" }), o.login)
) : ["No public organization memberships"]));
// Most recent pull requests
$("recent-prs").replaceChildren(...(d.prs.length ? d.prs.slice(0, 8).map((p) =>
el("li", {},
el("div", { className: "row-main" },
el("a", { href: p.url, textContent: p.title, rel: "noopener" }),
el("small", { textContent: `${p.repo} · ${date.format(new Date(p.created))}` })),
el("span", {}, prBadge(p)))
) : [el("li", { textContent: "No pull requests yet" })]));
$("updated").className = "";
$("updated").textContent = "last updated: " + new Date(d.time).toLocaleString("en-US");
}
function readCache() {
try { return JSON.parse(localStorage.getItem(CACHE_KEY)); } catch { return null; }
}
async function refresh() {
const cached = readCache();
if (cached && Date.now() - cached.time < REFRESH_MS) {
render(cached);
return;
}
try {
const data = await load();
try { localStorage.setItem(CACHE_KEY, JSON.stringify(data)); } catch {}
render(data);
} catch (err) {
if (cached) render(cached);
$("updated").className = "error";
$("updated").textContent = "Failed to load: " + err.message;
}
}
refresh();
setInterval(refresh, REFRESH_MS);
</script>
</body>
</html>