Estimated Reading Time for Blog Posts, Articles, etc. https://github.com/ethauvin/readingtime
Find a file
2023-06-29 11:52:46 -07:00
.circleci Upgraded to Kotlin 1.7.20 2022-09-30 22:31:47 -07:00
.github/workflows Updated dependencies 2023-06-29 11:38:22 -07:00
.idea Updated dependencies 2023-06-29 11:38:22 -07:00
config/detekt Cleaned up tests 2022-10-04 12:46:45 -07:00
examples Updated dependencies 2023-06-29 11:38:22 -07:00
gradle/wrapper Updated dependencies 2023-06-29 11:38:22 -07:00
src Cleaned up tests 2022-10-04 12:46:45 -07:00
.editorconfig Initial commit. 2020-07-23 01:47:35 -07:00
.gitattributes Initial commit. 2020-07-23 01:47:35 -07:00
.gitignore Updated dependencies. 2021-07-11 19:22:21 -07:00
.gitlab-ci.yml Using system wide Gradle. 2021-05-21 13:06:27 -07:00
bitbucket-pipelines.yml Upgraded to Kotlin 1.7.20 2022-09-30 22:31:47 -07:00
build.gradle.kts Fixed Kover reports 2023-06-29 11:52:46 -07:00
gradlew Updated dependencies 2023-06-29 11:38:22 -07:00
gradlew.bat Updated dependencies 2023-06-29 11:38:22 -07:00
LICENSE.TXT Updated dependencies and copyright. 2022-01-03 12:06:14 -08:00
pom.xml Version 0.9.1 2022-08-25 16:44:51 -07:00
README.md Updated dependencies 2023-06-29 11:38:22 -07:00
settings.gradle.kts Upgraded to Kotlin 1.5.21 and JDK 16. 2021-07-27 09:10:04 -07:00

License (3-Clause BSD) Release Maven Central

Quality Gate Status GitHub CI CircleCI

Estimated Reading Time for Blog Posts, Articles, etc.

A simple 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.

Gradle, Maven, etc.

To use with Gradle, include the following dependency in your build file:

repositories {
    mavenCentral()
}

dependencies {
    implementation("net.thauvin.erik:readingtime:0.9.1")
}

Instructions for using with Maven, Ivy, etc. can be found on Maven Central.

Properties

The following properties are available:

ReadingTime(
    text,
    wpm = 275,
    postfix = "min read",
    plural = "min read",
    excludeImages = false, 
    extra = 0,
    roundingMode = RoundingMode.HALF_EVEN
)

Property Description
text The text to be evaluated. (Required)
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.
extra Additional seconds to be added to the total reading time.
roundingMode The rounding mode to apply.

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
    wpm="275"
    postfix="min read"
    plural="min read"
    excludeImages="false"
    extra="0">some_text</t:readingtime>

None of the attributes are required.