mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:21:13 +00:00
* Type model, templates, reviews and sms pages under strict Props, state, refs and handlers typed; null guards where the types showed a possible null. creativeData exports Slug. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type Kai/Mori/Koe/Uta, research, philosophy, press and risk pages under strict Props, state, refs and handlers typed; ref callbacks no longer return the element. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type x-tender, solutions, story, tag, startups, support, newsletter and mcp pages under strict Captured-page trees and docs get shared types. Null-safe reads where a figure has no source or a page has no siblings. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type open source, platform, products, operative, trust, sdks and o11y pages under strict Captured-page trees, product docs and org data get shared types. Null guards on refs and canvas contexts; product() throws a clear error for a captured page with no API section. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type post, pricing, team, slack, skills, security, tabs and proof pages under strict Live pricing uses the lib Rung/Group/Row types. Null guards on refs and canvas contexts. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type models, studio, university, science, referral, operator, network and module pages under strict Model and university data tables get explicit row types; the Opener shape is shared by ModelsPage and Studio. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Narrow the review entry in its test entry() returns Review | null under strict; the test asserts it is set before use. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Type the Newsletter send button ref as a button Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk * Fit the callers of the typed pages to their types Product, solutions and tabs-tree callers use the page types; the open-source snapshot reads lib/oss's own Summary and Activity; the O11y card ref is a list item ref. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
68 lines
4.7 KiB
TypeScript
68 lines
4.7 KiB
TypeScript
// The figures /open-source shows, as the page draws them: `sum` and `act` are lib/oss.mjs's combine(), the estate and
|
|
// GitHub as hanzo-inc/app's scripts/sync-oss.ts writes them. scripts/live.mjs calls shape() and writes snapshot.js.
|
|
import { cuts, shade } from '../../../lib/heat.ts';
|
|
import type { Activity, Snapshot, Summary } from './types.ts';
|
|
|
|
const n = (x: number | string) => Number(x).toLocaleString('en-US');
|
|
const plural = (v: number, one: string, many: string) => `${n(v)} ${v === 1 ? one : many}`;
|
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
const d2 = (x: number) => String(x).padStart(2, '0');
|
|
const at = (iso: string) => { const d = new Date(iso); return `${MON[d.getUTCMonth()]} ${d.getUTCDate()}, ${d2(d.getUTCHours())}:${d2(d.getUTCMinutes())}`; };
|
|
const day = (iso: string) => { const d = new Date(iso.length === 10 ? iso + 'T00:00:00Z' : iso); return `${MON[d.getUTCMonth()]} ${d.getUTCDate()}, ${d.getUTCFullYear()}`; };
|
|
|
|
// a year of commits a day as one character a day, Sunday-first weeks ('.' before the first day); levels as Hanzo draws
|
|
// them: 0 for a day without commits, then the quartiles of the days with commits
|
|
export function heat(daily: Record<string, number>, from: string, to: string) {
|
|
const days: number[] = [];
|
|
for (let t = Date.parse(from + 'T00:00:00Z'), end = Date.parse(to + 'T00:00:00Z'); t <= end; t += 864e5) days.push(daily[new Date(t).toISOString().slice(0, 10)] || 0);
|
|
const cut = cuts(days);
|
|
return '.'.repeat(new Date(from + 'T00:00:00Z').getUTCDay()) + days.map((v) => shade(v, cut)).join('');
|
|
}
|
|
|
|
export function shape({ sum, act }: { sum: Summary; act: Activity }): Snapshot {
|
|
const KEYS = ['hanzo', 'lux', 'zoo'];
|
|
const win = `Commits a day, from ${day(act.from)} to ${day(act.to)}`;
|
|
const eco = KEYS.map((k) => {
|
|
const g = sum.groups[k], a = act.groups[k], gh = 'https://github.com/' + g.lead;
|
|
const tot = g.languages.reduce((s, l) => s + l.count, 0);
|
|
const pc = (c: number) => ((c / tot) * 100).toFixed(1), five = g.languages.slice(0, 5);
|
|
const top = five.map((l) => [l.name, pc(l.count)]), other = pc(tot - five.reduce((s, l) => s + l.count, 0));
|
|
return {
|
|
stats: [['Commits', n(g.commits.year), 'In the past year'], ['Merges', n(g.estate.merges as number), 'In the past year'], ['Commits', n(g.commits.week), 'In the past 7 days'],
|
|
[`${g.checked} organizations`, n(g.repos), 'Original repositories'], ['GitHub stars', n(g.stars), 'as GitHub counts them'], ['GitHub forks', n(g.forks), 'as GitHub counts them']],
|
|
heat: heat(a.daily, act.from, act.to),
|
|
window: win,
|
|
commits: a.latest.map((c) => [c.repo, c.message, at(c.at), c.url]),
|
|
read: 'Forge listing · read ' + at(sum.forge.read),
|
|
langs: [...top, ['Other', other]],
|
|
langCap: `The primary language of each of ${n(g.repos)} original repositories, as GitHub reads it`,
|
|
repos: g.top.map((r) => {
|
|
const faces = r.faces ?? [];
|
|
return {
|
|
name: r.repo, desc: r.description || '', lang: r.language || '', stars: n(r.stars ?? 0), forks: n(r.forks ?? 0),
|
|
av: faces.slice(0, 3).map((f) => f[0].toUpperCase()).join(''), more: faces.length > 3 ? '+' + (faces.length - 3) : '',
|
|
people: plural(r.contributors ?? 0, 'contributor', 'contributors'), commits: plural(r.commits ?? 0, 'commit this year', 'commits this year'),
|
|
pushed: r.pushed ? 'Pushed ' + day(r.pushed) : '', to: r.forge ?? 'https://github.com/' + r.repo, months: r.months,
|
|
};
|
|
}),
|
|
readTo: gh,
|
|
statTo: ['https://git.hanzo.ai/explore/repos', 'https://git.hanzo.ai/explore/repos', 'https://git.hanzo.ai/explore/repos', gh, gh, gh],
|
|
};
|
|
});
|
|
const orgs = KEYS.map((k) => {
|
|
const g = sum.groups[k];
|
|
return {
|
|
key: k, name: g.name, sub: `${g.orgs.length} organizations · ${n(g.repos)} repositories`,
|
|
orgs: g.orgs.map((o) => ({ name: o.name || o.login, login: o.login, repos: plural(o.repos, 'repository', 'repositories'),
|
|
commits: o.commits ? plural(o.commits, 'commit this year', 'commits this year') : '', stars: n(o.stars), desc: o.description || '', months: o.months })),
|
|
};
|
|
});
|
|
const groups = KEYS.map((k) => sum.groups[k]);
|
|
return {
|
|
eco, orgs,
|
|
total: [[n(sum.estate.commits), 'Commits, past year'], [n(groups.reduce((s, g) => s + g.repos, 0)), 'Original public repositories'], [n(groups.reduce((s, g) => s + g.stars, 0)), 'GitHub stars']],
|
|
hero: [[n(sum.groups.hanzo.repos), 'Original public repositories'], [n(sum.groups.hanzo.orgs.length), 'Organizations holding them'], [n(sum.groups.hanzo.commits.year), 'Commits, past year'], [n(sum.groups.hanzo.stars), 'GitHub stars']],
|
|
read: sum.forge.read, from: act.from, to: act.to,
|
|
};
|
|
}
|