
They will be processed by sharp and appear as if you placed them in a gatsby-plugin-image component.Exif Variables. With the configurations above, you can use the default markdown syntax for images. Gatsby-remark-images needs to be a sub-plugin of gatsby-plugin-mdx, included in the gatsbyRemarkPlugins array. Put the gatsby-remark-images plugin within the plugins option field of gatsby-transformer-remark. As with the previous example, either markdown or MDX can be used. Start out by installing gatsby-remark-images:Ĭonfigure the plugins in your gatsby-config file. The plugin gatsby-remark-images comes in handy for this. You may also include images in the markdown/MDX body itself.
MARKDOWN RESIZE IMAGE CODE
The code example above is just an example, adjust the portion to how you’d want to use it in your template. In the blog post template, import the gatsby-plugin-image package and pass the results of the GraphQL query into an component. The query below might be different to what you have in your blog post template, however the highlighted section will be relevant nevertheless: In this example, a Dynamic image is used to make a responsive image. This can be added to the GraphQL query in a markdown template file. If a filepath points to an actual image, it will be transformed into a File node in GraphQL and then you can get the image data out of it by using the childImageSharp field. Now that you’ve sourced markdown and image data, you can query for featured images in GraphQL. Then, in a markdown file, the path to a featuredImage would be relative to the page file (in this case, in an /images directory up a level): Querying for images from frontmatter You can set this up by specifying two distinct sources, one for the markdown files and the other for images: There are also occasions when you may want to source images from a different directory than where your markdown posts or pages are located, such as in an external /images folder. Configuring for images and posts in different directories The next step will be to incorporate the data into a template with a GraphQL query, which can be found later in this guide. Then, in an example markdown file, add a field called featuredImage: For example, if your markdown files and images are located together in a src/content directory, both content types will be automatically picked up by GraphQL as part of Gatsby’s data layer. If your images are in the same directory as the markdown files, sourcing and resolving the images can be done in one configuration. Configuring for images and posts in the same directory Then, configure the various plugins in the gatsby-config file.
MARKDOWN RESIZE IMAGE INSTALL
To start out, install the necessary plugins for gatsby-plugin-image. The tutorial uses MDX, the instructions below will use markdown for the most part. If you want to have a very detailed explanation of this, head to part 7 of the Gatsby tutorial. One way to do this is to grab the image filename from a frontmatter field and then transform it with gatsby-plugin-sharp in a GraphQL query. In sites like a blog, you may want to include a featured image that appears at the top of a page. Follow the MDX instructions or markdown instructions.įeatured images with frontmatter metadata Either markdown or MDX support added to your site.


(Need help creating one? Follow the Quick Start) The instructions also assume that you already have an existing Gatsby site running with either markdown or MDX. If you’re new to Gatsby we recommend checking out the main tutorial first.


You can add images in multiple ways which will be explained below. When building Gatsby sites composed primarily of markdown or MDX, insertion of images can enhance the content.
