背景:
我正在/src/content/
使用页面布局模板以编程方式创建带有 .mdx 文件的页面。一切正常,直到我需要从 .mdx 文件的 frontmatter 中获取图像,格式如下:
示例:/src/content/.../.../hello-world.mdx
---
title: foo
image: ../images/icon.png
---
hello world.
我在我的gatsby-config.js
. 此外,我gatsby-config.js
使用 gatsby-source-filesystem 的选项设置了我的文件,以在 .mdx 文件中查找 .mdx 文件/src/content
。
问题:
Gatsby在此声明“任何包含图像的 GraphQL 文件对象都将具有一个 childImageSharp 字段,您可以使用该字段来查询图像数据。” 然而,这对我来说并没有发生:
它只是将image:
frontmatter 中的键视为字符串,而从不给它childImageSharp
字段。试图通过写出字段来强制查询只会导致错误。
然而!!!
如果我使用相同的 .mdx 文件并将其放入/src/pages
突然 gatsby-plugin-image 开始正常运行并提供以下childImageSharp
字段:
为什么?
更新:将 .mdx 文件放入/src/content/
作品中,childImageSharp 字段出现在 GraphQL 中,但 .mdx 文件放置在更深的位置(例如:)src/content/recipes/guacamole/
不起作用。