1

我从gatsby netlify started repoconfig.yml向文件添加了一个新页面:

  - name: "pages"
    label: "Pages"
    files:
      - file: "src/pages/CV/index.md"
        label: "CV"
        name: "CV"
        fields:
          - {
              label: "Template Key",
              name: "templateKey",
              widget: "hidden",
              default: "cv-page",
            }
          - { label: "Name", name: "name", widget: "string" }
          - { label: "Portrait", name: "portrait", widget: "image" }
          - label: "Categories"
            name: "categories"
            widget: "list"
            fields:
              - { label: Title, name: title, widget: string }
              - { label: "Body", name: "body", widget: "markdown" }

然后我在我的 cv-page 组件中查询数据:

export const cvPageQuery = graphql`
  query CVPage($id: String!) {
    markdownRemark(id: { eq: $id }) {
      frontmatter {
        name
        portrait
        categories {
          title
          body
        }
      }
    }
  }
`;

现在我希望gatsby-transformer-remark将类别正文从 markdown 解析为 html - 但查询只是返回一个 markdown 字符串(例如body: "* one↵* two↵* three↵* four")。

之前,当我将 markdown 小部件作为字段直接放在页面上时,我只需要查询html外部frontmatter数据,数据就会在那里。为什么这不适用于嵌套在列表中的小部件?

谢谢您的帮助。

编辑:回购与我的代码供参考

4

1 回答 1

0

gatsby-transformer-remark转换只会转换文件正文中的降价.md。它不知道在您的frontmatter.

pages/CV/index.md

---
templateKey: cv-page
name: Miha Šušteršič
portrait: /img/headshot.png
categories:
  - body: |-
      * one
      * two
      * three
      * four
    title: Work experience
  - body: |-
      * one
      * two 
      * three
      * four
    title: Education and training
---

从查询:

{
  "markdownRemark": {
    "html": "",
    "frontmatter": {
      "name": "Miha Šušteršič",
      "portrait": "/img/headshot.png",
      "categories": [{
          "title": "Work experience",
          "body": "* one\n* two\n* three\n* four"
        },
        {
          "title": "Education and training",
          "body": "* one\n* two \n* three\n* four"
        }
      ]
    }
  }
}

从上面的查询结果可以看出,你的 html 是空的,因为 body 是空的。

于 2018-10-20T17:29:18.737 回答