I am trying to add gatsby-image with GraphQL. I don't need to rewrite my entire starter I just want the image optimization for loading times. All of the data queries were done with lodash so im getting confused. I know I am missing something simple following the documentation.
I am testing with a title just to see if I am accessing the data.
Do I need to add this query to gatsby-node?
import React from 'react';
import _ from 'lodash';
import { useStaticQuery, graphql } from "gatsby"
import { Layout } from '../components/index';
import { htmlToReact, safePrefix } from '../utils';
export default class Post extends React.Component {
render() {
const data = useStaticQuery(graphql`
query postInfo {
allMarkdownRemark {
edges {
node {
id
frontmatter {
content_img_path
excerpt
img_path
subtitle
title
}
}
}
}
}
`)
return (
<Layout {...this.props}>
<article className="post post-full">
<header className="post-header">
<div className="post-meta">
</div>
<h1 className="post-title">{_.get(this.props, 'pageContext.frontmatter.title')}</h1>
</header>
{_.get(this.props, 'pageContext.frontmatter.subtitle') &&
<div className="post-subtitle">
{htmlToReact(_.get(this.props, 'pageContext.frontmatter.subtitle'))}
</div>
}
<h3>{data.allMarkdownRemark.title}</h3>
{_.get(this.props, 'pageContext.frontmatter.content_img_path') &&
<div className="post-thumbnail">
<img className="thumbnail" src={safePrefix(_.get(this.props, 'pageContext.frontmatter.content_img_path'))} alt={_.get(this.props, 'pageContext.frontmatter.title')} />
</div>
}
<div className="post-content">
{htmlToReact(_.get(this.props, 'pageContext.html'))}
</div>
</article>
</Layout>
);
}
}