我想知道在gatsby静态网站中是否可以有多个帖子类型。
在gatsby-config.js上,我有以下代码。
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/books`,
name: `books`,
}
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/content/posts`,
name: `posts`,
}
Run Code Online (Sandbox Code Playgroud)
这两个文件夹都具有相关的markdown文件,我找不到graphql的任何示例来检索这两个文件。
提前致谢。
小智 5
另请参阅 本(1) 和 本(2)问题/评论,它们使事情变得清晰:
1。
回顾过去,将该字段添加到gatsby-transformer-remark中是错误的,将来会被删除
2。
使用正则表达式也是一个很好的解决方案,例如,我们在gatsbyjs.org上使用了很多。
示例:因此,这是仅获取帖子的方法:
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date]},
filter: {fileAbsolutePath: {regex: "/(\/content\/posts)/.*\\.md$/"}}
) {
edges {
node {
excerpt(pruneLength: 250)
id
frontmatter {
title
date(formatString: "MMMM DD, YYYY")
path
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2388 次 |
| 最近记录: |