71 lines
3.2 KiB
Markdown
71 lines
3.2 KiB
Markdown
[](http://opensource.org/licenses/BSD-3-Clause) [](https://github.com/ethauvin/readingtime/releases/latest) [](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/readingtime) [](https://bintray.com/ethauvin/maven/readingtime/_latestVersion)
|
|
|
|
[](https://snyk.io/test/github/ethauvin/readingtime?targetFile=pom.xml) [](https://sonarcloud.io/dashboard?id=ethauvin_readingtime) [](https://travis-ci.com/ethauvin/readingtime) [](https://circleci.com/gh/ethauvin/readingtime/tree/master)
|
|
|
|
# Estimated Reading Time for Blog Posts, Articles, etc.
|
|
|
|
A simple Kotlin/Java implementation of [Medium's Read Time calculation](https://blog.medium.com/read-time-and-you-bc2048ab620c).
|
|
|
|
## Examples (TL;DR)
|
|
|
|
```kotlin
|
|
import net.thauvin.erik.readingtime.ReadingTime
|
|
|
|
...
|
|
|
|
val rt = ReadingTime(htmlText);
|
|
println(rt.calcEstimatedReadTime()) // Outputs: X min read
|
|
|
|
```
|
|
|
|
where X is the estimated reading time for the given text.
|
|
|
|
- View [Kotlin](https://github.com/ethauvin/readingtime/blob/master/examples/src/main/kotlin/com/example/ReadingTimeExample.kt) or [Java](https://github.com/ethauvin/readingtime/blob/master/examples/src/main/java/com/example/ReadingTimeSample.java) Examples.
|
|
|
|
|
|
|
|
### Properties
|
|
|
|
The following properties are available:
|
|
|
|
```kotlin
|
|
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:
|
|
|
|
```kotlin
|
|
ReadingTime.wordCount(htmlText) // Returns the count of words. (HTML stripped)
|
|
ReadingTime.imgCount(htmlText) // Returns the count of images. (img HTML tags)
|
|
```
|
|
|
|
### Gradle
|
|
|
|
To use with [Gradle](https://gradle.org/), include the following dependency in your [build](https://github.com/ethauvin/readingtime/blob/master/examples/build.gradle.kts) file:
|
|
|
|
```gradle
|
|
repositories {
|
|
jcenter()
|
|
}
|
|
|
|
dependencies {
|
|
implementation("net.thauvin.erik:readingtime:0.9.0")
|
|
}
|
|
```
|