Show estimated read time in the viewer bar - #21
Merged
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
sjmiller609
marked this pull request as ready for review
July 31, 2026 15:12
This was referenced Jul 31, 2026
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 free
to 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.
Summary
Adds an estimated read time to the
/d/:slugchrome bar, alongside the other page-independent controls (theme toggle, bookmark, comments, history).lib/docs/reading-time.ts—estimateReadMinutes(html): masks comments/script/style/template/noscript/svg, runs the existinghtmlToText, 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".app/d/[slug]/page.tsxnext toextractSectionsand 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).N min readbefore the theme toggle, inheriting--jh-bar-mutedso it themes in light and dark. Hidden below 768px, where the bar is already tight.Testing
npm test— 168 passing, including 6 new cases forestimateReadMinutes(wpm rounding, non-prose blocks and comments ignored, entities decoded, CJK, zero-prose docs).npm run buildclean,tsc --noEmitclean.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.tsintroducesestimateReadMinutes(html): strip comments and non-prose blocks (includingsvg), convert with existinghtmlToText, count word tokens at 200 wpm and CJK characters at 500/min, round up.app/d/[slug]/page.tsxcomputes this at SSR next toextractSectionsand passesreadMinutesintoCommentsShell. 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.