内联图像未从 GatsbyJS 中的 Markdown 文件正文加载 [英] Inline images not loading from body of the markdown file in GatsbyJS
问题描述
我正在尝试使用 gatsby-remark-images 在我的 Markdown 文件中使用内嵌图像.不幸的是,图像不会加载到我的本地主机上.我不知道这是否只是错误的语法,还是我遗漏了一些严重的东西.
这是 来自你的 Gatsby 配置它会工作.
Gatsby 配置使用该行而不是之前定义的配置.这就是不使用 gatsby-remark-images
插件的原因.
您在 Markdown 文件中的相对路径与 ../../images/train.png
正确.
从您的配置中提取的行:
module.exports = {插件: [//... 其他插件{解析:`gatsby-transformer-remark`,选项: {插件: [{解析:`gatsby-remark-images`,选项: {//指定 maxWidth(以像素为单位)很重要//作为这个插件的内容容器使用 this 作为//生成每个图像不同宽度的基础.最大宽度:1200,},},],},},//`gatsby-transformer-remark`,//删除它,因为它将覆盖之前的配置]};
加载图像的屏幕截图:
I'm attempting to use inline images in my markdown file using gatsby-remark-images. Unfortunately, the image won't load on my local host. I don't know if it's simply erroneous syntax or I am missing something drastic.
Here's the config: (I have a suspicion that I've done something wrong somewhere, it's here.)
module.exports = {
siteMetadata: {
title: ``,
description: `A blog where code is written about`,
author: `@wesley`,
},
plugins: [
`gatsby-plugin-sass`,
`gatsby-plugin-styled-components`,
`gatsby-plugin-react-helmet`,
`gatsby-plugin-catch-links`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/pages`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
// It's important to specify the maxWidth (in pixels) of
// the content container as this plugin uses this as the
// base for generating different widths of each image.
maxWidth: 1200,
},
},
],
},
},
`gatsby-transformer-remark`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/mt.png`, // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
};
I've pored over the poor documentation on Gatsby over and over. I am confounded. Anyone have an idea as to what's going on? I was able to get the featured image to work, but that's not what I want.
package.json:
Path in markdown file is right (I believe):
Screenshot of what I'm getting:
I think if you remove the following line from your Gatsby config it will work.
Gatsby config is using that line instead of the previously defined configuration. That's why gatsby-remark-images
plugin is not used.
Your relative path in the markdown file is right with ../../images/train.png
.
Extracted lines from your config:
module.exports = {
plugins: [
// ... other plugins
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
// It's important to specify the maxWidth (in pixels) of
// the content container as this plugin uses this as the
// base for generating different widths of each image.
maxWidth: 1200,
},
},
],
},
},
// `gatsby-transformer-remark`, // remove this as it will override previous configuration
]
};
Screenshot of the loaded image:
这篇关于内联图像未从 GatsbyJS 中的 Markdown 文件正文加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!