Estimated Reading Time for Blog Posts, Articles, etc.
https://github.com/ethauvin/readingtime
articlesblogestimatedjavajspkotlinmediumminutespostsreadreadingreading-timereadingtimetexttimeweblog
.circleci | ||
.github/workflows | ||
.idea | ||
config/detekt | ||
examples | ||
gradle/wrapper | ||
src | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.gitlab-ci.yml | ||
.travis.yml | ||
bitbucket-pipelines.yml | ||
build.gradle.kts | ||
gradlew | ||
gradlew.bat | ||
LICENSE.TXT | ||
pom.xml | ||
README.md | ||
settings.gradle.kts |
Estimated Reading Time for Blog Posts, Articles, etc.
A simple Kotlin/Java implementation of Medium's Read Time calculation.
Examples (TL;DR)
import net.thauvin.erik.readingtime.ReadingTime
// ...
val rt = ReadingTime(htmlText)
println(rt.calcEstimatedReadTime()) // eg: 2 min read
To get the estimated reading time in seconds use the calcReadingTimeInSec()
function.
Properties
The following properties are available:
ReadingTime(
text = "sometext",
wpm = 275,
postfix = "min read",
plural = "min read",
excludeImages = false
)
Property | Description |
---|---|
text |
The text to be evaluated. |
wpm |
The words per minute reading average. |
postfix |
The value to be appended to the reading time. |
plural |
The value to be appended if the reading time is more than 1 minute. |
excludeImages |
Images are excluded from the reading time when set. |
Functions
A couple of useful functions are also available:
ReadingTime.wordCount(htmlText) // Returns the count of words. (HTML stripped)
ReadingTime.imgCount(htmlText) // Returns the count of images. (HTML img tags)
JSP
A JSP tag is also available for easy incorporation into web applications:
<%@taglib uri="https://erik.thauvin.net/taglibs/readingtime" prefix="t"%>
<t:readingtime
postfix="min read"
plural="min read"
excludeImages="false"
wpm="275">some_text_or_html</t:readingtime>
None of the attributes are required.
Just drop the jar into your WEB-INF/lib
directory.
Gradle
To use with Gradle, include the following dependency in your build file:
repositories {
jcenter()
}
dependencies {
implementation("net.thauvin.erik:readingtime:0.9.0")
}