mirror of
https://github.com/hanzoai/site.git
synced 2026-11-21 01:07:08 +00:00
The Commits and Merges tiles drew bars typed into content.js (85 KB of markup captured from hanzo.ai's page) and the third tile, "In the past 7 days", drew none. All three now draw the snapshot: commits a week for the year, merges a month, commits a day for the last seven days. The weeks count back from the last day, so the last bar is the week the third tile counts, not the one day the window leaves over. The tiles and the repository cards share components/home/spark.js, the bars as @hanzo/ui's Sparkline draws them (at least 4% tall, a line for none), filled with --x-heat so they match the calendar and its legend in both themes. Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
30 lines
1.6 KiB
JavaScript
30 lines
1.6 KiB
JavaScript
// Commits a day across every Hanzo repository, private ones counted: the calendar hanzo.ai's home draws, from the
|
|
// snapshot of api.hanzo.ai/v1/git/activity built into its page (content/live/_oss.json; scripts/live.mjs refreshes it
|
|
// before every build).
|
|
import O from '../content/live/_oss.json';
|
|
import { cuts, shade } from './heat.mjs';
|
|
const G = O.calendar;
|
|
|
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
export const DAYS = G.days.map(([day, c, r]) => {
|
|
const [y, m, d] = day.split('-').map(Number);
|
|
return { y, m, d, c, r, label: `${MON[m - 1]} ${d}, ${y}` };
|
|
});
|
|
// self-check: one entry a day for a full year, every count a number
|
|
if (DAYS.length < 365 || DAYS.some((x) => !Number.isFinite(x.c) || !Number.isFinite(x.r))) throw new Error('commit calendar data is incomplete');
|
|
export const TOTAL = DAYS.reduce((a, x) => a + x.c, 0);
|
|
export const FROM = DAYS[0].label;
|
|
export const TO = DAYS.at(-1).label;
|
|
export const FIRST_WEEKDAY = new Date(G.days[0][0] + 'T00:00:00Z').getUTCDay();
|
|
|
|
// A day's shade (0 to 4: none, then the quartiles of the days that had commits), and the series the tiles draw: the last
|
|
// seven days, and the year in weeks counted back from the last day, so the last bar is the week the "past 7 days" tile counts.
|
|
const CUT = cuts(DAYS.map((x) => x.c));
|
|
export const level = (c) => shade(c, CUT);
|
|
export const LAST7 = DAYS.slice(-7).map((x) => x.c);
|
|
const W = Math.floor(DAYS.length / 7);
|
|
export const WEEKS = Array.from({ length: W }, (_, i) => {
|
|
const end = DAYS.length - 7 * (W - 1 - i);
|
|
return DAYS.slice(end - 7, end).reduce((s, x) => s + x.c, 0);
|
|
});
|