feat(posts): reading time from frontmatter and view counter #9

Merged
magndotcc merged 2 commits from t3/blog-reading-time-view-counter into main 2026-10-30 23:01:46 +00:00
Owner

Claude Opus 5.5 in T3 Code (Claude Code) responding on behalf of Magnus

Each post sets its own reading time in its frontmatter, and every post shows a view count.

Reading time

  • Set it at the top of a post next to the other fields:
    ---
    title: the anthropic situation
    date: 2026-07-02
    readingTime: 5 min
    ---
    
    5, 5 min and 5m all work.
  • The five existing posts now have readingTime:, filled in with the current estimate so the site looks the same until you change the numbers.
  • Without the field, the estimate now uses the rendered article instead of the raw markdown. Link URLs, image paths and footnotes no longer count as words, code blocks are read more slowly, and each image adds a few seconds.

Views

  • Views appear in the post header and next to each entry in the post list.
  • A reader counts once per post per UTC day.
  • Counts live in one SQLite-backed Durable Object instead of KV. KV is eventually consistent, so two readers opening a post at the same moment would overwrite each other's increment and one view would be lost.
  • IPs are never stored. Each IP is hashed with a salt that is replaced every day, and the old salt is deleted along with that day's "seen" records.
  • POST /api/view/<slug> only accepts same-origin requests and slugs that exist. A per-IP limit of 30 requests a minute uses the Workers rate-limit binding.
  • Rendered pages stay in KV for up to an hour, so the post list fetches current counts from /api/views after it loads.

Free tier

  • The free plan supports SQLite-backed Durable Objects and allows 100k requests and 100k row writes a day. Each view costs one request and at most two row writes. If a limit is ever hit, view counting fails quietly and the pages still render.
  • Every view count starts at 0. wrangler deploy creates the Durable Object (migration v1) and the STATS_LIMITER binding.

Verification

  • npx tsc --noEmit and git diff --check pass.
  • Tested against local wrangler dev:
    • With readingTime: 7 min set on a post, both the list and the post header showed 7 min.
    • A second view from the same IP did not count again. A different IP did.
    • A slug that doesn't exist returned 404.
    • A request from another origin returned 403.
    • After 30 requests in a minute from one IP, the rest returned 429.
    • /api/views returned the current counts.

🤖 Generated with Claude Code

> Claude Opus 5.5 in T3 Code (Claude Code) responding on behalf of Magnus Each post sets its own reading time in its frontmatter, and every post shows a view count. **Reading time** - Set it at the top of a post next to the other fields: ``` --- title: the anthropic situation date: 2026-07-02 readingTime: 5 min --- ``` `5`, `5 min` and `5m` all work. - The five existing posts now have `readingTime:`, filled in with the current estimate so the site looks the same until you change the numbers. - Without the field, the estimate now uses the rendered article instead of the raw markdown. Link URLs, image paths and footnotes no longer count as words, code blocks are read more slowly, and each image adds a few seconds. **Views** - Views appear in the post header and next to each entry in the post list. - A reader counts once per post per UTC day. - Counts live in one SQLite-backed Durable Object instead of KV. KV is eventually consistent, so two readers opening a post at the same moment would overwrite each other's increment and one view would be lost. - IPs are never stored. Each IP is hashed with a salt that is replaced every day, and the old salt is deleted along with that day's "seen" records. - `POST /api/view/<slug>` only accepts same-origin requests and slugs that exist. A per-IP limit of 30 requests a minute uses the Workers rate-limit binding. - Rendered pages stay in KV for up to an hour, so the post list fetches current counts from `/api/views` after it loads. **Free tier** - The free plan supports SQLite-backed Durable Objects and allows 100k requests and 100k row writes a day. Each view costs one request and at most two row writes. If a limit is ever hit, view counting fails quietly and the pages still render. - Every view count starts at 0. `wrangler deploy` creates the Durable Object (migration `v1`) and the `STATS_LIMITER` binding. **Verification** - `npx tsc --noEmit` and `git diff --check` pass. - Tested against local `wrangler dev`: - With `readingTime: 7 min` set on a post, both the list and the post header showed `7 min`. - A second view from the same IP did not count again. A different IP did. - A slug that doesn't exist returned 404. - A request from another origin returned 403. - After 30 requests in a minute from one IP, the rest returned 429. - `/api/views` returned the current counts. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reading time now comes from the rendered article, and once three readers
finish a post it switches to the median time they actually spent on it.
Views are counted once per reader per post per day in a SQLite Durable
Object, behind a per-IP rate limit. IPs are only stored as hashes with a
daily salt that gets thrown away.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading time now comes from `readingTime:` at the top of each post, with
the rendered-article estimate as a fallback. The read timer and its
endpoint are gone, so the Durable Object only counts views.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
magndotcc changed title from feat(posts): measured reading time and view counter to feat(posts): reading time from frontmatter and view counter 2026-10-30 23:01:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
magndotcc/blog!9
No description provided.