-
Notifications
You must be signed in to change notification settings - Fork 0
Add google analytics, rss for annual letters; fix revalidation bug #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Even set `export const revalidate = <desired_seconds>` to desired seconds in each pages, the revalidation time will be rewritten by `unstable_cache`'s default setting (in previous case is 3600s, which cause the revalition to be 1 hour for every page). - Now set the default revalidation time to 6 hours (21600s) in `.env` file as `REVALIDATE_TIME`, and use it in `unstable_cache` in `lib/airtable.ts`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Google Analytics tracking, generates an RSS feed for Annual Letters at build time, and implements durable logging to Cloudflare R2 for production environments. Additionally, it fixes ISR revalidation inconsistencies by standardizing the default to 6 hours (21600s) across all pages and cache configurations.
Key Changes:
- Introduced Google Analytics via
@next/third-partiesand RSS feed generation using thersspackage - Centralized site configuration (
siteUrl,feedFileName,revalidateTime) inlib/consts.ts - Added R2-backed structured logging that appends NDJSON records to monthly log files
Reviewed Changes
Copilot reviewed 16 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/image-convert.ts | Extracted WebpOptions type and reduced sharp concurrency from 3 to 2 for lower memory footprint |
| src/utils/generate-rss-feed.ts | New utility to generate RSS feed at build time for Annual Letters |
| src/lib/r2/r2-logs.ts | New module to append structured logs to monthly NDJSON files in R2 |
| src/lib/r2/index.ts | Updated import path for constants from local to centralized location |
| src/lib/logger.ts | Enhanced logger to persist records to R2 in addition to console output |
| src/lib/consts.ts | Added siteUrl, feedFileName constants and changed default revalidateTime from 3600s to 21600s |
| src/lib/annual-letters.ts | Removed inline type definitions (moved to types/letters.d.ts) |
| src/lib/airtable/airtable.ts | Updated import to use centralized revalidateTime constant |
| src/components/home/MediaBanner.tsx | Updated import path for annualLetters data |
| src/app/projects/page.tsx | Changed revalidate from 14400s to 21600s and updated comment |
| src/app/projects/[id]/page.tsx | Added RSS feed generation call in generateStaticParams |
| src/app/people/page.tsx | Changed revalidate from 14400s to 43200s, added description metadata, updated import paths |
| src/app/letters/page.tsx | Switched from <a> to <Link> with prefetch={false}, added description metadata |
| src/app/layout.tsx | Added RSS feed link tag, Google Analytics component, and centralized URL constants |
| package.json | Added @next/third-parties, rss, and @types/rss dependencies |
| README.md | Updated default REVALIDATE_TIME documentation from 3600s to 21600s |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
π¨ Lint Check |
d8306eb to
c7c2436
Compare
π¨ Lint Checkβ Lint: No linting issues found! |
β¨ Features Updates && π Bug Fix
π Description
This PR adds three main capabilities and several quality-of-life improvements:
Google Analytics β Added Google Analytics to the whole site for analyzing purposes.
RSS feed for Annual Letters β A build-time RSS generator produces
public/letters-feed.xmland exposes it via a<link rel="alternate" type="application/rss+xml">tag. This makes it easy for anyone to subscribe to new DTR annual letters in any feed reader.Durable logging to Cloudflare R2 β Production logs are now persisted to monthly NDJSON files in R2 (in addition to console output) to support lightweight, long-horizon analysis without scraping server logs.
Additionally:
siteUrland feed filename inlib/consts.lib/airtable/*andlib/r2/*for clarity.π Feature Changes
New utility:
utils/generate-rss-feed.tsexecuted at build viaprojects/[id]/page.tsx#generateStaticParams.logger.tsnow appends structured logs to monthly NDJSON files in R2 vialib/r2/r2-logs.ts.RSS
<link rel="alternate">in<head>; richer page descriptions; canonical URLs sourced from a singlesiteUrl.Adds
rssdependency and a typed build pipeline for feed generation.π Refactor Changes
Lowered
sharpconcurrency (3β2) and cache sizing for low-mem hosts.Moved Airtable code to
lib/airtable/*, R2 code tolib/r2/*, constants tolib/consts.ts, and annual letter data tolib/annual-letters.ts. Addedtypes/*.d.ts.Eliminated inline interfaces in the annual letters module (now in
types/letters.d.ts).π Bug Fixes
Default
REVALIDATE_TIMEand page-levelrevalidatevalues were not aligned. Page-specific revalidation setting is overwritten by theunstable_cachesetting. Now theunstable_cacherevalidation is also changed to 21600s (6h) and comments/README updated.R2 logging failures are swallowed with a clear console error, so logging can never break page rendering.
β Checklist
npm audit/pnpm audit.π Dependency Changes
rssπ Steps to Reproduce (before fix)
A. Revalidation expectations drift
REVALIDATE_TIME="3600"in.envand navigate to/peopleand/projects.21600) and pages explicitly align with that value; comments/README reflect the truth.B. No durable prod logs
AIRTABLE_LOG=1in production, only console logs existed; there was no persistent store for monthly analysis.logs/YYYY/YYYY-MM.ndjson.π Notable File/Path Changes
RSS
src/utils/generate-rss-feed.ts(new)src/app/layout.tsx(RSS<link>in<head>)src/app/projects/[id]/page.tsx(invokes feed generation at build)Logging / R2
src/lib/logger.ts(now appends to R2)src/lib/r2/index.ts,src/lib/r2/r2-gc.ts,src/lib/r2/r2-logs.ts(new module structure)Airtable & constants
src/lib/airtable/*(moved fromsrc/lib/*)src/lib/consts.ts(addssiteUrl,feedFileName, defaultrevalidateTime=21600)Metadata & links
src/app/layout.tsx,src/app/letters/page.tsx,src/app/people/page.tsx(descriptions, canonical viasiteUrl, external links useprefetch={false})Types & images
src/types/letters.d.ts,src/types/images.d.ts,src/types/people.d.ts(expanded/cleaned)src/utils/image-convert.ts(types extracted; concurrency tuned)π¬ Additional Notes
GET β append β PUTworkflow, which is fine at a six-hour cadence. If write frequency grows or concurrency becomes a concern, switch to a per-event object model (e.g.,logs/YYYY/MM/dd/ts.json) with periodic compaction or use R2 object multipart uploads with conditional headers.siteUrlprevents hard-coded URL drift and keeps canonical/meta consistent across environments.