Skip to content

Show estimated read time in the viewer bar - #21

Merged
sjmiller609 merged 1 commit into
mainfrom
hypeship/viewer-read-time
Jul 31, 2026
Merged

Show estimated read time in the viewer bar#21
sjmiller609 merged 1 commit into
mainfrom
hypeship/viewer-read-time

Conversation

@sjmiller609

@sjmiller609 sjmiller609 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an estimated read time to the /d/:slug chrome bar, alongside the other page-independent controls (theme toggle, bookmark, comments, history).

  • lib/docs/reading-time.tsestimateReadMinutes(html): masks comments/script/style/template/noscript/svg, runs the existing htmlToText, counts word tokens at 200 wpm and CJK characters at 500/min (they have no spaces to tokenize on), rounds up. Returns 0 when the doc has no prose so an image-only doc doesn't claim "1 min read".
  • Computed at SSR in app/d/[slug]/page.tsx next to extractSections and passed to the shell — a pure function of the stored HTML, nothing stored, no client recompute (an inline edit changes it on the next load, same as the title and section list).
  • Rendered as a muted N min read before the theme toggle, inheriting --jh-bar-muted so it themes in light and dark. Hidden below 768px, where the bar is already tight.

Testing

  • npm test — 168 passing, including 6 new cases for estimateReadMinutes (wpm rounding, non-prose blocks and comments ignored, entities decoded, CJK, zero-prose docs).
  • npm run build clean, tsc --noEmit clean.
  • Verified in a local dev server against a seeded doc: a 1000-word doc shows "6 min read", a short doc "1 min read".

Note

Low Risk
Display-only SSR derivation from stored HTML with no auth or persistence changes; behavior is covered by new unit tests.

Overview
The document viewer chrome bar now shows an estimated read time (N min read) before the theme toggle, using muted bar styling and a tooltip. It is omitted when the estimate is 0 (no readable prose) and hidden below 768px so the tight mobile bar stays usable.

lib/docs/reading-time.ts introduces estimateReadMinutes(html): strip comments and non-prose blocks (including svg), convert with existing htmlToText, count word tokens at 200 wpm and CJK characters at 500/min, round up. app/d/[slug]/page.tsx computes this at SSR next to extractSections and passes readMinutes into CommentsShell. No persistence or client recompute—edits update the label on the next load like the title.

Vitest covers rounding, empty/non-prose docs, ignored markup, entities, and CJK.

Reviewed by Cursor Bugbot for commit 74ebdbd. Bugbot is set up for automated code reviews on this repo. Configure here.

Derive minutes-to-read from the stored HTML at SSR (200 wpm, CJK counted per
character) and render it in the chrome bar next to the theme toggle. Docs with
no prose omit it; the bar drops it below 768px where space is tight.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
justhtml Ready Ready Preview Jul 31, 2026 3:11pm

@sjmiller609
sjmiller609 marked this pull request as ready for review July 31, 2026 15:12
@sjmiller609
sjmiller609 merged commit a47add8 into main Jul 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant