-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
381 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Reading Time Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
## 2.0.0 - 2018-07-30 | ||
|
||
### Added | ||
- Initial Craft 3 release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Nathan Reed | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
# Read Time - Craft CMS | ||
# Read Time plugin for Craft CMS 3 | ||
|
||
An estimated read time Twig filter for Craft CMS. | ||
|
||
This plugin counts the words in any field and returns the length of time it will take to read based on 200 (default) words per minute. | ||
This plugin only outputs the result in minutes. | ||
Calculate the estimated read time for content. | ||
|
||
## Installation | ||
|
||
1. Move the `readtime` directory to `craft/plugins` directory. | ||
2. Install readtime under Craft Admin › Settings › Plugins. | ||
#### Requirements | ||
|
||
## Usage | ||
By default it will only output a int or float. If you require an identifier word, such as `min` or `minutes`, you can use the first param to do that. | ||
This plugin requires Craft CMS 3.0.0, or later. | ||
|
||
#### Composer | ||
|
||
1. Open your terminal and go to your Craft project: | ||
|
||
```bash | ||
cd /path/to/project | ||
``` | ||
|
||
2. Then tell Composer to load the plugin: | ||
|
||
```bash | ||
composer require zizther/craft-readtime | ||
``` | ||
|
||
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Read Time. | ||
|
||
`{{ entry.field | readTime }}` | ||
## Configuration | ||
|
||
Will output | ||
The average user read speed is set at 200 words per minute by default, this can be changed in the plugin settings. | ||
|
||
`12` | ||
## Using the Filter | ||
|
||
The `|readTime` filter returns an accurate value in minutes for how long it takes the average user to read the provided content. The value provided can be a string or an array of values. | ||
|
||
## Usage | ||
By default it will only output an int or float. | ||
Any value < 1 will output a float, another > 1 will output a | ||
|
||
```twig | ||
{{ entry.field | readTime }}` | ||
Returns: 0.38, 3, 12 | ||
``` | ||
|
||
You can also specify the identifier word to use. The plural word is automatic. | ||
`{{ entry.field | readTime('min') }}` | ||
Any value < 1 will output with `< 1`, not a float. | ||
```twig | ||
{{ entry.field | readTime('min') }} | ||
Returns: < 1 min, 1 min or 12 mins | ||
``` | ||
|
||
You can also call it as a function | ||
`{{ readTime(entry.fieldHandle, 'min') }}` | ||
|
||
Will output | ||
## Overriding Plugin Settings | ||
|
||
`< 1 min`, `1 min` or `12 mins` | ||
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. | ||
|
||
You can also specify the words per minute | ||
`{{ entry.field | readTime('min', 215) }}` | ||
Here’s what that config file might look like along with a list of all of the possible values you can override. | ||
|
||
## License | ||
```php | ||
<?php | ||
|
||
This work is licensed under the MIT license. | ||
return [ | ||
'wordsPerMinute' => 200 | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "zizther/craft-readtime", | ||
"description": "Calculate the estimated read time for content.", | ||
"type": "craft-plugin", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"read time", | ||
"average read time" | ||
], | ||
"support": { | ||
"docs": "https://github.com/zizther/craft-readtime/blob/master/README.md", | ||
"issues": "https://github.com/zizther/craft-readtime/issues" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nathan Reed", | ||
"homepage": "https://github.com/zizther" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "^3.0.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"zizther\\readtime\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"name": "Read Time", | ||
"handle": "read-time", | ||
"hasCpSettings": true, | ||
"hasCpSection": false, | ||
"changelogUrl": "https://raw.githubusercontent.com/zizther/craft-readtime/master/CHANGELOG.md", | ||
"class": "zizther\\readtime\\readtime" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/** | ||
* Read Time plugin for Craft CMS 3.x | ||
* | ||
* Calculate the estimated read time for content. | ||
* | ||
* @link https://github.com/zizther | ||
* @copyright Copyright (c) 2018 Nathan Reed | ||
*/ | ||
|
||
namespace zizther\readtime; | ||
|
||
use zizther\readtime\models\Settings; | ||
use zizther\readtime\twigextensions\ReadTimeTwigExtension; | ||
|
||
use Craft; | ||
use craft\base\Plugin; | ||
use craft\services\Plugins; | ||
use craft\events\PluginEvent; | ||
|
||
use yii\base\Event; | ||
|
||
class ReadTime extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
public static $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
|
||
public $schemaVersion = '1.0.0'; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
Craft::$app->view->registerTwigExtension(new ReadTimeTwigExtension()); | ||
|
||
Craft::info( | ||
Craft::t( | ||
'read-time', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
protected function createSettingsModel() | ||
{ | ||
return new Settings(); | ||
} | ||
|
||
protected function settingsHtml(): string | ||
{ | ||
// Get and pre-validate the settings | ||
$settings = $this->getSettings(); | ||
$settings->validate(); | ||
|
||
// Get the settings that are being defined by the config file | ||
$overrides = Craft::$app->getConfig()->getConfigFromFile(strtolower($this->handle)); | ||
|
||
return Craft::$app->view->renderTemplate( | ||
'read-time/settings', | ||
[ | ||
'settings' => $settings, | ||
'overrides' => array_keys($overrides) | ||
] | ||
); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.