gitsona 0.1.3 → 0.2.1
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.
- package/README.md +12 -21
- package/dist/analyze.js +76 -1
- package/dist/cli.js +34 -9
- package/dist/collect.js +7 -2
- package/dist/preview.js +5 -2
- package/dist/publish.js +17 -7
- package/dist/readme.js +38 -18
- package/dist/render/fonts.js +4 -1
- package/dist/render/hero.js +176 -155
- package/dist/render/index.js +2 -0
- package/dist/render/svg.js +8 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,43 +6,32 @@
|
|
|
6
6
|
|
|
7
7
|
<picture>
|
|
8
8
|
<source media="(prefers-color-scheme: dark)" srcset="docs/example/hero-dark.svg">
|
|
9
|
-
<img alt="Example
|
|
9
|
+
<img alt="Example card: a terminal running gitsona kanywst. On the left, the last 12 months of contributions drawn as ASCII terrain; on the right, the name kt and fetch-style rows: Role Security, authorization and identity; Upstream 68 PRs merged in 49 projects; Most days 309 of 365 days active; Night owl 56% of commits 22:00–02:00; Generalist 5 languages cover 80% of the code; Since Dec 2018" src="docs/example/hero-light.svg" width="100%">
|
|
10
10
|
</picture>
|
|
11
11
|
|
|
12
|
-
It reads your public activity
|
|
12
|
+
It reads your public activity and draws it as a terminal running `gitsona <you>`: your year as ASCII terrain, and the facts as fetch-style rows that type themselves in. Four of them say what sets you apart, each backed by a number. Under the card go the one-sentence summary, your latest repos and your last merged upstream PR. That's the whole profile: one screen, so your pins and contribution graph show right below. Nothing is hosted: the images are plain files in your own repo and make no outside requests. The examples here are the author's profile, drawn from live data.
|
|
13
13
|
|
|
14
14
|
## Two steps to your profile
|
|
15
15
|
|
|
16
16
|
1. **Look.** `npx gitsona --preview`, then open `<you>/gitsona-preview.html`.
|
|
17
|
-
2. **Ship.** `npx gitsona --push --action` commits it to your `<you>/<you>` repo (asks first), with a workflow that redraws it every
|
|
17
|
+
2. **Ship.** `npx gitsona --push --action` commits it to your `<you>/<you>` repo (asks first), with a workflow that redraws it every day. Leave out `--action` to redraw by hand.
|
|
18
18
|
|
|
19
19
|
The token comes from `GITSONA_TOKEN`, `GITHUB_TOKEN`, `GH_TOKEN`, or `gh auth token`, and gitsona draws the account behind it. To draw someone else, name them: `npx gitsona octocat --preview`.
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Want more?
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<picture>
|
|
26
|
-
<source media="(prefers-color-scheme: dark)" srcset="docs/example/traits-dark.svg">
|
|
27
|
-
<img alt="Working style: four spectra with evidence, such as 64 merged PRs across 46 projects owned by others" src="docs/example/traits-light.svg" width="100%">
|
|
28
|
-
</picture>
|
|
29
|
-
|
|
30
|
-
**When you work.** Weekday by hour, read in each commit's own time zone.
|
|
23
|
+
`--sections all` adds five panels under the card, or name the ones you want, in order: `traits`, `rhythm`, `projects`, `strata`, `upstream`.
|
|
31
24
|
|
|
32
25
|
<picture>
|
|
33
26
|
<source media="(prefers-color-scheme: dark)" srcset="docs/example/rhythm-dark.svg">
|
|
34
|
-
<img alt="Rhythm: a weekday by hour dot grid with the 22:00 to 02:00 window highlighted, labelled Night owl" src="docs/example/rhythm-light.svg" width="100%">
|
|
27
|
+
<img alt="Rhythm panel: a weekday by hour dot grid with the 22:00 to 02:00 window highlighted, labelled Night owl" src="docs/example/rhythm-light.svg" width="100%">
|
|
35
28
|
</picture>
|
|
36
29
|
|
|
37
|
-
**Where you give back.** Merged pull requests in projects owned by others.
|
|
38
|
-
|
|
39
30
|
<picture>
|
|
40
31
|
<source media="(prefers-color-scheme: dark)" srcset="docs/example/upstream-dark.svg">
|
|
41
|
-
<img alt="Upstream: merged pull requests per project, led by dexidp/dex and spiffe/spire" src="docs/example/upstream-light.svg" width="100%">
|
|
32
|
+
<img alt="Upstream panel: merged pull requests per project, led by dexidp/dex and spiffe/spire" src="docs/example/upstream-light.svg" width="100%">
|
|
42
33
|
</picture>
|
|
43
34
|
|
|
44
|
-
Plus project cards for notable repos you haven't pinned, and your language mix year by year. All six (`hero`, `traits`, `rhythm`, `projects`, `strata`, `upstream`) are drawn by default; `--sections` picks and orders them.
|
|
45
|
-
|
|
46
35
|
## Pick a typeface
|
|
47
36
|
|
|
48
37
|
<picture>
|
|
@@ -58,23 +47,25 @@ Plus project cards for notable repos you haven't pinned, and your language mix y
|
|
|
58
47
|
| --- | --- |
|
|
59
48
|
| `--preview` | Also write `gitsona-preview.html`, framed like a GitHub profile with a light/dark switch |
|
|
60
49
|
| `--push` | Create `<you>/<you>` if needed, commit and push. `-y` skips the questions |
|
|
61
|
-
| `--action` | Add a
|
|
62
|
-
| `--sections <list>` |
|
|
50
|
+
| `--action` | Add a workflow that redraws the profile every day. `--schedule weekly` for Mondays only |
|
|
51
|
+
| `--sections <list>` | `all`, or pick and order panels, such as `hero,rhythm` |
|
|
63
52
|
| `--font <name>` | `pixel`, `geist`, `mono`, `grotesk`, `rounded` or `retro` |
|
|
64
53
|
| `--accent <hex>` | Accent colour. Defaults to your top language's colour |
|
|
65
54
|
| `--private` | Count private repos in language and topic stats. Their names are never drawn |
|
|
55
|
+
| `--bio` | Repeat your GitHub bio under the card. The sidebar already shows it |
|
|
66
56
|
|
|
67
57
|
`npx gitsona --help` lists the rest. Output goes to `./<you>`, or to `.` inside a `<you>/<you>` checkout; `-o` changes it.
|
|
68
58
|
|
|
69
59
|
## Re-running
|
|
70
60
|
|
|
71
61
|
- Only the block between `<!-- gitsona:start -->` and `<!-- gitsona:end -->` is redrawn. Anything you write outside it stays. A README without the markers keeps its old content below the new block; `--replace` overwrites the whole file instead.
|
|
72
|
-
- The
|
|
62
|
+
- The scheduled workflow redraws with the options of the run that wrote it (`--sections`, `--font`, `--accent`, `--bio` and so on), commits only when something changed, and stays on the gitsona version that wrote it. Run `--action` again to upgrade. For private contribution counts, add a token with repo read access as the `GITSONA_TOKEN` secret.
|
|
73
63
|
|
|
74
64
|
## Notes
|
|
75
65
|
|
|
76
66
|
- Images make no outside requests. Text is drawn as glyph outlines shaped with HarfBuzz, since GitHub's image CSP can block embedded fonts. Characters outside the chosen faces, such as a name in kanji, fall back to the viewer's system font.
|
|
77
67
|
- The GitHub mobile app ignores `<picture>` and always shows the light images.
|
|
68
|
+
- Upstream counts merged PRs in repositories owned by others: not you, and not an organization you belong to. Organizations whose membership the token can't see (private membership with the default Actions token) count as others'. Add `GITSONA_TOKEN` with `read:org` to leave them out.
|
|
78
69
|
- Commit search covers default branches only, and the rhythm panel samples up to 100 commits per month: it describes habits, not totals.
|
|
79
70
|
|
|
80
71
|
## Development
|
package/dist/analyze.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { DOMAINS, domainById, domainVotes, tokens } from "./taxonomy.js";
|
|
2
2
|
const DAY = 86_400_000;
|
|
3
|
+
/** Merged PRs in others' projects it takes for the hero to call someone "Upstream". */
|
|
4
|
+
const UPSTREAM_BADGE = 10;
|
|
5
|
+
const RHYTHM_MIN_SAMPLES = 30;
|
|
6
|
+
const RHYTHM_MIN_SHARE = 0.3;
|
|
3
7
|
const FALLBACK_COLOR = "#8b949e";
|
|
4
8
|
// Generic domains are everywhere (most repos are a CLI or a web page); they only lead when nothing else does.
|
|
5
9
|
const DOMAIN_DAMPING = { devtools: 0.45, web: 0.6, knowledge: 0.8 };
|
|
@@ -15,7 +19,7 @@ export function analyze(raw, now = new Date(raw.fetchedAt)) {
|
|
|
15
19
|
const languages = languageShares(repos);
|
|
16
20
|
const domains = scoreDomains(live, now);
|
|
17
21
|
const lastYear = lastYearStats(raw, now);
|
|
18
|
-
const upstream = upstreamStats(raw.prs, ownOrgs, raw.externalIssues);
|
|
22
|
+
const upstream = { ...upstreamStats(raw.prs, ownOrgs, raw.externalIssues), truncated: raw.prsTruncated === true };
|
|
19
23
|
const rhythm = rhythmStats(raw);
|
|
20
24
|
const traits = buildTraits(raw, { languages, domains, lastYear, upstream, live, now });
|
|
21
25
|
const accent = languages[0]?.color ?? "#5fb3a1";
|
|
@@ -38,6 +42,8 @@ export function analyze(raw, now = new Date(raw.fetchedAt)) {
|
|
|
38
42
|
lastYear,
|
|
39
43
|
lifetime: lifetimeStats(raw),
|
|
40
44
|
traits,
|
|
45
|
+
// "Public non-fork" exactly: forks and the profile repo are already out of `repos`; private ones go here.
|
|
46
|
+
badges: buildBadges(rhythm, lastYear, upstream, languages, repos.filter((r) => !r.isPrivate).length),
|
|
41
47
|
rhythm,
|
|
42
48
|
upstream,
|
|
43
49
|
landmarks: pickLandmarks(raw, live, domains, now),
|
|
@@ -253,6 +259,7 @@ function rhythmStats(raw) {
|
|
|
253
259
|
peakHour,
|
|
254
260
|
window: [bestStart, (bestStart + 4) % 24],
|
|
255
261
|
chronotype,
|
|
262
|
+
share: samples ? best / samples : 0,
|
|
256
263
|
sentence,
|
|
257
264
|
monthly: raw.monthlyCommits,
|
|
258
265
|
};
|
|
@@ -325,6 +332,74 @@ function buildTraits(raw, ctx) {
|
|
|
325
332
|
});
|
|
326
333
|
return traits;
|
|
327
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* The hero's four facts. Every label is chosen from the very number printed beside it, never from a
|
|
337
|
+
* blended score, so a label can't claim more than its number shows.
|
|
338
|
+
*/
|
|
339
|
+
function buildBadges(rhythm, lastYear, upstream, languages, ownRepos) {
|
|
340
|
+
const badges = [];
|
|
341
|
+
const projects = upstream.projects.length;
|
|
342
|
+
const more = upstream.truncated ? "+" : "";
|
|
343
|
+
badges.push(upstream.merged >= UPSTREAM_BADGE
|
|
344
|
+
? {
|
|
345
|
+
id: "upstream",
|
|
346
|
+
label: "Upstream",
|
|
347
|
+
fact: `${upstream.merged}${more} PRs merged in ${projects}${more} ${projects === 1 && !more ? "project" : "projects"}`,
|
|
348
|
+
}
|
|
349
|
+
: {
|
|
350
|
+
id: "upstream",
|
|
351
|
+
label: "Own repos",
|
|
352
|
+
fact: `${ownRepos} public non-fork ${ownRepos === 1 ? "repository" : "repositories"}`,
|
|
353
|
+
});
|
|
354
|
+
const ratio = lastYear.days.length ? lastYear.activeDays / lastYear.days.length : 0;
|
|
355
|
+
badges.push({
|
|
356
|
+
id: "cadence",
|
|
357
|
+
// Words that hold up next to the number: "every" allows one quiet day (today may not have started),
|
|
358
|
+
// "most" means more than half.
|
|
359
|
+
label: lastYear.days.length &&
|
|
360
|
+
(lastYear.activeDays === lastYear.days.length ||
|
|
361
|
+
(lastYear.activeDays === lastYear.days.length - 1 && lastYear.days.at(-1).count === 0))
|
|
362
|
+
? "Every day"
|
|
363
|
+
: ratio >= 0.9
|
|
364
|
+
? "Nearly daily"
|
|
365
|
+
: ratio > 0.5
|
|
366
|
+
? "Most days"
|
|
367
|
+
: ratio >= 0.25
|
|
368
|
+
? "Regularly"
|
|
369
|
+
: "In bursts",
|
|
370
|
+
fact: `${lastYear.activeDays} of ${lastYear.days.length} days active`,
|
|
371
|
+
});
|
|
372
|
+
if (rhythm.samples) {
|
|
373
|
+
const [a, b] = rhythm.window;
|
|
374
|
+
// An even spread already puts 1/6 of commits in any 4-hour window; a chronotype needs a clear lean
|
|
375
|
+
// and enough commits to see it.
|
|
376
|
+
const leans = rhythm.samples >= RHYTHM_MIN_SAMPLES && rhythm.share >= RHYTHM_MIN_SHARE;
|
|
377
|
+
badges.push({
|
|
378
|
+
id: "rhythm",
|
|
379
|
+
label: leans ? rhythm.chronotype : "Any hour",
|
|
380
|
+
fact: `${pct(rhythm.share)} of commits ${fmtHour(a)}–${fmtHour(b)}`,
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
const top = languages[0];
|
|
384
|
+
if (top) {
|
|
385
|
+
let acc = 0;
|
|
386
|
+
let l80 = 0;
|
|
387
|
+
for (const l of languages) {
|
|
388
|
+
if (acc >= 0.8)
|
|
389
|
+
break;
|
|
390
|
+
acc += l.share;
|
|
391
|
+
l80++;
|
|
392
|
+
}
|
|
393
|
+
badges.push(top.share >= 0.6
|
|
394
|
+
? { id: "breadth", label: "Specialist", fact: `${top.name} is ${pct(top.share)} of the code` }
|
|
395
|
+
: {
|
|
396
|
+
id: "breadth",
|
|
397
|
+
label: l80 >= 4 ? "Generalist" : "Focused",
|
|
398
|
+
fact: `${l80} ${l80 === 1 ? "language covers" : "languages cover"} 80% of the code`,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
return badges;
|
|
402
|
+
}
|
|
328
403
|
function joinList(items) {
|
|
329
404
|
if (items.length <= 1)
|
|
330
405
|
return items.join("");
|
package/dist/cli.js
CHANGED
|
@@ -7,10 +7,10 @@ import { analyze } from "./analyze.js";
|
|
|
7
7
|
import { collect } from "./collect.js";
|
|
8
8
|
import { GitHub, GitHubError, resolveToken } from "./github.js";
|
|
9
9
|
import { previewHtml } from "./preview.js";
|
|
10
|
-
import { ASSETS, commitAndPush, createProfileRepo, DRAWN, ensureCheckout, hasGh, repoExists, writeWorkflow, } from "./publish.js";
|
|
10
|
+
import { ASSETS, commitAndPush, createProfileRepo, DRAWN, ensureCheckout, hasGh, repoExists, SCHEDULES, writeWorkflow, } from "./publish.js";
|
|
11
11
|
import { mergeReadme, readmeBlock } from "./readme.js";
|
|
12
12
|
import { DEFAULT_TYPESET, fontFileProblem, TYPESET_NAMES, TYPESETS, withDisplayFont, } from "./render/fonts.js";
|
|
13
|
-
import { fetchAvatars, render, SECTIONS } from "./render/index.js";
|
|
13
|
+
import { DEFAULT_SECTIONS, fetchAvatars, render, SECTIONS } from "./render/index.js";
|
|
14
14
|
import { VERSION } from "./version.js";
|
|
15
15
|
const HELP = `gitsona ${VERSION}
|
|
16
16
|
Draw a GitHub profile README from what you actually do on GitHub.
|
|
@@ -28,19 +28,21 @@ Output
|
|
|
28
28
|
--json Also write ${ASSETS}/profile.json with the derived numbers
|
|
29
29
|
|
|
30
30
|
Content
|
|
31
|
-
--sections <list> Comma-separated, in order: ${SECTIONS.join(",")}
|
|
31
|
+
--sections <list> Comma-separated, in order, or "all": ${SECTIONS.join(",")}
|
|
32
|
+
(default: hero, one screen that leaves room for your pins)
|
|
32
33
|
--font <name> Typeface preset: pixel (default), geist, mono, grotesk, rounded, retro
|
|
33
34
|
--display-font <file>
|
|
34
35
|
Use your own .ttf/.otf for the name and headlines
|
|
35
36
|
--accent <hex> Accent colour (default: your top language's colour)
|
|
36
37
|
--no-motion Skip the contour draw-in animation
|
|
37
|
-
--no-cursor Leave out the
|
|
38
|
-
--
|
|
38
|
+
--no-cursor Leave out the blinking cursor on the last prompt
|
|
39
|
+
--bio Repeat your GitHub bio under the hero (the sidebar already shows it)
|
|
39
40
|
--private Count private repositories in language and topic stats
|
|
40
41
|
(their names are never drawn)
|
|
41
42
|
|
|
42
43
|
Publishing
|
|
43
|
-
--action Add a
|
|
44
|
+
--action Add a GitHub Actions workflow that redraws the profile
|
|
45
|
+
--schedule <when> How often the workflow redraws: daily (default) or weekly
|
|
44
46
|
--push Create <user>/<user> if needed, commit and push (asks first)
|
|
45
47
|
-y, --yes Don't ask before creating the repository or pushing
|
|
46
48
|
|
|
@@ -85,9 +87,12 @@ async function main(argv) {
|
|
|
85
87
|
"display-font": { type: "string" },
|
|
86
88
|
"no-motion": { type: "boolean" },
|
|
87
89
|
"no-cursor": { type: "boolean" },
|
|
90
|
+
bio: { type: "boolean" },
|
|
91
|
+
// Accepted for scripts written for 0.1: the bio is now left out unless --bio asks for it.
|
|
88
92
|
"no-bio": { type: "boolean" },
|
|
89
93
|
private: { type: "boolean" },
|
|
90
94
|
action: { type: "boolean" },
|
|
95
|
+
schedule: { type: "string" },
|
|
91
96
|
push: { type: "boolean" },
|
|
92
97
|
yes: { type: "boolean", short: "y" },
|
|
93
98
|
token: { type: "string" },
|
|
@@ -113,6 +118,9 @@ async function main(argv) {
|
|
|
113
118
|
process.stderr.write(`${s}\n`);
|
|
114
119
|
};
|
|
115
120
|
const sections = parseSections(v.sections);
|
|
121
|
+
const schedule = (v.schedule ?? "daily");
|
|
122
|
+
if (!SCHEDULES.includes(schedule))
|
|
123
|
+
throw new UsageError(`--schedule takes ${SCHEDULES.join(" or ")}.`);
|
|
116
124
|
if (v.accent && !/^#[0-9a-f]{6}$/i.test(v.accent))
|
|
117
125
|
throw new UsageError("--accent takes a hex colour like #3fb950.");
|
|
118
126
|
const fontName = (v.font ?? DEFAULT_TYPESET);
|
|
@@ -171,7 +179,7 @@ async function main(argv) {
|
|
|
171
179
|
const block = readmeBlock(profile, {
|
|
172
180
|
sections: rendered.sections,
|
|
173
181
|
dir: `./${ASSETS}`,
|
|
174
|
-
bio: v["no-bio"] ?
|
|
182
|
+
bio: v.bio && !v["no-bio"] ? profile.bio : null,
|
|
175
183
|
});
|
|
176
184
|
const existing = existsSync(readmePath) ? readFileSync(readmePath, "utf8") : null;
|
|
177
185
|
writeFileSync(readmePath, mergeReadme(existing, block, !!v.replace));
|
|
@@ -181,8 +189,23 @@ async function main(argv) {
|
|
|
181
189
|
}
|
|
182
190
|
if (v.preview)
|
|
183
191
|
writeFileSync(join(out, "gitsona-preview.html"), previewHtml(profile, block));
|
|
184
|
-
if (v.action)
|
|
185
|
-
|
|
192
|
+
if (v.action) {
|
|
193
|
+
// Carry the look of this run into the scheduled ones. Every value here was validated above.
|
|
194
|
+
const keep = [];
|
|
195
|
+
if (v.sections)
|
|
196
|
+
keep.push("--sections", sections.join(","));
|
|
197
|
+
if (fontName !== DEFAULT_TYPESET)
|
|
198
|
+
keep.push("--font", fontName);
|
|
199
|
+
if (v.accent)
|
|
200
|
+
keep.push("--accent", `"${v.accent}"`);
|
|
201
|
+
for (const flag of ["bio", "private", "no-motion", "no-cursor"])
|
|
202
|
+
if (v[flag])
|
|
203
|
+
keep.push(`--${flag}`);
|
|
204
|
+
if (v["display-font"]) {
|
|
205
|
+
log(` note: the workflow can't reach ${v["display-font"]}; scheduled redraws use --font ${fontName}`);
|
|
206
|
+
}
|
|
207
|
+
writeWorkflow(out, schedule, keep);
|
|
208
|
+
}
|
|
186
209
|
const rel = relative(process.cwd(), out) || ".";
|
|
187
210
|
const bytes = [...rendered.files.values()].reduce((s, f) => s + f.length, 0);
|
|
188
211
|
log("");
|
|
@@ -214,6 +237,8 @@ async function main(argv) {
|
|
|
214
237
|
}
|
|
215
238
|
function parseSections(s) {
|
|
216
239
|
if (!s)
|
|
240
|
+
return [...DEFAULT_SECTIONS];
|
|
241
|
+
if (s.trim() === "all")
|
|
217
242
|
return [...SECTIONS];
|
|
218
243
|
const list = s
|
|
219
244
|
.split(",")
|
package/dist/collect.js
CHANGED
|
@@ -48,7 +48,7 @@ export async function collect(gh, login, opts) {
|
|
|
48
48
|
throw new GitHubError(`GitHub user "${login}" was not found.`);
|
|
49
49
|
// Independent queries run together; the search API calls inside each stay sequential or pooled.
|
|
50
50
|
log("repositories, contribution calendar, pull requests and commit times");
|
|
51
|
-
const [repos, years, { prs, authored }, externalIssues, { times, monthly }] = await Promise.all([
|
|
51
|
+
const [repos, years, { prs, authored, truncated }, externalIssues, { times, monthly }] = await Promise.all([
|
|
52
52
|
collectRepos(gh, u.login, opts.includePrivate),
|
|
53
53
|
collectYears(gh, u.login, u.contributionsCollection.contributionYears),
|
|
54
54
|
collectPRs(gh, u.login),
|
|
@@ -78,6 +78,7 @@ export async function collect(gh, login, opts) {
|
|
|
78
78
|
external: prs.length,
|
|
79
79
|
externalMerged: prs.filter((p) => p.state === "MERGED").length,
|
|
80
80
|
},
|
|
81
|
+
prsTruncated: truncated,
|
|
81
82
|
externalIssues,
|
|
82
83
|
commitTimes: times,
|
|
83
84
|
monthlyCommits: monthly,
|
|
@@ -159,6 +160,7 @@ async function collectPRs(gh, login) {
|
|
|
159
160
|
const authored = await searchCount(gh, `author:${login} is:pr`);
|
|
160
161
|
const prs = [];
|
|
161
162
|
let after = null;
|
|
163
|
+
let truncated = false;
|
|
162
164
|
for (let page = 0; page < 10; page++) {
|
|
163
165
|
const d = await gh.graphql(`query($q: String!, $after: String) {
|
|
164
166
|
search(query: $q, type: ISSUE, first: 100, after: $after) {
|
|
@@ -187,9 +189,12 @@ async function collectPRs(gh, login) {
|
|
|
187
189
|
}
|
|
188
190
|
if (!d.search.pageInfo.hasNextPage)
|
|
189
191
|
break;
|
|
192
|
+
// Search serves at most 10 pages; more results past the last one means the counts are lower bounds.
|
|
193
|
+
if (page === 9)
|
|
194
|
+
truncated = true;
|
|
190
195
|
after = d.search.pageInfo.endCursor;
|
|
191
196
|
}
|
|
192
|
-
return { prs, authored };
|
|
197
|
+
return { prs, authored, truncated };
|
|
193
198
|
}
|
|
194
199
|
async function collectCommitTimes(gh, login) {
|
|
195
200
|
// One page per calendar month for the last 12 months. A single newest-first query would hit
|
package/dist/preview.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
function esc(s) {
|
|
2
2
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
3
3
|
}
|
|
4
|
-
/** Just enough Markdown for the block gitsona writes: headings, paragraphs, lists, links, raw HTML. */
|
|
4
|
+
/** Just enough Markdown for the block gitsona writes: headings, paragraphs, lists, links, bold, hard breaks, raw HTML. */
|
|
5
5
|
export function miniMarkdown(md) {
|
|
6
6
|
const inline = (s) => s
|
|
7
7
|
.replace(/\\([\\[\]`*_<>])/g, "\uE000$1")
|
|
8
8
|
.replace(/`([^`]+)`/g, (_, c) => `<code>${esc(c)}</code>`)
|
|
9
|
-
|
|
9
|
+
// The URL comes from the API, but it lands in an attribute: escape quotes along with the rest.
|
|
10
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, t, u) => `<a href="${esc(u).replace(/"/g, """)}">${t}</a>`)
|
|
11
|
+
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
|
10
12
|
.replace(/ {2}$/gm, "<br>")
|
|
13
|
+
.replace(/\\$/gm, "<br>")
|
|
11
14
|
.replace(/\uE000(.)/g, (_, c) => esc(c));
|
|
12
15
|
const blocks = md.split(/\n{2,}/);
|
|
13
16
|
return blocks
|
package/dist/publish.js
CHANGED
|
@@ -121,13 +121,23 @@ export function commitAndPush(dir, paths, message) {
|
|
|
121
121
|
throw new Error(`git push failed: ${p.out}`);
|
|
122
122
|
return "pushed";
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
export const SCHEDULES = ["daily", "weekly"];
|
|
125
|
+
/** Off the hour, so the run doesn't queue behind every other scheduled job at :00. */
|
|
126
|
+
const CRON = { daily: "23 3 * * *", weekly: "23 3 * * 1" };
|
|
127
|
+
/**
|
|
128
|
+
* The scheduled workflow. `args` are the drawing options of the run that wrote it, so each redraw looks
|
|
129
|
+
* the same; callers pass only values the CLI has already validated (section names, preset names, hex).
|
|
130
|
+
*/
|
|
131
|
+
export function workflow(schedule = "daily", args = []) {
|
|
132
|
+
return WORKFLOW.replace("__CRON__", CRON[schedule]).replace("__ARGS__", args.map((a) => ` ${a}`).join(""));
|
|
133
|
+
}
|
|
134
|
+
// Pinned to the release that wrote it, so every scheduled redraw runs the same code instead of
|
|
135
|
+
// whatever is on main. Running gitsona --action again moves the pin.
|
|
136
|
+
const WORKFLOW = `name: gitsona
|
|
127
137
|
|
|
128
138
|
on:
|
|
129
139
|
schedule:
|
|
130
|
-
- cron: "
|
|
140
|
+
- cron: "__CRON__"
|
|
131
141
|
workflow_dispatch:
|
|
132
142
|
|
|
133
143
|
permissions:
|
|
@@ -146,7 +156,7 @@ jobs:
|
|
|
146
156
|
with:
|
|
147
157
|
node-version: 22
|
|
148
158
|
- name: Redraw the profile
|
|
149
|
-
run: npx -y gitsona@${VERSION} "\${{ github.repository_owner }}" --out . --
|
|
159
|
+
run: npx -y gitsona@${VERSION} "\${{ github.repository_owner }}" --out . --quiet__ARGS__
|
|
150
160
|
env:
|
|
151
161
|
# The default token sees public activity. For private contribution counts, add a
|
|
152
162
|
# fine-grained token with read access to your repos as the GITSONA_TOKEN secret.
|
|
@@ -163,10 +173,10 @@ jobs:
|
|
|
163
173
|
git push
|
|
164
174
|
fi
|
|
165
175
|
`;
|
|
166
|
-
export function writeWorkflow(dir) {
|
|
176
|
+
export function writeWorkflow(dir, schedule = "daily", args = []) {
|
|
167
177
|
const wf = join(dir, ".github", "workflows");
|
|
168
178
|
mkdirSync(wf, { recursive: true });
|
|
169
179
|
const path = join(wf, "gitsona.yml");
|
|
170
|
-
writeFileSync(path,
|
|
180
|
+
writeFileSync(path, workflow(schedule, args));
|
|
171
181
|
return path;
|
|
172
182
|
}
|
package/dist/readme.js
CHANGED
|
@@ -12,9 +12,21 @@ function esc(s) {
|
|
|
12
12
|
.replace(/\[/g, "[")
|
|
13
13
|
.replace(/\]/g, "]");
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Text from GitHub (a bio, a PR title) set inline: whitespace collapses so a newline can't start a
|
|
17
|
+
* heading or list, and Markdown punctuation is escaped so it can't end a link or start emphasis.
|
|
18
|
+
*/
|
|
16
19
|
function mdText(s) {
|
|
17
|
-
return s
|
|
20
|
+
return (s
|
|
21
|
+
.replace(/\s+/g, " ")
|
|
22
|
+
.trim()
|
|
23
|
+
.replace(/([\\[\]`*_<>])/g, "\\$1")
|
|
24
|
+
// A leading block marker would turn the line into a heading, list, quote or rule.
|
|
25
|
+
.replace(/^([#+\-=>|~]|\d+(?=[.)]))/, (m) => (/^\d/.test(m) ? `${m}\\` : `\\${m}`)));
|
|
26
|
+
}
|
|
27
|
+
/** Only github.com links go into the README; anything else would be a link we didn't mean to write. */
|
|
28
|
+
function ghUrl(u) {
|
|
29
|
+
return /^https:\/\/github\.com\/[^\s()]+$/.test(u) ? u : null;
|
|
18
30
|
}
|
|
19
31
|
function picture(dir, base, alt, width) {
|
|
20
32
|
const w = width ? ` width="${width}"` : ` width="100%"`;
|
|
@@ -31,25 +43,32 @@ export function readmeBlock(p, opts) {
|
|
|
31
43
|
const out = [START, ""];
|
|
32
44
|
const has = (s) => sections.includes(s);
|
|
33
45
|
if (has("hero")) {
|
|
34
|
-
|
|
46
|
+
const badges = p.badges.map((b) => `${b.label}: ${b.fact}`).join(". ");
|
|
47
|
+
out.push(picture(dir, "hero", `${p.displayName} (@${p.login}). ${p.headline}. ${p.summary} ${badges}.`), "");
|
|
35
48
|
}
|
|
36
|
-
|
|
37
|
-
const bio = opts.bio
|
|
49
|
+
// GitHub's sidebar already shows the bio, website and X handle, so only what it can't show goes here.
|
|
50
|
+
const bio = opts.bio ?? null;
|
|
38
51
|
if (bio)
|
|
39
|
-
|
|
52
|
+
out.push(mdText(bio), "");
|
|
53
|
+
// The card shows the facts; the sentence that ties them together reads better as text, on a phone too.
|
|
54
|
+
if (has("hero"))
|
|
55
|
+
out.push(mdText(p.summary), "");
|
|
56
|
+
const lines = [];
|
|
40
57
|
if (p.recent.length) {
|
|
41
|
-
const links = p.recent
|
|
42
|
-
|
|
58
|
+
const links = p.recent
|
|
59
|
+
.filter((r) => ghUrl(r.url))
|
|
60
|
+
.slice(0, 3)
|
|
61
|
+
.map((r) => `[${mdText(r.name)}](${r.url})`);
|
|
62
|
+
if (links.length)
|
|
63
|
+
lines.push(`**Lately** ${links.join(" · ")}`);
|
|
64
|
+
}
|
|
65
|
+
const last = p.upstream.recentMerged[0];
|
|
66
|
+
if (last && !has("upstream") && ghUrl(last.url)) {
|
|
67
|
+
lines.push(`**Last merged upstream** [${mdText(last.title)}](${last.url}) in \`${last.repo}\``);
|
|
43
68
|
}
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
if (p.twitter)
|
|
48
|
-
contact.push(`[@${p.twitter} on X](https://x.com/${p.twitter})`);
|
|
49
|
-
if (contact.length)
|
|
50
|
-
intro.push(contact.join(", "));
|
|
51
|
-
for (const para of intro)
|
|
52
|
-
out.push(para, "");
|
|
69
|
+
// Two short lines read as one block; a trailing backslash is a hard line break in GFM.
|
|
70
|
+
if (lines.length)
|
|
71
|
+
out.push(lines.join("\\\n"), "");
|
|
53
72
|
if (has("traits")) {
|
|
54
73
|
out.push(`### Working style`, "", picture(dir, "traits", workingStyleAlt(p)), "");
|
|
55
74
|
}
|
|
@@ -59,6 +78,7 @@ export function readmeBlock(p, opts) {
|
|
|
59
78
|
if (has("projects") && p.landmarks.length) {
|
|
60
79
|
out.push(`### Projects`, "");
|
|
61
80
|
out.push(p.landmarks
|
|
81
|
+
.filter((r) => ghUrl(r.url))
|
|
62
82
|
.map((r) =>
|
|
63
83
|
// A Markdown link around a one-line <picture> keeps the card clickable without <a>.
|
|
64
84
|
`[${picture(dir, `project-${slug(r.name)}`, `${r.name}: ${r.description ?? ""}`, "49%").replace(/\n\s*/g, "")}](${r.url})`)
|
|
@@ -73,7 +93,7 @@ export function readmeBlock(p, opts) {
|
|
|
73
93
|
}
|
|
74
94
|
if (has("upstream")) {
|
|
75
95
|
out.push(`### Upstream`, "", picture(dir, "upstream", upstreamAlt(p)), "");
|
|
76
|
-
const recent = p.upstream.recentMerged.slice(0, 5);
|
|
96
|
+
const recent = p.upstream.recentMerged.filter((pr) => ghUrl(pr.url)).slice(0, 5);
|
|
77
97
|
if (recent.length) {
|
|
78
98
|
out.push("Recently merged:", "", ...recent.map((pr) => `- [${mdText(pr.title)}](${pr.url}) in \`${pr.repo}\`, ${fmtDate(pr.mergedAt)}`), "");
|
|
79
99
|
}
|
package/dist/render/fonts.js
CHANGED
|
@@ -13,7 +13,7 @@ const geistMono = (wght) => ({
|
|
|
13
13
|
scale: 0.9,
|
|
14
14
|
});
|
|
15
15
|
/** Data roles shared by most presets: Geist Mono, slightly smaller because a monospace reads large. */
|
|
16
|
-
const MONO_DATA = { regular: geistMono(400), medium: geistMono(500), semibold: geistMono(600) };
|
|
16
|
+
const MONO_DATA = { regular: geistMono(400), medium: geistMono(500), semibold: geistMono(600), mono: geistMono(400) };
|
|
17
17
|
/**
|
|
18
18
|
* Bundled typesets, chosen with --font. Each pairs a face for the name and headlines with one for
|
|
19
19
|
* body text and numbers. All are SIL OFL 1.1; licences sit next to the files in fonts/.
|
|
@@ -51,6 +51,7 @@ export const TYPESETS = {
|
|
|
51
51
|
regular: { file: "SpaceMono-Regular.ttf", system: MONO, weight: 400, scale: 0.88 },
|
|
52
52
|
medium: { file: "SpaceMono-Regular.ttf", system: MONO, weight: 400, scale: 0.88 },
|
|
53
53
|
semibold: { file: "SpaceMono-Bold.ttf", system: MONO, weight: 700, scale: 0.88 },
|
|
54
|
+
mono: { file: "SpaceMono-Regular.ttf", system: MONO, weight: 400, scale: 0.88 },
|
|
54
55
|
},
|
|
55
56
|
},
|
|
56
57
|
rounded: {
|
|
@@ -61,6 +62,8 @@ export const TYPESETS = {
|
|
|
61
62
|
regular: { file: "Rubik.ttf", vars: { wght: 400 }, system: SANS, weight: 400 },
|
|
62
63
|
medium: { file: "Rubik.ttf", vars: { wght: 500 }, system: SANS, weight: 500 },
|
|
63
64
|
semibold: { file: "Rubik.ttf", vars: { wght: 600 }, system: SANS, weight: 600 },
|
|
65
|
+
// Rubik has no monospace cut, so the grid falls back to Geist Mono.
|
|
66
|
+
mono: geistMono(400),
|
|
64
67
|
},
|
|
65
68
|
},
|
|
66
69
|
retro: {
|
package/dist/render/hero.js
CHANGED
|
@@ -1,182 +1,203 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ellipsize, fitSize, measure,
|
|
3
|
-
import { Doc, esc, fmt, r1
|
|
1
|
+
import { makeField, normalize } from "./contour.js";
|
|
2
|
+
import { ellipsize, fitSize, measure, wrap } from "./fonts.js";
|
|
3
|
+
import { Doc, esc, fmt, r1 } from "./svg.js";
|
|
4
4
|
const W = 1200;
|
|
5
|
-
const H_MIN = 480;
|
|
6
5
|
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
6
|
+
/** Density ramp, lightest to heaviest: one character per cell of the terrain. */
|
|
7
|
+
export const RAMP = " .:-=+*#%@";
|
|
7
8
|
export function fmtDate(iso) {
|
|
8
9
|
const d = new Date(iso.length === 10 ? `${iso}T00:00:00Z` : iso);
|
|
9
10
|
return `${d.getUTCDate()} ${MONTHS[d.getUTCMonth()]} ${d.getUTCFullYear()}`;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
|
-
* The last twelve months
|
|
13
|
-
*
|
|
13
|
+
* The last twelve months as ASCII terrain: days sit on a week × weekday lattice, each day raises a
|
|
14
|
+
* hill as high as its contribution count, and every character cell takes the glyph for its height.
|
|
15
|
+
* West to east is time. Returns one string per row.
|
|
14
16
|
*/
|
|
15
|
-
export function
|
|
16
|
-
// Text first: the card grows to fit wider faces or longer headlines instead of overlapping.
|
|
17
|
-
const left = 56;
|
|
18
|
-
const colW = 520;
|
|
19
|
-
const nameSize = fitSize(p.displayName, "display", 104, colW + 60, 48);
|
|
20
|
-
const headline = wrap(p.headline, "text", 30, colW, 2);
|
|
21
|
-
const summary = wrap(p.summary, "regular", 19, colW - 10, 3);
|
|
22
|
-
const textBottom = 76 + 22 + nameSize * 0.7 + 44 + headline.length * 35 + 2 + summary.length * 26;
|
|
23
|
-
const legendRows = 4;
|
|
24
|
-
// Legend starts 22px under the text, its last row sits 58px above the bottom edge (clear of the months).
|
|
25
|
-
const H = Math.max(H_MIN, Math.ceil(textBottom + 22 + (legendRows - 1) * 28 + 58));
|
|
26
|
-
const doc = new Doc(W, H, t, `${p.displayName} (@${p.login}): ${p.headline}`);
|
|
17
|
+
export function asciiTerrain(p, cols, rows) {
|
|
27
18
|
const days = p.lastYear.days;
|
|
28
19
|
const max = Math.max(1, ...days.map((d) => d.count));
|
|
29
|
-
// Terrain frame: days are laid out on a week × weekday lattice spread over the card.
|
|
30
|
-
const x0 = 40;
|
|
31
|
-
const x1 = W - 40;
|
|
32
|
-
const y0 = 64;
|
|
33
|
-
const y1 = H - 78;
|
|
34
20
|
const first = days[0] ? new Date(`${days[0].date}T00:00:00Z`) : new Date();
|
|
35
21
|
const offset = (first.getUTCDay() + 6) % 7;
|
|
36
22
|
const weeks = Math.ceil((days.length + offset) / 7);
|
|
37
|
-
|
|
23
|
+
// Work in a field twice as fine as the character grid, with cells roughly as tall as a glyph.
|
|
24
|
+
const fw = cols * 2;
|
|
25
|
+
const fh = rows * 4;
|
|
26
|
+
const pad = 1.5;
|
|
27
|
+
const hills = days
|
|
28
|
+
.map((d, i) => {
|
|
38
29
|
const k = i + offset;
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const sy = 2 * 30 ** 2;
|
|
48
|
-
const cell = 6;
|
|
49
|
-
const field = normalize(makeField(Math.ceil(W / cell) + 1, Math.ceil(H / cell) + 1, cell, (x, y) => {
|
|
30
|
+
const x = pad + (Math.floor(k / 7) / Math.max(1, weeks - 1)) * (fw - 2 * pad);
|
|
31
|
+
const y = pad + ((k % 7) / 6) * (fh - 2 * pad);
|
|
32
|
+
return { x, y, h: Math.sqrt(d.count / max) };
|
|
33
|
+
})
|
|
34
|
+
.filter((h) => h.h > 0);
|
|
35
|
+
const sx = 2 * (fw / 60) ** 2;
|
|
36
|
+
const sy = 2 * (fh / 10) ** 2;
|
|
37
|
+
const field = normalize(makeField(fw + 1, fh + 1, 1, (x, y) => {
|
|
50
38
|
let v = 0;
|
|
51
|
-
for (const
|
|
52
|
-
const dx = x -
|
|
53
|
-
|
|
54
|
-
if (dx > 70 || dx < -70)
|
|
39
|
+
for (const h of hills) {
|
|
40
|
+
const dx = x - h.x;
|
|
41
|
+
if (dx > fw / 10 || dx < -fw / 10)
|
|
55
42
|
continue;
|
|
56
|
-
|
|
43
|
+
const dy = y - h.y;
|
|
44
|
+
v += h.h * Math.exp(-(dx * dx) / sx - (dy * dy) / sy);
|
|
57
45
|
}
|
|
58
|
-
// A faint swell so quiet stretches still read as land rather than an empty sheet.
|
|
59
|
-
v += 0.05 * (Math.sin(x / 97 + phase[0]) + Math.sin(y / 61 + phase[1]) + Math.sin((x + y) / 143 + phase[2]));
|
|
60
46
|
return v;
|
|
61
47
|
}));
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.join("");
|
|
86
|
-
// Month graticule along the bottom edge.
|
|
87
|
-
const ticks = [];
|
|
88
|
-
days.forEach((d, i) => {
|
|
89
|
-
if (!d.date.endsWith("-01"))
|
|
90
|
-
return;
|
|
91
|
-
const [x] = pos(i);
|
|
92
|
-
const label = MONTHS[+d.date.slice(5, 7) - 1];
|
|
93
|
-
ticks.push(`<line x1="${r1(x)}" y1="${y0 - 18}" x2="${r1(x)}" y2="${H - 44}" stroke="${t.rule}" stroke-width="1" stroke-dasharray="2 5"/>`, doc.text(x, H - 26, d.date.endsWith("01-01") ? `${label} ${d.date.slice(0, 4)}` : label, {
|
|
94
|
-
font: "regular",
|
|
95
|
-
size: 14,
|
|
96
|
-
fill: t.faint,
|
|
97
|
-
anchor: "middle",
|
|
98
|
-
}));
|
|
99
|
-
});
|
|
100
|
-
// Peak marker.
|
|
101
|
-
const peakIdx = days.findIndex((d) => d.date === p.lastYear.peak.date);
|
|
102
|
-
let peak = "";
|
|
103
|
-
if (peakIdx >= 0 && p.lastYear.peak.count > 0) {
|
|
104
|
-
const [px, py] = pos(peakIdx);
|
|
105
|
-
const label = `${fmt(p.lastYear.peak.count)} on ${fmtDate(p.lastYear.peak.date)}`;
|
|
106
|
-
const lw = measure(label, "medium", 15);
|
|
107
|
-
const right = px + 14 + lw < W - 24;
|
|
108
|
-
const lx = right ? px + 12 : px - 12;
|
|
109
|
-
peak =
|
|
110
|
-
`<g class="pk">` +
|
|
111
|
-
`<path d="M${r1(px)} ${r1(py - 7)}l6.5 11h-13z" fill="${t.accent}" stroke="${t.bg}" stroke-width="2" paint-order="stroke"/>` +
|
|
112
|
-
doc.text(lx, py + 3, label, {
|
|
113
|
-
font: "medium",
|
|
114
|
-
size: 15,
|
|
115
|
-
fill: t.ink,
|
|
116
|
-
anchor: right ? "start" : "end",
|
|
117
|
-
tnum: true,
|
|
118
|
-
halo: { color: t.bg, width: 2.5 },
|
|
119
|
-
}) +
|
|
120
|
-
`</g>`;
|
|
48
|
+
const at = (i, j) => {
|
|
49
|
+
const fx = Math.round((i / Math.max(1, cols - 1)) * fw);
|
|
50
|
+
const fy = Math.round((j / Math.max(1, rows - 1)) * fh);
|
|
51
|
+
return field.values[fy * field.cols + fx];
|
|
52
|
+
};
|
|
53
|
+
// Normalise over the cells actually drawn, so the highest cell always gets the heaviest glyph.
|
|
54
|
+
const cells = Array.from({ length: rows }, (_, j) => Array.from({ length: cols }, (_, i) => at(i, j)));
|
|
55
|
+
const top = Math.max(1e-9, ...cells.flat());
|
|
56
|
+
return cells.map((row) => row.map((v) => RAMP[Math.min(RAMP.length - 1, Math.floor((v / top) ** 0.8 * RAMP.length))]).join(""));
|
|
57
|
+
}
|
|
58
|
+
const HANDLE_SIZE = 20;
|
|
59
|
+
/**
|
|
60
|
+
* Fits the name and the @handle on one line `avail` wide. The name shrinks first; a handle that still
|
|
61
|
+
* does not fit is shortened, and left out when too little room is left (the title bar names the login).
|
|
62
|
+
* Offsets are relative to the start of the line.
|
|
63
|
+
*/
|
|
64
|
+
export function nameLine(name, login, avail) {
|
|
65
|
+
const gap = 18;
|
|
66
|
+
const handle = `@${login}`;
|
|
67
|
+
const hw = measure(handle, "mono", HANDLE_SIZE);
|
|
68
|
+
let size = fitSize(name, "display", 72, avail - gap - hw, 36);
|
|
69
|
+
if (measure(name, "display", size) + gap + hw <= avail) {
|
|
70
|
+
return { name, size, handle, handleX: measure(name, "display", size) + gap };
|
|
121
71
|
}
|
|
122
|
-
|
|
72
|
+
size = fitSize(name, "display", 72, avail, 36);
|
|
73
|
+
const shown = ellipsize(name, "display", size, avail);
|
|
74
|
+
const room = avail - measure(shown, "display", size) - gap;
|
|
75
|
+
const short = room >= 90 ? ellipsize(handle, "mono", HANDLE_SIZE, room) : null;
|
|
76
|
+
return { name: shown, size, handle: short, handleX: measure(shown, "display", size) + gap };
|
|
77
|
+
}
|
|
78
|
+
/** Keeps only the characters of `line` that fall in `set`; the rest become spaces, so tones stay aligned. */
|
|
79
|
+
function only(line, set) {
|
|
80
|
+
return [...line].map((c) => (set.includes(c) ? c : " ")).join("");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A terminal running `gitsona <login>`: the year as ASCII terrain in the logo slot, and the facts as
|
|
84
|
+
* fetch-style rows that type themselves in.
|
|
85
|
+
*/
|
|
86
|
+
export function hero(p, t, opts = {}) {
|
|
87
|
+
const motion = opts.motion !== false;
|
|
88
|
+
const L = 44;
|
|
89
|
+
const top = 44; // title bar
|
|
90
|
+
// Right column: the name, then the rows.
|
|
91
|
+
const rx = 540;
|
|
92
|
+
const fs = 22; // row size: large enough to survive a phone-width README
|
|
93
|
+
const lh = 37;
|
|
123
94
|
const joined = new Date(p.joined);
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
95
|
+
const facts = [
|
|
96
|
+
["Role", p.headline],
|
|
97
|
+
...p.badges.map((b) => [b.label, b.fact]),
|
|
98
|
+
["Since", `${MONTHS[joined.getUTCMonth()]} ${joined.getUTCFullYear()}`],
|
|
99
|
+
];
|
|
100
|
+
// Values line up one column after the longest key, as fetch tools do.
|
|
101
|
+
const vx = rx + Math.max(...facts.map(([k]) => measure(`${k}:`, "mono", fs))) + measure("00", "mono", fs);
|
|
102
|
+
const valueW = W - 44 - vx;
|
|
103
|
+
const rows = facts.map(([k, v]) => [k, wrap(v, "mono", fs, valueW, 2)]);
|
|
104
|
+
const head = nameLine(p.displayName, p.login, W - 44 - rx);
|
|
105
|
+
const nameSize = head.size;
|
|
106
|
+
const nameY = top + 52 + nameSize * 0.72;
|
|
107
|
+
const ruleY = nameY + 26;
|
|
108
|
+
const rowsY = ruleY + 44;
|
|
109
|
+
const lineCount = rows.reduce((n, [, v]) => n + v.length, 0);
|
|
110
|
+
const paletteY = rowsY + (lineCount - 1) * lh + 30;
|
|
111
|
+
const H = Math.max(500, Math.ceil(paletteY + 20 + 64));
|
|
112
|
+
const doc = new Doc(W, H, t, `${p.displayName} (@${p.login}): ${p.headline}`);
|
|
113
|
+
const parts = [];
|
|
114
|
+
// Window chrome.
|
|
115
|
+
const bar = mixHex(t.bg, t.contour, 0.75);
|
|
116
|
+
parts.push(`<path d="M1 ${top}V14Q1 1 14 1H${W - 14}Q${W - 1} 1 ${W - 1} 14V${top}Z" fill="${bar}"/>`, `<line x1="1" x2="${W - 1}" y1="${top}" y2="${top}" stroke="${t.rule}"/>`, ...["#ff5f57", "#febc2e", "#28c840"].map((c, i) => `<circle cx="${28 + i * 20}" cy="22" r="6" fill="${c}"/>`), doc.text(W / 2, 28, `${p.login}@github: ~`, { font: "mono", size: 14, fill: t.muted, anchor: "middle" }));
|
|
117
|
+
// Prompt.
|
|
118
|
+
const prompt = `$ gitsona ${p.login}`;
|
|
119
|
+
parts.push(typed(doc, t, L, top + 42, prompt, { font: "mono", size: 17, fill: t.muted }, motion ? 150 : -1));
|
|
120
|
+
// Logo slot: the year as ASCII terrain, in three tones.
|
|
121
|
+
const artSize = 15;
|
|
122
|
+
const adv = measure("0", "mono", artSize);
|
|
123
|
+
const artTop = top + 86;
|
|
124
|
+
const artRows = Math.max(10, Math.floor((paletteY - artTop) / 20) + 1);
|
|
125
|
+
const cols = Math.floor((rx - L - 36) / adv);
|
|
126
|
+
const art = asciiTerrain(p, cols, artRows);
|
|
127
|
+
// Three tones: quiet ground, slopes, and the peaks in the accent colour.
|
|
128
|
+
const tones = [
|
|
129
|
+
// Quiet ground still clears 3:1 against the window, a quarter of the way from faint to muted.
|
|
130
|
+
[".:-=", mixHex(t.faint, t.muted, 0.25)],
|
|
131
|
+
["+*", t.muted],
|
|
132
|
+
["#%@", t.accent],
|
|
133
|
+
];
|
|
134
|
+
art.forEach((line, j) => {
|
|
135
|
+
const y = artTop + j * 20;
|
|
136
|
+
const g = tones
|
|
137
|
+
.map(([set, fill]) => doc.text(L, y, only(line, set), { font: "mono", size: artSize, fill }))
|
|
138
|
+
.join("");
|
|
139
|
+
parts.push(motion ? `<g class="ar" style="animation-delay:${450 + j * 45}ms">${g}</g>` : g);
|
|
140
|
+
});
|
|
141
|
+
parts.push(doc.text(L, H - 26, `${fmt(p.lastYear.total)} contributions · ${fmtDate(p.lastYear.days[0]?.date ?? p.generatedAt)} → today`, {
|
|
142
|
+
font: "mono",
|
|
143
|
+
size: 14,
|
|
144
|
+
fill: t.muted,
|
|
135
145
|
}));
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
// Right column: name, rule, rows.
|
|
147
|
+
parts.push(doc.text(rx - nameSize * 0.04, nameY, head.name, { font: "display", size: nameSize, fill: t.ink }));
|
|
148
|
+
if (head.handle) {
|
|
149
|
+
parts.push(doc.text(rx + head.handleX, nameY, head.handle, { font: "mono", size: HANDLE_SIZE, fill: t.accent }));
|
|
139
150
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
parts.push(`<line x1="${rx}" x2="${W - 44}" y1="${ruleY}" y2="${ruleY}" stroke="${t.faint}" stroke-width="1.5" stroke-dasharray="6 6"/>`);
|
|
152
|
+
let y = rowsY;
|
|
153
|
+
let delay = 900;
|
|
154
|
+
for (const [key, lines] of rows) {
|
|
155
|
+
parts.push(doc.text(rx, y, `${key}:`, { font: "mono", size: fs, fill: t.accent }));
|
|
156
|
+
for (const line of lines) {
|
|
157
|
+
parts.push(typed(doc, t, vx, y, line, { font: "mono", size: fs, fill: t.ink }, motion ? delay : -1));
|
|
158
|
+
delay += 220;
|
|
159
|
+
y += lh;
|
|
160
|
+
}
|
|
144
161
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
y
|
|
162
|
+
// Palette row, then the prompt again with a cursor.
|
|
163
|
+
const pal = ["#e06c75", "#e5c07b", "#98c379", "#56b6c2", "#61afef", "#c678dd", t.accent, t.ink];
|
|
164
|
+
for (const [i, c] of pal.entries()) {
|
|
165
|
+
parts.push(`<rect x="${rx + i * 40}" y="${r1(paletteY)}" width="36" height="20" fill="${c}"/>`);
|
|
149
166
|
}
|
|
150
|
-
const
|
|
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
|
-
|
|
167
|
+
const py = H - 26;
|
|
168
|
+
parts.push(doc.text(rx, py, "$", { font: "mono", size: 17, fill: t.muted }));
|
|
169
|
+
if (opts.cursor !== false) {
|
|
170
|
+
const cw = measure("0", "mono", 17);
|
|
171
|
+
parts.push(`<rect class="cur" x="${r1(rx + cw * 2)}" y="${py - 16}" width="${r1(cw)}" height="20" fill="${t.accent}"/>`);
|
|
172
|
+
}
|
|
173
|
+
if (motion) {
|
|
174
|
+
doc.style(`.ar{animation:ar .35s ease-out backwards}@keyframes ar{from{opacity:0}}` +
|
|
175
|
+
`.ty{animation:ty .5s forwards}@keyframes ty{99%{transform:translateX(var(--w));opacity:1}100%{transform:translateX(var(--w));opacity:0}}` +
|
|
176
|
+
`.cur{animation:cur 1.1s steps(1) infinite}@keyframes cur{50%{opacity:0}}` +
|
|
177
|
+
`@media (prefers-reduced-motion:reduce){.ar,.ty,.cur{animation:none}.ty{opacity:0}}`);
|
|
178
|
+
}
|
|
179
|
+
return doc.render(parts.join(""));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Text that types itself in: a cover the colour of the window slides off it in steps, one per few
|
|
183
|
+
* characters. With delay < 0 the text is simply drawn.
|
|
184
|
+
*/
|
|
185
|
+
function typed(doc, t, x, y, s, o, delay) {
|
|
186
|
+
const text = doc.text(x, y, s, o);
|
|
187
|
+
if (delay < 0)
|
|
188
|
+
return text;
|
|
189
|
+
const w = Math.ceil(measure(s, o.font, o.size)) + 8;
|
|
190
|
+
const steps = Math.max(3, Math.round(s.length / 2));
|
|
191
|
+
return (text +
|
|
192
|
+
`<rect class="ty" x="${r1(x - 2)}" y="${r1(y - o.size)}" width="${w}" height="${Math.round(o.size * 1.35)}" fill="${t.bg}" style="--w:${w}px;animation-delay:${delay}ms;animation-timing-function:steps(${steps})"/>`);
|
|
193
|
+
}
|
|
194
|
+
function mixHex(a, b, k) {
|
|
195
|
+
const pa = [1, 3, 5].map((i) => Number.parseInt(a.slice(i, i + 2), 16));
|
|
196
|
+
const pb = [1, 3, 5].map((i) => Number.parseInt(b.slice(i, i + 2), 16));
|
|
197
|
+
return `#${pa
|
|
198
|
+
.map((v, i) => Math.round(v + (pb[i] - v) * k)
|
|
199
|
+
.toString(16)
|
|
200
|
+
.padStart(2, "0"))
|
|
201
|
+
.join("")}`;
|
|
181
202
|
}
|
|
182
203
|
export { esc };
|
package/dist/render/index.js
CHANGED
|
@@ -3,6 +3,8 @@ import { hero } from "./hero.js";
|
|
|
3
3
|
import { card, rhythm, strata, traits, upstream } from "./panels.js";
|
|
4
4
|
import { theme } from "./theme.js";
|
|
5
5
|
export const SECTIONS = ["hero", "traits", "rhythm", "projects", "strata", "upstream"];
|
|
6
|
+
/** One screen: the hero carries the key points, and GitHub's own pins and graph show right below. */
|
|
7
|
+
export const DEFAULT_SECTIONS = ["hero"];
|
|
6
8
|
export const MODES = ["dark", "light"];
|
|
7
9
|
export async function fetchAvatars(gh, p) {
|
|
8
10
|
const urls = [...new Set(p.upstream.projects.slice(0, 8).map((x) => x.ownerAvatar))];
|
package/dist/render/svg.js
CHANGED
|
@@ -11,7 +11,14 @@ export function fmt(n) {
|
|
|
11
11
|
return `${(n / 1000).toFixed(1).replace(/\.0$/, "")}k`;
|
|
12
12
|
return n.toLocaleString("en-US");
|
|
13
13
|
}
|
|
14
|
-
const FONT_KEY = {
|
|
14
|
+
const FONT_KEY = {
|
|
15
|
+
display: "d",
|
|
16
|
+
text: "t",
|
|
17
|
+
regular: "r",
|
|
18
|
+
medium: "m",
|
|
19
|
+
semibold: "s",
|
|
20
|
+
mono: "o",
|
|
21
|
+
};
|
|
15
22
|
export class Doc {
|
|
16
23
|
width;
|
|
17
24
|
height;
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Kept equal to package.json by test/version.test.ts; the release workflow runs that test before publishing. */
|
|
2
|
-
export const VERSION = "0.1
|
|
2
|
+
export const VERSION = "0.2.1";
|
package/package.json
CHANGED