GithubHelp home page GithubHelp logo

ernestofgonzalez / gatsby-remark-reading-time Goto Github PK

View Code? Open in Web Editor NEW

This project forked from syntra/gatsby-remark-reading-time

0.0 2.0 0.0 226 KB

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

License: MIT License

JavaScript 100.00%

gatsby-remark-reading-time's Introduction

gatsby-remark-reading-time

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

This plugin supports both MD and MDX formats.

Installation

Install

yarn add gatsby-remark-reading-time

Markdown (MD)

Add to gatsby-transformer-remark plugins in gatsby-config.js

// gatsby-config.js
  ...
  plugins: [
    ...
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          `gatsby-remark-reading-time`,
          // ...
        ],
      },
    },
  ]

MDX

Add this plugin outside your gatsby-plugin-mdx config, i.e. this plugin should not live within either of remarkPlugins or gatsbyRemarkPlugins config options:

// gatsby-config.js
  ...
  plugins: [
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [...],
        remarkPlugins: [...],
      },
    },
    'gatsby-remark-reading-time',
     ...
  ],

Usage

The reading time can be queried in the relevant markdown fields. An example of this is shown below for a single post:

Markdown (MD)

If you are using the gatsby-transformer-remark plugin then you can use:

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
        }
      }
    }
  }
`;

MDX

If you are using the gatsby-plugin-mdx plugin then you can use:

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

Fields

There are 4 available fields within readingTime:

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

License

MIT

gatsby-remark-reading-time's People

Contributors

aritheelk avatar ernestofgonzalez avatar tgallacher avatar trangcongthanh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.