@breezertwo/strapi-plugin-reading-time
v5.2.0
Published
Calculate the reading time of your content
Downloads
280
Maintainers
Readme
Strapi Plugin Reading Time
A plugin for Strapi that provides the ability to automatically calculate the reading time of text based fields. Supports extracting text from nearly all field types. (e.g Text, Rich text (Blocks), Markdown, Lists, Image captions, ...)
Installation
npm i @breezertwo/strapi-plugin-reading-timeConfiguration
Add the following config to ./config/plugins.ts.
module.exports = ({ env }) => ({
// ...
'reading-time': {
enabled: true,
config: {
contentTypes: {
'api::article.article': { // UID of collection-type
field: 'reading_time', // the field name for the reading time value in the schema
references: ['content', 'description'], // the names of the fields included in the reading time calculation
},
// ...
},
},
},
// ...
});The field (e.g reading_time) must be float/decimal type in the collection-type schema and unique for each locale.
Adding the reading time field to an existing collection-type will require you to change, save or republish the entry/entries in order for this plugin to update the field correctly.
How reading time is recalculated
Absent or empty references are skipped.If no reference has any content, the reading time is not recalculated.
On update, the plugin only recalculates when every configured reference is in the payload. A partial update (e.g. PUT that sends only title) does not recalculate, because the fields it would need aren't part of the request. Strapi admin panel always submits the full form, entries edited through the UI are always recalculated; only partial API writes are affected.
On create, every configured reference is counted.
Components and dynamic zones
references decides what is counted. Point it at a component or dynamic zone and every text field inside is counted, however deeply nested, with no further configuration:
Example:
[...]
"blocks": {
"type": "dynamiczone",
"components": [
"shared.media",
"shared.quote",
"shared.rich-text",
"shared.slider"
]
},
[...]config: {
contentTypes: {
'api::article.article': {
field: 'reading_time',
references: ['title', 'blocks'],
},
},
},Text inside uploaded media is limited to caption and alternativeText — filenames, mime types and format variants are never counted.
Upgrading
skipUndefinedReferences was removed
Delete it from your config; the plugin warns on startup if it is still set. Its true behaviour is now the only behaviour.
Previously the default (false) meant that a single empty reference suppressed the calculation entirely, so a content-type referencing an empty dynamic zone or an unfilled optional field never got a reading time at all. The option also had no effect on updates, since a partial payload is short-circuited before it is consulted.
Reading times are now calculated from whichever references have content, so entries that previously got no value will get one on their next save.
📄 License
This project is licensed under the MIT License — see the LICENSE file for details.
If you find this plugin helpful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs and issues
- 🤝 Contributing to the project
- 💡 Suggesting new features
- 📣 Sharing with others who might benefit
