fix(site): tolerate both legacy and flat gh-trending schemas - #2
Merged
Conversation
The static build crashed (`data.weekly.map is not a function`) when
rendering archive pages whose JSON was written by the old gh_trending
Lambda, where `weekly`/`monthly` were `{ period, repos[] }` objects
rather than flat `Repo[]` arrays. Archive pages render historical data,
so both shapes must be supported.
- Add site/src/lib/trending.ts: loadTrending() + normalizeTrending()
that coerce either schema (and missing fields) into the flat
TrendingData shape, mapping legacy generated_at -> updated_at and
defaulting stars_this_period to 0.
- Use it in trending.astro, archive/gh-trending/[date].astro, and
rss/trending.xml.ts, removing the duplicated inline interfaces/loaders.
Verified by building with a mix of legacy-dict and flat archives synced
from S3 — all pages render with real repo cards.Uh oh!
There was an error while loading. Please reload this page.
2 tasks
datj9 added a commit
that referenced
this pull request
Jul 11, 2026
The static build crashed (`data.weekly.map is not a function`) when
rendering archive pages whose JSON was written by the old gh_trending
Lambda, where `weekly`/`monthly` were `{ period, repos[] }` objects
rather than flat `Repo[]` arrays. Archive pages render historical data,
so both shapes must be supported.
- Add site/src/lib/trending.ts: loadTrending() + normalizeTrending()
that coerce either schema (and missing fields) into the flat
TrendingData shape, mapping legacy generated_at -> updated_at and
defaulting stars_this_period to 0.
- Use it in trending.astro, archive/gh-trending/[date].astro, and
rss/trending.xml.ts, removing the duplicated inline interfaces/loaders.
Verified by building with a mix of legacy-dict and flat archives synced
from S3 — all pages render with real repo cards.
Co-authored-by: Dat <dat.nguyen@ringkas.co.id>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After #1 changed `gh_trending` to emit the flat `{updated_at, weekly[], monthly[]}` schema, the deploy build failed:
```
TypeError: data.weekly.map is not a function
Caught error rendering /archive/gh-trending/2026-05-18
```
The archive pages (`/archive/gh-trending/[date]`) render historical JSON synced from S3. Files written before #1 use the legacy shape where `weekly`/`monthly` are `{ period, repos[] }` objects (and repos lack `stars_this_period`). The new code assumed flat arrays, so `.map()` threw on every legacy archive and the static build aborted — blocking the whole deploy. (The live site was unaffected: the build fails before the S3 upload/CloudFront step.)
Change
Result: old archives render as before, new data renders with period badges, and schema drift can never crash the build again.
Test plan
Follows #1 — needed for that deploy to go green.