我正在使用我的第一个 Gatsby 模板(Panr 的 Hello Friend),我完全没有使用 React.js 的经验。
我试图了解模板设计的一些逻辑, gatsby-node.js
特别gatsby-config.js
是:
来自gatsby-config.js
:
{
resolve: `gatsby-source-filesystem`,
options: {
name: `posts`,
path: `${__dirname}/src/posts`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages`,
},
},
从gatsby-node.js
:
const sortedPages = markdownPages.sort((pageA, pageB) => {
const typeA = getType(pageA.node)
const typeB = getType(pageB.node)
return (typeA > typeB) - (typeA < typeB)
})
const posts = allNodes.filter(
({ internal, fileAbsolutePath }) =>
internal.type === 'MarkdownRemark' &&
fileAbsolutePath.indexOf('/posts/') !== -1,
)
// Create posts index with pagination
paginate({
createPage,
items: posts,
component: indexTemplate,
itemsPerPage: siteMetadata.postsPerPage,
pathPrefix: '/',
})
我是否正确地认为有两个内容类别:
1.pages
2.posts
并且帖子被枚举(分页)但页面不是?
排序pageA
和pageB
实现什么?
另外,我将如何添加其他内容类别?
注意:我意识到这是一个不适合 Stack Overflow 的模糊问题。我会在 Gatsby 特定论坛上问这个问题,但我不相信存在这个问题,这是Gatsby 社区页面中推荐的论坛。