Enabling the GitHub commit field on the home page
How the 48-week contribution grid previews out of the box, fetches live GitHub data at build time, and omits synthetic data once configured.
how it works
Out of the box (githubUsers: [] and sampleCommits: true in src/data/site.ts), src/lib/github.ts renders a deterministic 48-week sample grid (activity, past 48 weeks) so the home layout previews without credentials.
Once SITE.githubUsers lists one or more usernames, sample mode turns off and src/lib/github.ts queries GitHub’s GraphQL contributionCalendar at build time, sums daily counts across accounts, and maps the last 48 weeks into --heat-0 through --heat-4 (github, past 48 weeks).
On narrower viewports, CommitField.astro trims older columns cleanly to preserve square aspect ratios: 48 weeks on desktop, 24 weeks under 760px, and 12 weeks under 600px.
setup
- Add one or more GitHub handles to
githubUsersinsrc/data/site.ts:
githubUsers: ['your-handle'],- Copy
.env.exampleto.envfor local builds and provide a token with public profile read access:
GITHUB_TOKEN=ghp_your_token_here- For production deployments, pass
GITHUB_TOKENin your CI environment (for GitHub Actions, store a personal access token asGH_TOKENin repository secrets since GitHub reserves theGITHUB_prefix). WhengithubUsersis configured withoutGITHUB_TOKEN, the build logs a warning and omits the commit field rather than displaying synthetic activity. To hide the field completely, leavegithubUsers: []and setsampleCommits: false.