问题描述
我正在尝试将 Markdown 文件注入到我的 Gatsby 页面中,该页面在本地运行(开发和服务器)。但是,同样的 graphql 查询在 Netlify 中无法返回数据。对我来说似乎很奇怪。
export const query = graphql`
query {products_horizontal: file(
sourceInstanceName: { eq: "products" }
childMarkdownRemark: { frontmatter: { vertical: { eq: false } } }
) {
sourceInstanceName
childMarkdownRemark {
frontmatter {
title
date
store
vertical
price
image
templateKey
description
featuredpost
featuredimage
tag
color
}
}
}}`
我在构建时添加了一个 console.log 来查看我的数据对象的内容,下面是我的应用程序的本地构建
products_horizontal: {
sourceInstanceName: 'products',childMarkdownRemark: { frontmatter: [Object] }
},
如您所见,product_horizontal 有一个备注节点。现在,当涉及到 netlify 中完全相同的文件时。我得到以下信息:
products_horizontal: null
注意:当我从过滤器中删除 frontmatter: { vertical: { eq: false } }
时,它也适用于 Netlify。
我已经被这个错误困扰了大约 6 个小时,非常感谢您的帮助。我现在将添加更多代码以供参考。 gatsby-config.js
module.exports = {
plugins: [
`gatsby-plugin-sass`,`gatsby-plugin-sharp`,"gatsby-plugin-netlify-cms",`gatsby-transformer-sharp`,{
resolve: `gatsby-transformer-remark`,options: {
// commonmark mode (default: true)
commonmark: true,// Footnotes mode (default: true)
footnotes: true,// Pedantic mode (default: true)
pedantic: true,// GitHub Flavored Markdown mode (default: true)
gfm: true,// Plugins configs
plugins: [],},{
resolve: `gatsby-source-filesystem`,options: {
name: "images",path: `${__dirname}/src/images`,options: {
name: "products",path: `${__dirname}/product`,options: {
name: "blogs",path: `${__dirname}/blog`,options: {
name: "tags",path: `${__dirname}/tag`,{
resolve: "gatsby-plugin-layout",options: {
component: require.resolve(`./src/components/Layout/index.tsx`),{
resolve: `gatsby-plugin-intl`,options: {
path: `${__dirname}/src/intl`,languages: [`en`,`az`,`ru`],defaultLanguage: `en`,redirect: false,],}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)