Estimated Reading Time for Blog Posts, Articles, etc. https://github.com/ethauvin/readingtime
Find a file
2021-05-19 21:54:21 -07:00
.circleci Cleanup. 2020-07-27 03:40:15 -07:00
.github/workflows Moved Sonarqube to GitHub action. 2021-05-19 21:54:21 -07:00
.idea Upgraded to Gradle 6.6 and Kotlin 1.4.0. 2020-08-18 00:17:41 -07:00
config/detekt Added detekt. 2020-07-23 10:50:52 -07:00
examples Moved Sonarqube to GitHub action. 2021-05-19 21:54:21 -07:00
gradle/wrapper Moved Sonarqube to GitHub action. 2021-05-19 21:54:21 -07:00
src Updated copyright. 2021-03-20 02:09:58 -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 Removed pom.xml.asc 2021-03-20 14:17:51 -07:00
.gitlab-ci.yml Fix for Gitlab CI 2021-05-11 21:50:51 -07:00
.travis.yml Moved Sonarqube to GitHub action. 2021-05-19 21:54:21 -07:00
bitbucket-pipelines.yml Initial Bitbucket Pipelines configuration 2020-07-26 05:44:06 +00:00
build.gradle.kts Moved Sonarqube to GitHub action. 2021-05-19 21:54:21 -07:00
gradlew Upgraded to Gradle 6.6 and Kotlin 1.4.0. 2020-08-18 00:17:41 -07:00
gradlew.bat Upgraded to Gradle 6.6 and Kotlin 1.4.0. 2020-08-18 00:17:41 -07:00
LICENSE.TXT Moved to Maven Central instead of JCenter. 2021-03-20 00:45:35 -07:00
pom.xml Moved Sonarqube to GitHub action. 2021-05-19 21:54:21 -07:00
README.md Removed repository from example. 2021-03-20 17:20:51 -07:00
settings.gradle.kts Initial commit. 2020-07-23 01:47:35 -07:00

License (3-Clause BSD) Release Maven Central

Known Vulnerabilities Quality Gate Status Build Status CircleCI

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 = "some_text",
    wpm = 275,
    postfix = "min read",
    plural = "min read",
    excludeImages = false, 
    extra = 0
)

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.
extra Additional seconds to be added to the total reading time.

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.

Gradle, Maven, etc.

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

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

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