I have a bunch of markdown files like below where I reference a path to an image in the project at src/images
:
---
title: "Test"
picture: "images/image.png"
subtitle: "Hello friends"
---
this is a testing markdown file
and a gatsby-config
entry which the image paths are based upon:
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
I then query for these markdown files which are all in the same directory:
const query = useStaticQuery(graphql`
query MyQuery {
allMarkdownRemark(filter: {fileAbsolutePath: {regex: "/markdown-content/"}}, sort: {order: DESC, fields: [frontmatter___date]}) {
edges {
node {
frontmatter {
title
picture
subtitle
}
excerpt
}
}
}
}
`);
and generate a TestComponent
like below for each markdown file by mapping over the nodes and passing the data as a prop
const TestComponent = ({ data: { frontmatter: { title, picture, subtitle }, excerpt } }) => (
<Container>
<img src={picture} />
<h1>{title}</h1>
<h2>{maintext}</h2>
<p>{excerpt}</p>
</Container>
);
The issue is that Gatsby doesn't pick up the images in the build
or develop
passes so the images are broken. The only solution in the docs for this use case seems to be the static
directory, but I'd like to keep the images in src/images
. Is this possible?