在 Gatsby.js 中使用 Markdown Remark 自定义 frontmatter 变量 [英] Custom frontmatter variables with Markdown Remark in Gatsby.js

查看:25
本文介绍了在 Gatsby.js 中使用 Markdown Remark 自定义 frontmatter 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 读取我自己的变量,它只能识别 titletemplateKey(那些已经在 starter 中使用的).我收到此错误:

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 文件的 frontmatter 中新添加的属性没有显示在我的 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'.

这篇关于在 Gatsby.js 中使用 Markdown Remark 自定义 frontmatter 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆