Skip to content

Instantly share code, notes, and snippets.

@haxzie-xx
Created January 19, 2019 18:24
Show Gist options
  • Select an option

  • Save haxzie-xx/97b116ba9a8730cfd3dd22899aef1437 to your computer and use it in GitHub Desktop.

Select an option

Save haxzie-xx/97b116ba9a8730cfd3dd22899aef1437 to your computer and use it in GitHub Desktop.
Gatsby blog post template
import React from 'react'
import { graphql } from 'gatsby'
import Layout from '../components/layout'
const BlogPostTemplate = ({ data }) => {
// extract the contents from data
const { markdownRemark } = data;
const { frontmatter, html } = markdownRemark;
// return the component layout
return (
<Layout>
<h1>{ frontmatter.title }</h1>
<h3> { frontmatter.author } | { frontmatter.date } </h3>
<div dangerouslySetInnerHTML={{ __html: html }}></div>
</Layout>
);
}
export default BlogPostTemplate;
export const postDataQuery = graphql`
query postDataQuery($path: String!) {
markdownRemark(frontmatter: { slug: { eq: $path } }) {
html
frontmatter {
title
author
date
}
}
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment