Created
February 28, 2021 16:01
-
-
Save Ekwuno/9c023648c4190b35f0e7ace9ae84b9d0 to your computer and use it in GitHub Desktop.
This version uses Gatsby plugin Image
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 Layout from "../../components/layout"; | |
import { graphql } from "gatsby"; | |
import { MDXRenderer } from "gatsby-plugin-mdx"; | |
import { GatsbyImage, getImage } from "gatsby-plugin-image"; | |
export const query = graphql` | |
query($slug: String) { | |
mdx(slug: { eq: $slug }) { | |
frontmatter { | |
date(formatString: "MM DD YYYY") | |
title | |
hero_image { | |
childImageSharp { | |
gatsbyImageData( | |
formats: [JPG, WEBP, AVIF] | |
placeholder: TRACED_SVG | |
avifOptions: { speed: 10 } | |
) | |
} | |
} | |
} | |
slug | |
body | |
} | |
} | |
`; | |
const BlogPosts = ({ data }) => { | |
const image = getImage(data.mdx.frontmatter.hero_image); | |
return ( | |
<Layout> | |
<GatsbyImage image={image} aria-hidden={true} /> | |
<MDXRenderer>{data.mdx.body}</MDXRenderer> | |
</Layout> | |
); | |
}; | |
export default BlogPosts ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment