内嵌图片未从GatsbyJS中的markdown文件的主体加载

时间:2019-11-19 19:25:40

标签: javascript reactjs graphql markdown gatsby

我正在尝试使用gatsby-remark-images在Markdown文件中使用嵌入式图像。不幸的是,该图像不会加载到我的本地主机上。我不知道这仅仅是语法错误还是我遗漏了一些夸张的东西。

这里是config :(我怀疑我在某处做错了,在这里。)

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

我反复研究了关于盖茨比的糟糕文献。我很困惑。任何人都知道发生了什么事吗?我能够使用精选图片,但这不是我想要的。

package.json: here's the json package

降价文件中的路径正确(我相信): path is right (i believe)

我得到的屏幕截图: but this is what i'm getting

1 个答案:

答案 0 :(得分:0)

我认为,如果您从Gatsby配置中删除以下line,它将可以正常工作。

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

您的降价文件中的相对路径右对齐../../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 
   ]
};

已加载图像的屏幕截图train image