Created
April 28, 2019 19:13
-
-
Save danilowoz/b2d3ea8d9ac95d108a486e121c6dc2a7 to your computer and use it in GitHub Desktop.
Creating programmatically the pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { graphql } from "gatsby" | |
const BlogPost = ({ data }) => { | |
const { markdownRemark } = data | |
const imageSource = markdownRemark.frontmatter.image.childImageSharp.fluid.src | |
return ( | |
<> | |
<img src={imageSource} alt={markdownRemark.frontmatter.title} /> | |
<h1>{markdownRemark.frontmatter.title}</h1> | |
<p>{markdownRemark.frontmatter.date}</p> | |
<p>By {markdownRemark.frontmatter.author}</p> | |
<p>In: {markdownRemark.frontmatter.category.join()}</p> | |
<p>Tags: {markdownRemark.frontmatter.tags.join()}</p> | |
<div dangerouslySetInnerHTML={{ __html: markdownRemark.html }} /> | |
</> | |
) | |
} | |
export default BlogPost | |
export const query = graphql` | |
query BlogPostBySlug($slug: String!) { | |
markdownRemark(fields: { slug: { eq: $slug } }) { | |
html | |
frontmatter { | |
title | |
date(formatString: "MMMM DD, YYYY") | |
author | |
category | |
image { | |
childImageSharp { | |
fluid { | |
src | |
} | |
} | |
} | |
} | |
} | |
} | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment