【发布时间】:2021-07-25 13:57:15
【问题描述】:
我尝试了各种我能想到的格式:
const { projects, blogs }, const { data } 然后通过 data.projects 调用它...
有人能指出我的代码中的错误吗?
错误为 Syntax Error: Expected Name, found ":"。
{
projects: allMarkdownRemark(
filter: { frontmatter: { type: { eq: "project" } } }
谢谢
完整代码:
const path = require("path")
exports.createPages = async ({ graphql, actions }) => {
const result = await graphql(`
{
projects: allMarkdownRemark(
filter: { frontmatter: { type: { eq: "project" } } }
) {
nodes {
frontmatter {
slug
}
}
}
blogs: projects: allMarkdownRemark(
filter: { frontmatter: { type: { eq: "blog" } } }
) {
nodes {
frontmatter {
slug
}
}
}
}
`)
result.data.projects.allMarkdownRemark.nodes.forEach(node => {
actions.createPage({
path: "/projects/" + node.frontmatter.slug,
component: path.resolve("./src/templates/project-details.js"),
context: { slug: node.frontmatter.slug },
})
})
result.data.blogs.allMarkdownRemark.nodes.forEach(node => {
actions.createPage({
path: "/blogs/" + node.frontmatter.slug,
component: path.resolve("./src/templates/blog-details.js"),
context: { slug: node.frontmatter.slug },
})
})
}
【问题讨论】:
标签: node.js reactjs graphql gatsby