【发布时间】:2021-02-25 06:06:10
【问题描述】:
在 Gatsby 中,我有 file.md,我想生成多个页面——file.md 的每个部分一个页面。
gatsby-transformer-remark
使用gatsby-transformer-remark 时,我可以使用allMarkdownRemark.nodes.html 获取整个markdown 文件的HTML。如何获取文件每个部分的 HTML?例如:
file.md:
# section 1
**bold**
# section 2
foo
我想获得一组 HTML 部分,例如:
[
'<div><h1>section 1</h1><b>bold</b></div>',
'<div><h1>section 2</h1>foo</div>'
]
gatsby-plugin-mdx
有了gatsby-plugin-mdx,我什么时候做
query MyQuery {
mdx {
headings {
value
depth
}
}
}
我明白了
{
"data": {
"mdx": {
"headings": [
{
"value": "Section1",
"depth": 1
},
{
"value": "Section2",
"depth": 1
},
]
}
},
"extensions": {}
}
但是当我这样做时:
query MyQuery {
mdx(headings: {elemMatch: {value: {eq: "Section1"}}}) {
body
}
}
body 是整个文件,而不仅仅是 Section1。
【问题讨论】:
标签: markdown gatsby gatsby-plugin