awilum / craft-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:19:34 UTC
README
阅读时间插件显示内容的估计阅读时间,以秒或分钟为单位。
要求
- Craft CMS: ^4.0
- PHP: ^8.0
安装
要安装插件,请按照以下说明操作。
-
打开您的终端并进入Craft项目目录
cd /path/to/project
-
在终端运行
composer require awilum/craft-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 ...');