craft-plugins / reading-time
阅读时间插件显示内容的估计阅读时间,以秒或分钟为单位。
1.1.0
2022-12-13 11:51 UTC
Requires
- craftcms/cms: ^4.3.3
Requires (Dev)
- ext-iconv: *
- pestphp/pest: ^1.22
- phpstan/phpstan: ^1.8.0
This package is auto-updated.
Last update: 2024-09-13 16:23:42 UTC
README
阅读时间插件显示内容的估计阅读时间,以秒或分钟为单位。
需求
- Craft CMS: ^4.0
- PHP: ^8.0
安装
要安装插件,请按照以下说明操作。
-
打开您的终端并进入您的Craft项目
cd /path/to/project
-
在终端中运行
composer require awilum/craft-reading-time
。 -
在控制面板中,转到设置 → 插件,然后点击Reading Time的“安装”按钮。
使用方法
在twig模板中显示阅读时间
{{ readingTime('Some text here ...') }}
在twig模板中使用自定义翻译显示阅读时间
{{ readingTime('Some text here ...', {
'minute': 'Minute',
'minutes': 'Minutes',
'second': 'Second',
'seconds': 'Seconds'
}) }}
在twig模板中使用自定义翻译和格式显示阅读时间
{{ readingTime('Some text here ...', {
'minute': 'Minute',
'minutes': 'Minutes',
'second': 'Second',
'seconds': 'Seconds',
'format': '[minutes_count] [minutes_label] – [seconds_count] [seconds_label]'
}) }}
在twig模板中使用自定义翻译和格式,并以不同的格式显示,隐藏minutes
和seconds
标签
{{ readingTime('Some text here ...', {
'minute': 'Minute',
'minutes': 'Minutes',
'second': 'Second',
'seconds': 'Seconds',
'format': '[minutes_count] [minutes_label] – [seconds_count] [seconds_label]'
}) }}
您还可以在twig模板中使用readingTime
过滤器
{{ 'Some text here ...'|readingTime }}
在PHP中使用readingTime
函数
use function Awilum\CraftReadingTime\readingTime; echo readingTime('Some text here ...');
许可
MIT许可 (MIT) 版权所有 (c) Sergey Romanenko