How to Build a blog with Astro, Strapi, & Tailwind CSS

In case anyone still looking for answers on how to enable read time functionality follow these steps and it should work;

1 - Run this in your headlesss-blog repo to install reading-time package.

npm install reading-time --production

2 - Add a new file “lifecycles.js” in the following path;

src\api\post\content-types\post\lifecycles.js

3 - Add this code to lifecycles.js;

const readingTime = require("reading-time");

module.exports = {
  beforeCreate(event) {
    const { data, where, select, populate } = event.params;

    if (event.params.data.content && event.params.data.content?.length > 0) {
      // @ts-ignore
      event.params.data.readingTime = readingTime(event.params.data.content)?.text || null;
    }
  },

  beforeUpdate(event) {
    const { data, where, select, populate } = event.params;

    if (event.params.data.content && event.params.data.content?.length > 0) {
      // @ts-ignore
      event.params.data.readingTime = readingTime(event.params.data.content)?.text || null;
    }
  },

};

It appears that they’ve changed file structure multiple times, the article has links to explain the new structure.

1 Like