Skip to content

Gatsby remark plugin to add an estimated reading time field to all remark nodes

License

Notifications You must be signed in to change notification settings

trangcongthanh/gatsby-remark-reading-time

 
 

Repository files navigation

gatsby-remark-reading-time

Adds a medium-like reading time estimate to your gatsby remark posts. Powered by reading-time.

Installation

  1. Install
yarn add gatsby-remark-reading-time
  1. Add to gatsby-transformer-remark plugins in gatsby-config.js
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        `gatsby-remark-reading-time`,
        // ...
      ],
    },
  },

Usage

The reading time can be queried in the fields of markdownRemark nodes. An example of this in a single post would look like this:

export const query = graphql`
  query($slug: String!) {
    markdownRemark(fields: { slug: { eq: $slug } }) {
      htmlAst
      excerpt(pruneLength: 200)
      frontmatter {
        title
        date(formatString: "MMMM Do, YYYY")
      }
      fields {
        slug
        readingTime {
          text
        }
      }
    }
  }
`;

There are 4 available values in readingTime:

  • text: '1 min read',
  • minutes: 1,
  • time: 60000,
  • words: 200

License

MIT

About

Gatsby remark plugin to add an estimated reading time field to all remark nodes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%