定制 philippecharrat/reader-time-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

philippecharrat/reader-time-bundle

最新稳定版本:1.0.1

Composer 安装命令:

composer require philippecharrat/reader-time-bundle

包简介

A tool for calculating the time required to read online content

README 文档

README

A Symfony bundle that provides a Twig filter to estimate the time required to read online content (text or rich HTML).

It supports:

  • word counting (unicode letters)
  • optional rich-content overhead (images + tables)
  • per-language reading speed presets (WPM) for several languages

Requirements

  • PHP >= 8.1
  • Symfony FrameworkBundle ^6.0 || ^7.0
  • TwigBundle ^6.0 || ^7.0

Installation

Install with Composer:

composer require philippecharrat/reader-time-bundle

Symfony Flex should auto-enable the bundle (depending on your project setup). If not, enable it manually:

// config/bundles.php
return [
// ...
PhilippeCharrat\ReaderTimeBundle\ReaderTimeBundle::class => ['all' => true],
];

Configuration

Create (or edit) the following file:

# config/packages/reader_time.yaml
reader_time:
words_per_minute: 200
minimum_minutes: 1

Options

  • words_per_minute (int, default: 200, min: 1) Base reading speed used when no langcode preset is provided (or if it is unknown).
  • minimum_minutes (int, default: 1, min: 0) Minimum value returned when content is not empty (use 0 if you want to allow returning 0 for very short content).

Usage (Twig)

A Twig filter is provided:

Filter name: reader_time_minutes
Signature: reader_time_minutes(content, onlyText = false, langcode = null)

Examples

Estimate from rich HTML (text + images + tables):

{{ article.content|reader_time_minutes }}

Estimate from plain text only (ignore images/tables):

{{ article.content|reader_time_minutes(true) }}

Use a language preset (affects WPM):

{{ article.content|reader_time_minutes(false, 'fr') }}

Available language codes : ar, zh, nl, en, fi, fr, de, he, it, ko, es, sv

How it works (high-level)

Text is extracted with strip_tags() and normalized whitespace.
Words are counted using a unicode letters regex (\p{L}+).
If onlyText=false, extra time is added for:
    images (<img ...>) with a reduced weight when alt=""
    tables (<table ...>)

Contributing

Issues and pull requests are welcome.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固