我的博客将在每个帖子上显示作者的图片和姓名,并且要让模板加载正确的模板,我需要通过上下文传递一个值。问题是 $slug 已经是 gatsby-node 中 blogPage 函数的对象。
像这样的东西:
const path = require(`path`)
const _ = require("lodash")
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
const blogPostTemplate = path.resolve(`src/templates/blogPost.js`)
const autorPageTemplate = path.resolve(`src/templates/autorPage.js`)
const tagTemplate = path.resolve(`src/templates/tags.js`)
const catTemplate = path.resolve(`src/templates/categories.js`)
const result = await graphql(`
{
blogPost: allMarkdownRemark(
filter: {
frontmatter: {
type: {
eq: "blog-post"
}
}
},
sort: {
order: DESC,
fields: [
frontmatter___date
]
},
limit: 1000
) {
edges {
node {
fields {
slug
}
}
}
}
autorPage: allMarkdownRemark(
filter: {
frontmatter: {
type: {
eq: "autor"
}
}
}
) {
edges {
node {
frontmatter {
name
}
}
}
}
tagsGroup: allMarkdownRemark(limit: 2000) {
group(field: frontmatter___tags) {
fieldValue
}
}
categoriesGroup: allMarkdownRemark(limit: 2000) {
group(field: frontmatter___categories) {
fieldValue
}
}
}
`)
// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`)
return
}
慕的地10843
ABOUTYOU
相关分类