Repository navigation
Conversation
… 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
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.
The bug
trimLeadingNavlocates 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 — hitfirstProse <= 0and return untouched, so the reader renders the site's entire sidebar as the document.https://en.wikipedia.org/wiki/Moyuopens 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:Tools,Appearance), a collapsible group's toggle (- [x] Tools), and logo links carrying no text of their own ([](…),[](https://www.bbc.com/)).## Error 404 - Oops, the page you're looking for is no longer hereis the body, and is kept.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:en.wikipedia.org/wiki/MoyuFrom Wikipedia, the free encyclopediabbc.com/news/articles/…(404)Error 404headingko.wikipediaarticle,en.wikipediaKonjac + Mercuryscripts/check-reader.mjspins 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 aftertsc.pnpm lint,pnpm exec tsc -bandpnpm buildall pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01WmQb9ehzkzYaVtDbMTpHAv