我已从gatsby netlify started repo向config.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" }
然后我在简历页面组件中查询数据:
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
,数据就在那里。为什么在嵌套在列表中的窗口小部件不起作用?
感谢您的帮助。
编辑:repo with my code供参考
答案 0 :(得分:0)
gatsby-transformer-remark
转换将仅转换.md
文件正文中的markdown。它不知道如何转换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为空。