Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Time to read #37

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const BlogIndex = ({ data, location }) => {

export default BlogIndex

export const pageQuery = graphql`
export const pageQuery = graphql `
query {
site {
siteMetadata {
Expand All @@ -60,7 +60,7 @@ export const pageQuery = graphql`
slug
}
frontmatter {
date(formatString: "MMMM DD, YYYY")
date (formatString: "DD [de] MMMM, YYYY", locale: "es")
title
description
author
Expand Down
20 changes: 16 additions & 4 deletions src/styles/templates/blog-post.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@
text-decoration: none;
box-shadow: none;
}
.blogpost__date p {
font-size: 12px;
margin: 0;
}
.blogpost__author p, h2 {
padding: 0;
font-size: 16px;
margin: 0 0 0 .5em

}
@media (max-width: 600px) {
.blogpost__author {
flex-direction: column;
align-items: flex-start;
}
.blogpost__author img {
margin-bottom: .3em;
margin-left: .7em;
}
}
9 changes: 6 additions & 3 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 gravatar from '../utils/gravatar';
import '../styles/templates/blog-post.css';
import { Link, graphql } from "gatsby";
import readingTime from "../utils/readingTime";

import Layout from "../components/layout";
import SEO from "../components/seo";
Expand All @@ -12,6 +13,7 @@ const BlogPostTemplate = ({ data, pageContext, location }) => {
const siteTitle = data.site.siteMetadata.title;
const { previous, next } = pageContext;
const { title, date, description, author, email, platziUser } = post.frontmatter;
const timeToRead = readingTime(post.html);

return (
<Layout location={location} title={siteTitle}>
Expand All @@ -37,11 +39,12 @@ const BlogPostTemplate = ({ data, pageContext, location }) => {
{author}
</a>
</h2>
</div>
<div className="blogpost__date">
<p>
{date}
</p>
<p>
{ timeToRead }
</p>
</div>
</div>
</header>
Expand Down Expand Up @@ -100,7 +103,7 @@ export const pageQuery = graphql`
html
frontmatter {
title
date(formatString: "MMMM DD, YYYY")
date (formatString: "DD [de] MMMM, YYYY", locale: "es")
description
author
email
Expand Down
9 changes: 9 additions & 0 deletions src/utils/readingTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const readingTime = (text) => {
const wordsPerMinute = 200;
const numOfWords = text.split(/\s/g).length;
const minutes = numOfWords / wordsPerMinute;
const readTime = Math.ceil(minutes);
return `Tiempo de lectura ${readTime} min`;
}

export default readingTime