DEV Community

Discussion on: Adding reading time to Astro (the easy way)

Collapse
 
lexlohr profile image
Alex Lohr

It's a bit problematic to use a regular expression to clean up tags. Imagine you are using < in the text, because you are describing an equation; while that will only invalidate the result of your calculation, it's still considered bad practice.

A fast virtual DOM parser like linkedom will allow you to get document.body.textContent and run the calculation on that.

Also, if you split by \s, you may get non-existing words if there are multiple spaces; better split by \W+.