Skip to content

fix(reader): short pages kept their whole sidebar - #10

Open
fiend37 wants to merge 1 commit into
SneakRead:mainfrom
fiend37:fix/reader-nav-preamble-short-pages
Open

fiend37 wants to merge 1 commit into
SneakRead:mainfrom
fiend37:fix/reader-nav-preamble-short-pages

Conversation

@fiend37

@fiend37 fiend37 commented Sep 11, 2026

Copy link
Copy Markdown

The bug

trimLeadingNav locates the body by scanning for the first line with >120 characters of visible prose. Pages that have no such line — disambiguation stubs, link lists, error pages — hit firstProse <= 0 and return untouched, so the reader renders the site's entire sidebar as the document.

https://en.wikipedia.org/wiki/Moyu opens with 62 lines of Wikipedia menu (Main page / Contents / Current events / Tools / Appearance…) before reaching **Moyu** may refer to:. The other bail-out — the half-the-document safety valve added in a8994f1 — leaks the same way on a nav-heavy site whose first paragraph sits below the midpoint.

The fix

Both bail-outs now fall back to trimNavRun, which needs no paragraph to anchor on. It walks the run of menu items that opens the page and stops at the first line that could be content:

  • The run crosses the filler a menu is padded with — short bare labels between groups (Tools, Appearance), a collapsible group's toggle (- [x] Tools), and logo links carrying no text of their own ([![Wikipedia](…)](…), [](https://www.bbc.com/)).
  • It may cross one heading, but only if the menu actually resumes afterwards. Wikis drop the article's own H1 in the middle of the sidebar; a 404 page's ## Error 404 - Oops, the page you're looking for is no longer here is the body, and is kept.
  • If the page is nothing but menu, or the run is shorter than a menu, nothing is trimmed.

MediaWiki's Appearance panel ships two sentences long enough to survive the run, so they join the boilerplate list beside the other MediaWiki chrome. Its bare labels (Text, Width, Color) are deliberately left out — those are ordinary section headings on plenty of real articles.

Verification

Ran before/after over 11 pages scraped through r.jina.ai:

Page Result
en.wikipedia.org/wiki/Moyu 66 lines of menu dropped; opens on From Wikipedia, the free encyclopedia
bbc.com/news/articles/… (404) menu dropped; opens on the Error 404 heading
BBC News home, Guardian home, Hacker News, MDN, GitHub repo, Naver article, ko.wikipedia article, en.wikipedia Konjac + Mercury byte-identical

scripts/check-reader.mjs pins both directions — the sidebar must go, a link-dense homepage must keep every headline, a 404 keeps its heading, an all-links page is left alone. Offline, no dependencies, no network; it fails 2/4 against the code this PR replaces, and is wired into CI after tsc.

pnpm lint, pnpm exec tsc -b and pnpm build all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WmQb9ehzkzYaVtDbMTpHAv

… the menu

trimLeadingNav found the body by looking for the first line with >120 chars of
visible prose. Pages that have no such line — disambiguation stubs, link lists,
error pages — fell straight through `firstProse <= 0` and were rendered with
their entire sidebar on top: en.wikipedia.org/wiki/Moyu opened as 62 lines of
Wikipedia menu before "Moyu may refer to:". The other bail-out, the half-the-
document safety valve, leaks the same way on a nav-heavy site.

Both now fall back to trimNavRun, which needs no paragraph: it walks the run of
menu items that opens the page and stops at the first line that could be
content. The run crosses the chrome a menu is padded with — short bare labels
between groups, collapsible toggles, logo links with no text of their own — and
it may cross one heading, but only if the menu actually resumes after it, so a
404 page keeps the "Error 404" heading that carries its message. If the page is
nothing but menu, or the run is shorter than a menu, nothing is trimmed.

MediaWiki's Appearance panel ships two sentences long enough to survive the run;
they join the boilerplate list next to the other MediaWiki chrome. Its bare
labels ("Text", "Width", "Color") are deliberately left out — they are ordinary
section headings on plenty of real articles.

Checked against 11 scraped pages: Moyu drops 66 lines of menu, the BBC 404 page
now opens on its heading, and the other 9 — BBC and Guardian homepages, HN, MDN,
GitHub, Naver, ko/en Wikipedia articles — are byte-identical.

scripts/check-reader.mjs pins both directions offline (no deps, no network) and
runs in CI: the sidebar must go, and a link-dense homepage must keep every
headline. It fails 2/4 against the code this commit replaces.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WmQb9ehzkzYaVtDbMTpHAv

This branch has not been deployed

No deployments
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