内联图像未从 GatsbyJS 中的 Markdown 文件正文加载

Wes*_*lle 3 javascript markdown reactjs graphql gatsby

我正在尝试使用 gatsby-remark-images 在我的降价文件中使用内联图像。不幸的是,图像不会加载到我的本地主机上。我不知道这是否只是错误的语法,或者我遗漏了一些严重的东西。

这是配置:(我怀疑我在某处做错了什么,它在这里。)

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`,
  ],
};

Run Code Online (Sandbox Code Playgroud)

我一遍又一遍地研究了关于 Gatsby 的糟糕文档。我很困惑。任何人都知道发生了什么?我能够让特色图片发挥作用,但这不是我想要的。

包.json: 这是 json 包

降价文件中的路径是正确的(我相信): 路径是对的(我相信)

我得到的截图: 但这就是我得到的

AWo*_*olf 6

我认为如果您从 Gatsby 配置中删除以下,它将起作用。

Gatsby 配置正在使用该行而不是之前定义的配置。这gatsby-remark-images就是不使用插件的原因。

Markdown 文件中的相对路径与../../images/train.png.

从您的配置中提取的行:

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 
   ]
};
Run Code Online (Sandbox Code Playgroud)

加载的图片截图: 火车图片

  • 我知道这不是评论的最佳用途,但这个答案使我免于数小时令人困惑的调查。非常感激。 (2认同)