Skip to content

Commit

Permalink
feat(blog-post): add reading time
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofdombi committed Dec 1, 2018
1 parent bf37551 commit 4a7d3aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"react-dom": "^16.5.1",
"react-helmet": "^5.2.0",
"react-typography": "^0.16.13",
"reading-time": "^1.1.3",
"typeface-merriweather": "0.0.43",
"typeface-montserrat": "0.0.43",
"typography": "^0.16.17",
Expand Down
3 changes: 3 additions & 0 deletions src/templates/blog-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Helmet from 'react-helmet'
import { Link, graphql } from 'gatsby'
import get from 'lodash/get'
import readingTime from 'reading-time'

import Bio from '../components/Bio'
import Layout from '../components/Layout'
Expand All @@ -13,6 +14,7 @@ class BlogPostTemplate extends React.Component {
const siteTitle = get(this.props, 'data.site.siteMetadata.title')
const siteDescription = post.excerpt
const { previous, next } = this.props.pageContext
const timeToRead = readingTime(post.html)

return (
<Layout location={this.props.location} title={siteTitle}>
Expand All @@ -31,6 +33,7 @@ class BlogPostTemplate extends React.Component {
}}
>
{post.frontmatter.date}
{` - ${timeToRead.text}`}
</p>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
<hr
Expand Down

0 comments on commit 4a7d3aa

Please sign in to comment.