Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reading-time npm package by Intl.Segmenter API #11086

Open
1 of 2 tasks
slorber opened this issue Apr 11, 2025 · 1 comment · May be fixed by #11091
Open
1 of 2 tasks

Replace reading-time npm package by Intl.Segmenter API #11086

slorber opened this issue Apr 11, 2025 · 1 comment · May be fixed by #11091
Labels
good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. help wanted Asking for outside help and/or contributions to this particular issue or PR. proposal This issue is a proposal, usually non-trivial change

Comments

@slorber
Copy link
Collaborator

slorber commented Apr 11, 2025

Have you read the Contributing Guidelines on issues?

Motivation

We could get rid of some npm lib/code in our blog readingTime API by relying on built-in Intl.Segmenter APIs (Node.js v16+)

const segmenter = new Intl.Segmenter('en', { granularity: 'word' });
const segments = segmenter.segment('This is a test');

let count = 0;
for (const seg of segments) {
  console.log({seg});
  count++;
}

console.log(count);

The library code is more complex, likely less performant, and less accurate (doesn't take the locale as param) than the native implementation
https://github.com/ngryman/reading-time/blob/master/src/reading-time.ts


This is not a critical feature but if someone from the community want to contribute, PRs welcome.

I'd appreciate if you start by writing unit tests / snapshots for the reading-time lib usage.

Then we can see how the new implementation gives a different result depending on inputs.

Based on that result we can decide if it's safe to ship immediately, or if it requires a future flag + breaking change.

Note that Docusaurus exposes a way to pass your own readingTime function, and we may need to change that API: https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog#ReadingTimeFn

Self-service

  • I'd be willing to do some initial work on this proposal myself.
@slorber slorber added good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. help wanted Asking for outside help and/or contributions to this particular issue or PR. proposal This issue is a proposal, usually non-trivial change labels Apr 11, 2025
@shreedharbhat98
Copy link

Hi @slorber, I would like to contribute to this issue and this is my first contribution to Docusaurus.
I have raised a PR for the same here. Let's have some discussions there.
Thanks in advance. 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. help wanted Asking for outside help and/or contributions to this particular issue or PR. proposal This issue is a proposal, usually non-trivial change
Projects
None yet
2 participants