craft-plugins/reading-time

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

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

安装次数: 16

依赖项: 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:23:42 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. 在控制面板中,转到设置 → 插件,然后点击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模板中使用自定义翻译和格式,并以不同的格式显示,隐藏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) 版权所有 (c) Sergey Romanenko