Skip to content

Commit

Permalink
readTime function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeyouell committed Jun 18, 2018
1 parent c47933f commit a0d5f98
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The average user read speed is set at 200 words per minute by default, this can

## Using the Filter

The `|readTime` filter returns a human time duration of how long it takes the average user to read the provided content. The value provided can be a string or an array of values.
The `|readTime` filter returns the human time duration of how long it takes the average user to read the provided content. The value provided can be a string or an array of values.

Seconds are included by default, but can be disabled by using `|readTime(false)`

Expand All @@ -60,6 +60,26 @@ Returns: 2 minutes, 40 seconds
Returns: 3 minutes
```

## Using the Function

The `readTime()` function returns the average read time for the whole entry based on it's field layout.

Seconds are included by default, but can be disabled by adding a second parameter of `false`

#### Examples

```twig
{{ readTime(entry) }}
Returns: 9 minutes, 40 seconds
```

```twig
{{ readTime(entry, false) }}
Returns: 10 minutes
```

## Overriding Plugin Settings

If you create a [config file](https://docs.craftcms.com/v3/configuration.html) in your `config` folder called `read-time.php`, you can override the plugin’s settings in the Control Panel. Since that config file is fully [multi-environment](https://docs.craftcms.com/v3/configuration.html) aware, this is a handy way to have different settings across multiple environments.
Expand All @@ -78,6 +98,4 @@ return [

Some things to do, and ideas for potential features:

- Twig extension that calculates the read time for all of the fields that exist within a given entry `{{ readTime(entry) }}` for example

Brought to you by [Luke Youell](https://github.com/lukeyouell)

0 comments on commit a0d5f98

Please sign in to comment.