Skip to content

fix(content): count a Hindi word with its vowel signs as one in the rules, as Readability does (#1411 follow-up) - #1444

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/hindi-word-count
Oct 24, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/hindi-word-count

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1411. That PR made Readability keep a Hindi vowel sign inside its word. The Rules tab's own counter (rules.ts countWords) didn't do the same.

  • Vowel signs and the virama are Unicode marks (\p{M}), not letters, so the rules' counter broke a word at each one. For example, "वाक्य" counted as three words.
  • That inflated the rules' word counts on Hindi pages. Those counts feed the summary's word limit, the answer under each H2, and the intro's length.

The fix: rules.ts now counts words with Readability's countWords, now exported, instead of its own copy without \p{M}. The rules and Readability count words one way.

English and other spaced scripts count as before; a test checks that apostrophes and hyphens stay inside a word.

Related issue

Follow-up to #1411.

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

Run cd web && npx vitest run src/lib/content/rules.test.ts. "यह पहला वाक्य है। यह दूसरा है।" now counts 7 words; the old counter gave 10.

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: yarn test (362 files / 3281 tests) and yarn build with CI's placeholder env.

🤖 Generated with Claude Code

…ules, as Readability does (ansvisor#1411 follow-up)

The Rules tab's word counts (a summary's words, a section's answer, an
intro's length) split a Hindi word at each vowel sign: they are marks,
not letters, so "वाक्य" counted as three words. The rules now count words
with Readability's own counter (countWords), which keeps a mark inside
its word.

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. With one shared countWords, the rules and Readability count words the same way. Nothing else imported the removed rules.ts export, and readability.ts doesn't import rules.ts, so this adds no import cycle. The test covers both the Hindi case and inner apostrophes and hyphens.

@gkhngyk
gkhngyk merged commit f87687f 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