Skip to content
 
 

Repository files navigation

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, ...)

NPM Version Strapi Version Test

Installation

npm i @breezertwo/strapi-plugin-reading-time

Configuration

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'],
    },
  },
},

📄 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

About

A plugin for Strapi Headless CMS that provides the ability to calculate the reading time for a piece of content.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages