This package provides a simple way to calculate and display the estimated reading time for content in both Arabic and English.
You can install the package via composer:
composer require somarkn99/estimated-reading-time
A Wordpress version of this package is available as a plugin here
Add the service provider to the providers
array in config/app.php
:
'providers' => [
// Other Service Providers
Somarkn99\EstimatedReadingTime\EstimatedReadingTimeServiceProvider::class,
],
You can publish the configuration file using this command:
php artisan vendor:publish --provider="Somarkn99\EstimatedReadingTime\EstimatedReadingTimeServiceProvider" --tag="config"
This will publish the estimatedreadingtime.php
configuration file to the config
directory.
You can use the Blade directive to display the estimated reading time in your views:
@readingtime($content, 'en')
Or for Arabic content:
@readingtime($content, 'ar')
You can directly call the calculate
method from the EstimatedReadingTime
class in your controllers, commands, or other parts of your application:
use Somarkn99\EstimatedReadingTime\EstimatedReadingTime;
$readingTime = EstimatedReadingTime::calculate($content, 'en');
If you prefer to use an API to get the estimated reading time, you can use the provided endpoint.
Ensure the route is loaded by including it in your routes/api.php
:
Route::prefix('api')->group(function () {
require base_path('vendor/somarkn99/estimated-reading-time/src/routes/api.php');
});
Send a POST
request to /api/reading-time
with the content and language in the request body.
Request:
POST /api/reading-time
Content-Type: application/json
{
"content": "Your article content goes here...",
"lang": "en"
}
Response:
{
"reading_time": "Estimated Time of Reading: 3 Min"
}
You can customize the package by modifying the configuration options:
return [
'ar_prefix' => 'الوقت المقدر للقراءة: ',
'ar_suffix_s' => 'دقيقة',
'ar_suffix_p' => 'دقائق',
'en_prefix' => 'Estimated Time of Reading: ',
'en_suffix' => 'Min',
'en_wpm' => 300,
'ar_wpm' => 250,
'exclude_images' => true,
];
If you discover any security-related issues, please email kesen.somar.99@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.