Skip to content

Commit

Permalink
Merge pull request #2 from lukeyouell/develop
Browse files Browse the repository at this point in the history
Plugin name changed to Read Time
  • Loading branch information
lukeyouell authored Jun 6, 2018
2 parents fbb0147 + 5955075 commit b0253e2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 1.1.0 - 2018-06-06

### Changed
- Plugin name changed to `Read Time`

## 1.0.0 - 2018-06-06

### Added
- Initial release
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<img src="src/icon.svg" alt="icon" width="100" height="100">

# Reading Time plugin for Craft CMS 3
# Read Time plugin for Craft CMS 3

Calculate the estimated reading time for content.
Calculate the estimated read time for content.

## Installation

Expand All @@ -12,7 +12,7 @@ This plugin requires Craft CMS 3.0.0, or later.

#### Plugin Store

Log into your control panel and click on 'Plugin Store'. Search for 'Reading Time'.
Log into your control panel and click on 'Plugin Store'. Search for 'Read Time'.

#### Composer

Expand All @@ -25,44 +25,44 @@ cd /path/to/project
2. Then tell Composer to load the plugin:

```bash
composer require lukeyouell/craft-readingtime
composer require lukeyouell/craft-readtime
```

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Reading Time.
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Read Time.

## Configuration

The average user reading speed is set at 200 words per minute by default, this can be changed in the plugin settings.
The average user read speed is set at 200 words per minute by default, this can be changed in the plugin settings.

## Using the Filter

The `|readingTime` 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 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.

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

#### Examples

```twig
{{ string|readingTime }}
{{ string|readTime }}
Returns: 30 second
```

```twig
{{ richTextField|readingTime }}
{{ richTextField|readTime }}
Returns: 2 minutes, 40 seconds
```

```twig
{{ richTextField|readingTime(false) }}
{{ richTextField|readTime(false) }}
Returns: 3 minutes
```

## Overriding Plugin Settings

If you create a [config file](https://docs.craftcms.com/v3/configuration.html) in your `config` folder called `reading-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.
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.

Here’s what that config file might look like along with a list of all of the possible values you can override.

Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "lukeyouell/craft-readingtime",
"description": "Calculate the estimated reading time for content.",
"name": "lukeyouell/craft-readtime",
"description": "Calculate the estimated read time for content.",
"type": "craft-plugin",
"version": "1.0.0",
"version": "1.1.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"average reading time"
"average read time"
],
"support": {
"docs": "https://github.com/lukeyouell/craft-readingtime/blob/master/README.md",
"issues": "https://github.com/lukeyouell/craft-readingtime/issues"
"docs": "https://github.com/lukeyouell/craft-readtime/blob/master/README.md",
"issues": "https://github.com/lukeyouell/craft-readtime/issues"
},
"license": "MIT",
"authors": [
Expand All @@ -26,15 +26,15 @@
},
"autoload": {
"psr-4": {
"lukeyouell\\readingtime\\": "src/"
"lukeyouell\\readtime\\": "src/"
}
},
"extra": {
"name": "Reading Time",
"handle": "reading-time",
"name": "Read Time",
"handle": "read-time",
"hasCpSettings": true,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/lukeyouell/craft-readingtime/master/CHANGELOG.md",
"class": "lukeyouell\\readingtime\\ReadingTime"
"changelogUrl": "https://raw.githubusercontent.com/lukeyouell/craft-readtime/master/CHANGELOG.md",
"class": "lukeyouell\\readtime\\ReadTime"
}
}
18 changes: 9 additions & 9 deletions src/ReadingTime.php → src/ReadTime.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php
/**
* Reading Time plugin for Craft CMS 3.x
* Read Time plugin for Craft CMS 3.x
*
* Calculate the estimated reading time for content.
* Calculate the estimated read time for content.
*
* @link https://github.com/lukeyouell
* @copyright Copyright (c) 2018 Luke Youell
*/

namespace lukeyouell\readingtime;
namespace lukeyouell\readtime;

use lukeyouell\readingtime\models\Settings;
use lukeyouell\readingtime\twigextensions\ReadingTimeTwigExtension;
use lukeyouell\readtime\models\Settings;
use lukeyouell\readtime\twigextensions\ReadTimeTwigExtension;

use Craft;
use craft\base\Plugin;
Expand All @@ -20,7 +20,7 @@

use yii\base\Event;

class ReadingTime extends Plugin
class ReadTime extends Plugin
{
// Static Properties
// =========================================================================
Expand All @@ -40,11 +40,11 @@ public function init()
parent::init();
self::$plugin = $this;

Craft::$app->view->registerTwigExtension(new ReadingTimeTwigExtension());
Craft::$app->view->registerTwigExtension(new ReadTimeTwigExtension());

Craft::info(
Craft::t(
'reading-time',
'read-time',
'{name} plugin loaded',
['name' => $this->name]
),
Expand All @@ -70,7 +70,7 @@ protected function settingsHtml(): string
$overrides = Craft::$app->getConfig()->getConfigFromFile(strtolower($this->handle));

return Craft::$app->view->renderTemplate(
'reading-time/settings',
'read-time/settings',
[
'settings' => $settings,
'overrides' => array_keys($overrides)
Expand Down
10 changes: 5 additions & 5 deletions src/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
/**
* Reading Time plugin for Craft CMS 3.x
* Read Time plugin for Craft CMS 3.x
*
* Calculate the estimated reading time for content.
* Calculate the estimated read time for content.
*
* @link https://github.com/lukeyouell
* @copyright Copyright (c) 2018 Luke Youell
*/

namespace lukeyouell\readingtime\models;
namespace lukeyouell\readtime\models;

use lukeyouell\readingtime\ReadingTime;
use lukeyouell\readtime\ReadTime;

use Craft;
use craft\base\Model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<?php
/**
* Reading Time plugin for Craft CMS 3.x
* Read Time plugin for Craft CMS 3.x
*
* Calculate the estimated reading time for content.
* Calculate the estimated read time for content.
*
* @link https://github.com/lukeyouell
* @copyright Copyright (c) 2018 Luke Youell
*/

namespace lukeyouell\readingtime\twigextensions;
namespace lukeyouell\readtime\twigextensions;

use lukeyouell\readingtime\ReadingTime;
use lukeyouell\readtime\ReadTime;

use Craft;
use craft\helpers\DateTimeHelper;

class ReadingTimeTwigExtension extends \Twig_Extension
class ReadTimeTwigExtension extends \Twig_Extension
{
// Public Methods
// =========================================================================

public function getName()
{
return 'readingTime';
return 'readTime';
}

public function getFilters()
{
return [
new \Twig_SimpleFilter('readingTime', [$this, 'readingTime']),
new \Twig_SimpleFilter('readTime', [$this, 'readTime']),
];
}

public function readingTime($value = null, $showSeconds = true)
public function readTime($value = null, $showSeconds = true)
{
$settings = ReadingTime::$plugin->getSettings();
$settings = ReadTime::$plugin->getSettings();

$value = is_array($value) ? implode(' ', $value) : (string)$value;
$wpm = $settings->wordsPerMinute;
Expand Down

0 comments on commit b0253e2

Please sign in to comment.