awilum/craft-reading-time

阅读时间插件显示内容的估计阅读时间,以秒或分钟为单位。

资助包维护!
awilum.github.io/donate

安装: 403

依赖: 0

建议者: 0

安全: 0

星标: 5

关注者: 2

分支: 0

类型:craft-plugin

1.1.0 2022-12-13 11:51 UTC

This package is auto-updated.

Last update: 2024-09-13 16:19:34 UTC


README

License MIT GitHub Repo stars GitHub forks Hits of Code

阅读时间插件显示内容的估计阅读时间,以秒或分钟为单位。

要求

  • Craft CMS: ^4.0
  • PHP: ^8.0

安装

要安装插件,请按照以下说明操作。

  1. 打开您的终端并进入Craft项目目录

    cd /path/to/project
    
  2. 在终端运行 composer require awilum/craft-reading-time

  3. 在控制面板中,转到设置 → 插件,并点击“安装”按钮进行阅读时间。

使用方法

在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模板中使用自定义翻译和格式,并使用隐藏minutesseconds标签的替代格式显示阅读时间

{{ 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)版权所有 Sergey Romanenko