Gatsby.js中带有Markdown备注的自定义前题变量
我正在使用Gatsbyjs和NetlifyCMS建立一个网站.我已经开始使用此启动器 https://github.com/AustinGreen/gatsby-starter- netlify-cms ,而我现在正在尝试对其进行自定义.
I am building a website using Gatsbyjs and NetlifyCMS. I've started using this starter https://github.com/AustinGreen/gatsby-starter-netlify-cms, and I am trying to customise it now.
我想在降价文件的开头使用自定义变量,如下所示:
I want to use custom variables in the frontmatter of a markdown file like this:
---
templateKey: mirror
nazev: Černobílá
title: Black and White
cena: '2700'
price: '108'
thumbnail: /img/img_1659.jpeg
---
我想使用GraphQL访问此数据.我使用gatsby-source-filesystem和gatsby-transform-remark.这是我的查询:
I want to acess this data with GraphQL. I use gatsby-source-filesystem and gatsby-transform-remark. This is my query:
{
allMarkdownRemark {
edges {
node {
frontmatter {
templateKey
nazev
title
cena
price
}
}
}
}
}
我无法让GraphQL读取我自己的变量,它只能识别title
和templateKey
(那些已经在启动程序中使用的变量).我收到此错误:
I can't get the GraphQL to read my own variables, it recognises only title
and templateKey
(those, that were already used in the starter). I get this error:
{
"errors": [
{
"message": "Cannot query field \"nazev\" on type \"frontmatter_2\".",
"locations": [
{
"line": 7,
"column": 11
}
]
},
{
"message": "Cannot query field \"cena\" on type \"frontmatter_2\".",
"locations": [
{
"line": 9,
"column": 11
}
]
},
{
"message": "Cannot query field \"price\" on type \"frontmatter_2\". Did you mean \"pricing\"?",
"locations": [
{
"line": 10,
"column": 11
}
]
}
]
}
我已经搜索了几天,但什么也没找到.有人可以帮我吗?
I've searched for days, but found nothing. Would someone help me please?
已解决!
问题是我的markdown文件的最前面的新添加的属性没有显示在我的GraphQL中.
The problem was that the newly-added properties in the frontmatter of my markdown file didn't show up in my GraphQL.
我要做的就是用"gatsby-develop"重新启动服务器.
All I had to do was to restart the server with 'gatsby-develop'.