Skip to content

Commit

Permalink
performance issue
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Oct 28, 2023
1 parent aae5b33 commit 4cf9cbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Any BREAKING CHANGE between minor versions will be documented here in upper case
## [Unreleased]
### Fixed
- Wrong urls in `pagefind` with `base_path` plugin [#502].
- Performance issue in `reading_info` plugin.
- Updated deps: `tailwindcss`, `deno_dom`, `highlight.js`, `sass`.

## [1.19.2] - 2023-10-21
Expand Down
11 changes: 8 additions & 3 deletions plugins/reading_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ export default function (userOptions?: Partial<Options>) {
const segmenter = new Intl.Segmenter(lang, {
granularity: "word",
});
const words = segmenter.segment(content);
const wordCount = [...words].filter((word) => word.isWordLike).length;
const minutes = wordCount / options.wordsPerMinute;

let wordCount = 0;
for (const word of segmenter.segment(content)) {
if (word.isWordLike) {
wordCount++;
}
}

const minutes = wordCount / options.wordsPerMinute;
const time = Math.round(minutes * 60 * 1000);
const displayTime = Math.ceil(parseFloat(minutes.toFixed(2)));

Expand Down

0 comments on commit 4cf9cbc

Please sign in to comment.