Gatsby 如何使用 GraphQL 提供 Markdown frontmatter?

How does Gatsby serve up Markdown frontmatter with GraphQL?

对我来说,Gatsby 最有趣的功能是 gatsby-source-filesystem 能够进入降价文件目录并通过 GraphQL 查询为 React 提供静态内容。本质上,带有 YAML frontmatter 的平面文件是可过滤、可排序、可嵌套等的。它是如何完成的?它是基于现有的方法吗?如果没有,是否可以将其提取出来与其他堆栈一起使用? (以 Vuepress 为例)

追问:方法是YAML具体的吗?可以是 TOML 或 JSON 或 CSV 或 or 或...?

gatsby-source-filesystem 没有任何特定于 markdown 的逻辑,实际上不负责拆分 frontmatter。那是 gatsby-transformer-remark 的工作,它使用 grey-matter to do the actual frontmatter parsing (source).

从那里使用 Gatsby 提供的 createNode 操作创建节点。类型由 Gatsby 根据节点的值推断。