【发布时间】:2020-11-15 05:03:24
【问题描述】:
我正在尝试在我的 markdown frontmatter 中存储一个按钮的内容,该按钮会将用户导航到不同的页面,因为它可以通过 Netlify CMS 进行编辑。
当 GraphQL 静态查询返回数据时,我的 frontmatter 已转换为相对文件路径,而不是预期的页面 URL。页面查询不会发生这种情况。
页脚.md:
---
templateKey: footer
title: Some footer title
logo: /img/logo.svg
links:
- url: /prices/
text: Prices
- url: /privacy-policy/
text: Privacy policy
---
GraphQL 静态查询:
const queryData = useStaticQuery(graphql`
query FooterComponent {
site {
siteMetadata {
title
}
}
markdownRemark(frontmatter: { templateKey: { eq: "footer" } }) {
frontmatter {
title
logo {
publicURL
}
links {
url
text
}
}
}
}
`);
返回的数据:
{
"title":"Some footer title",
"logo":{"publicURL":"/static/6731239d1e0c5fcdf0f825a8de82be10/logo.svg"},
"links":[
{"url":"../pages/prices","text":"Prices"},
{"url":"../pages/privacy-policy","text":"Privacy policy"}
]
}
您可以看到 links 数组中对象的 URL 已被转换为相对文件路径,而不是像在原始 markdown 文件中那样从 frontmatter 返回实际链接。
如何检索实际链接?
【问题讨论】:
标签: javascript reactjs graphql gatsby