Skip to content

fix(audit): read a page's readability as the editor's Quality does, with one Flesch band (#1411 follow-up) - #1442

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/one-flesch
Oct 24, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/one-flesch

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1411, review item 4: Site Audit and the Content Editor gave the same page different Flesch scores. The cause was three differences: syllables, sentences and the band. This needs to land before NEXT_PUBLIC_CONTENT_QUALITY_PHASE is turned on.

One reading

  • Server port. server/src/lib/audit/signals/readability.js is a JS mirror of the editor's English reading in web/src/lib/content/readability.ts. It is marked "Mirrors… keep the two in step", as other mirrored modules are. It covers:
    • prose blocks: headings aside, each list item on its own, table cells not at all;
    • sentences: abbreviations, "No. 5", a lower-case continuation, closing quotes and brackets;
    • syllables: "-ted"/"-ded" keep theirs, a silent final e doesn't count.
  • Main content. The audit's readability signal now reads the page's main content through extractPageContent, the same extraction the editor's URL import uses, instead of the whole body.
    • Menus and footers no longer count. A page with too few words of its own gets na ("not enough text") rather than a score made of menu items.
    • Text a page builder leaves loose in a div, section, figcaption or dd/dt counts as a paragraph, as the editor's import makes it one.
    • Scripts, styles and SVG are removed before extraction, which keeps the cost down. A page still over 2 MB after that isn't read ("page too large to read").
  • Shared fixture. One page reads Flesch 82 in both server/src/lib/audit/audit.test.js and web/src/lib/content/readability.test.ts.

One band: the rubric's

rubric.json already documents the audit's band ("50–70 for general audiences; sub-30 academic and 80+ childlike both underperform"). I kept it and moved the editor onto it. Both sides apply it to the score as it shows, rounded:

Flesch (rounded) Site Audit Editor (reading level, 20 points)
50–70 pass full
30–49, 71–80 warn half
under 30, over 80 fail none

The advice now says which way to go:

  • the editor's detail: under 50 "shorter words and sentences", over 70 "reads simpler than most readers expect, keep the detail";
  • the rubric's howToFix;
  • the LLM's readability instruction, which now also gets the score in the finding.

@gkhngyk, please confirm the band.

  • The other option was "60 and up", which is what the editor had.
  • With the rubric's band, plain how-to copy fails: the fixture, a normal pour-over guide, reads 82. The editor's own test page (very short words) went from a total of 80+ to 67.
  • If you'd rather reward plain text, it is one constant on each side (FLESCH_BAND) plus the rubric line.

Effect on prod

  • Re-audits will move some readability results, because they now read main content with the editor's counter.
  • Site Audit still applies English Flesch to every language, so the two sides agree on English pages only.
  • The editor side is behind the Quality flag.
  • There is no migration and no API change. Server and web can deploy in either order.

Related issue

Follow-up to #1411 (review item 4).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/audit/. The fixture reads 82 through fleschReadingEase and through the signal with a nav and footer around it. A page with little text of its own gives na, div text is read, and a page over 2 MB isn't read.
  2. cd web && npx vitest run src/lib/content/readability.test.ts. The same fixture reads 82, and the band tests check full, half and none on both sides of 50–70.
  3. With NEXT_PUBLIC_CONTENT_QUALITY_PHASE=1, paste the fixture (in either test file) into a draft. Instructions › Quality shows "Reading level 82 (Flesch Reading Ease) · Aim for 50–70: the page reads simpler…".

I checked step 3 locally at 1024px, in light and dark, with a temporary draft that I deleted afterwards.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): 0 errors, 6 existing warnings in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run:

  • server: npm run format, npm run lint and npm test (191 files / 2316 tests);
  • web: yarn test (362 / 3283) and yarn build with CI's placeholder env.

🤖 Generated with Claude Code

…ith one Flesch band (ansvisor#1411 follow-up)

Site Audit and the Content Editor gave the same page different Flesch
scores (a 240-word page read 73 in the editor and 66 in the audit):

- the audit's readability signal now reads the page's main content
  (extractPageContent, as the editor's URL import) with a server mirror of
  the editor's blocks, sentences and syllables (signals/readability.js);
  menus and footers no longer count, text loose in a div is a paragraph,
  and a page with too few words of its own has no score
- one band in both places, the rubric's: 50–70 passes (full points in the
  editor), 30–50 and 70–80 warn (half), past them fails (none), read on
  the score as it shows
- the editor's detail and the audit's how-to-fix and recommendation say
  which way to go: under 50 shorter, over 70 fuller
- one fixture page reads Flesch 82 in both tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Three follow-ups below, none of them blocking.

The band is still an open product call: 50–70, and fewer reading-level points above 70 for plain English pages. This review covers the code only.

  1. (low) The audit and the editor still read two kinds of page differently.

    • Text with no tag of its own. This is text that sits straight in <main> or <article>, for example spans with <br> between them.
      • readingBlocks (server/src/lib/audit/signals/readability.js:74-90) reads only text inside one of the tags it lists, so the audit returns "not enough text".
      • The editor wraps the same text in a paragraph and scores it. My page reads 82 there.
      • Fix: also read the text runs at the top level of the content, one block per run between blocks.
    • Page-builder text in minified HTML. When the HTML has no whitespace between blocks, the editor's import joins neighbouring blocks:
      • cleanHtml (DOMPurify) drops div, figcaption, dd and dt but keeps their text, so the texts run together: "…shake it level.Start with a short pour…", "…fresh beans.BloomFresh coffee…".
      • The editor then counts one sentence where the audit counts two.
      • Results, editor against audit:
        • the fixture with every <p> turned into a <div> and minified: 80 against 82;
        • a page of six page-builder text blocks: 73 against 82;
        • a page with a figure caption and a definition list: 75 against 86.
      • The audit's reading is the right one, and the joined words also show in the imported draft.
      • Fix on the editor side: in cleanHtml, turn those tags into <p> before purifying, or at least add a space. This can be its own PR.
  2. (low) The main-content read is slow on large pages.

    • extractPageContent now runs on every audit, synchronously, in the API process.
    • judge → textOf (server/src/lib/page-content.js:176, :365) reads each element's whole subtree at every level strip goes down. So the time grows faster than the page does.
    • On a product grid, all under the 2 MB cap:
      • 0.4 s at 0.39 MB;
      • 2.9 s at 1.17 MB;
      • 6.5 s at 1.69 MB.
    • A 0.94 MB long article takes 1.3 s. The old signal took 0.15 s on the same page.
    • Typical pages stay well under a second: a 48-product category page took 0.23 s.
    • Fix: compute each element's text length once, bottom-up, and have judge read it. That speeds up the URL import too. Lowering MAX_READ_HTML (signals/content.js:18) would also cap the cost.
  3. (low) The two comments in web/src/lib/content/readability.test.ts:23 and :79 say the fixture is shared with signals/readability.test.js. It is in server/src/lib/audit/audit.test.js.

Note on existing audits. Re-audits will change many readability results, mostly upward:

  • The old counter found a sentence end only where a space followed the full stop.
  • A page whose HTML has no space between blocks therefore read as a few very long sentences. That often gave a negative score and a fail.
  • Those pages are now read properly.
  • When a fail becomes a pass, the page's total rises by about 2 points, since Content has about 11 evaluated signals.
  • The overview's change from the previous audit and the "Improving" status will show that rise even when the page didn't change. That's worth a line in the changelog.

Checked

  • One reading on both sides. I ran 401 random pages in the editor's own HTML through both counters. The pages covered:

    • headings;
    • lists with nested lists and paragraphs;
    • quotes and tables;
    • line breaks, abbreviations and closing quotes.

    The server and the editor gave the same rounded Flesch and the same band on every page. The fixture reads 82 through the full import path as well.

  • Rubric version, signal count, docs and en.json: nothing to update.

    • The signal count stays 48.
    • rubric_version is stored with each audit, but nothing reads it. It also stayed v1.1 through #1424.
    • The Site Audit guide doesn't state the band.
    • The rubric's copy reaches the UI from rubric.json.
    • Both new editor strings are in en.json. The old detail string is still used for German, French, Spanish and Turkish.
  • Merge state: merges cleanly on current main, including #1444's change to readability.ts. No migration. CI is green.

@gkhngyk
gkhngyk merged commit 181cf75 into ansvisor:main Oct 24, 2026
6 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
ansvisor#1433 is on main (squash-merged), with ansvisor#1429–ansvisor#1436 and ansvisor#1442/ansvisor#1444; this
branch's own change (Send to CMS part 2) is applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
…library

ansvisor#1438's branch now has main (ansvisor#1429–ansvisor#1436, ansvisor#1442, ansvisor#1444); this branch's own
changes (Send to CMS part 3a) are applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
…-bulk

ansvisor#1439's branch now has main (ansvisor#1429–ansvisor#1436, ansvisor#1442, ansvisor#1444); this branch's own
change (Send to CMS part 3b) is applied on top.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants