1

我正在与 Gatsby 合作,我想用降价的图片加载我的帖子。

我正在使用本教程: https ://www.gatsbyjs.org/docs/working-with-images-in-markdown/

我正确加载和删除了我的“featuredImage”,然后模糊了跨度。

但是 Markdown 中的图像被加载,但模糊的跨度仍然留在页面上。

我的gatsby-config.js

//https://www.gatsbyjs.org/docs/adding-markdown-pages/

module.exports = {
  siteMetadata: {
    title: `Tzook Blog`,
    description: `My old blog in new gatsby`,
    author: `@tzookb`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/content/`
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 1200
            },
          },
        ],
      },
    },
    {
      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/gatsby-icon.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`,
    `gatsby-plugin-emotion`
  ],
}

看这些图片:

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

4

2 回答 2

3

可以在cwgw 对此 open gatsby 问题的评论找到解决方法:

所以再深入一点,看起来 Gatsby 只在一个特定的路径上寻找“子插件”,options.plugins.

gatsby-plugin-mdx使用options.gatsbyRemarkPlugins. 这对于转换 markdown 是很好的,因为插件本身会处理它,但是像 Gatsby 特定的 api 文件gatsby-browser.js不会被加载,因为 Gatsby 不知道它们存在。

如果你试试这个……</p>

{
  resolve: 'gatsby-plugin-mdx',
  options: {
    gatsbyRemarkPlugins: [ `gatsby-remark-images` ],
    plugins: [ `gatsby-remark-images` ],
  }
},

…一切正常。

于 2019-10-23T10:41:31.473 回答
2

ksav 的解决方案对我有用 - 如果有人感到困惑,这是以下语法的缩写: { resolve: 'gatsby-plugin-mdx', options: { gatsbyRemarkPlugins: [{ resolve: 'gatsby-remark-images' }], plugins: [{ resolve: 'gatsby-remark-images' }], }, 其中带有键 'resolve' 的对象用于指定插件名称,而不是简单地将其作为字符串传递到数组中。

于 2019-11-11T02:57:27.850 回答