Skip to content

Commit

Permalink
fix(remark-lesetid): estimate text one time instead of each text node
Browse files Browse the repository at this point in the history
  • Loading branch information
luxass committed Feb 3, 2024
1 parent 0178bd5 commit b8e009e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-coins-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"remark-lesetid": patch
---

only estimate text one time
22 changes: 11 additions & 11 deletions packages/remark-lesetid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ const remarkLesetid: Plugin<Options[], Root> = (options) => {
}

const { dataKey } = options;

return (tree, file) => {
let textOnPage = "";
visit(tree, "text", (node) => {
const textOnPage = node.value;
const estimation = estimate(textOnPage);
textOnPage += node.value;
});

// if matter is defined in data, the frontmatter
// parser is vfile-matter.
if ("matter" in file.data && file.data.matter) {
file.data.matter[dataKey] ||= estimation;
return;
}
const estimation = estimate(textOnPage);
// if matter is defined in data, the frontmatter
// parser is vfile-matter.
if ("matter" in file.data && file.data.matter) {
file.data.matter[dataKey] ||= estimation;
return;
}

file.data[dataKey] ||= estimation;
});
file.data[dataKey] ||= estimation;
};
};

Expand Down

0 comments on commit b8e009e

Please sign in to comment.