Skip to content

Instantly share code, notes, and snippets.

@Ekwuno
Created February 28, 2021 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ekwuno/9c023648c4190b35f0e7ace9ae84b9d0 to your computer and use it in GitHub Desktop.
Save Ekwuno/9c023648c4190b35f0e7ace9ae84b9d0 to your computer and use it in GitHub Desktop.
This version uses Gatsby plugin Image
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