I'm hoping that someone has run into something similar and can give me some advice in the right direction.
I'm building out a blog using gatsby with content pulled from Prismic. Each blog post has an author and tag related to them via Prismic Content Relationship. My goal is to dynamically create pages via gatsby-node for the author and tag pages that also include pagination for their related blog posts. Prismic unfortunately doesn't seem to create a relationship going both ways, so I have to find related blog posts by doing a graphql query on my allPrismicBlog filtering for author uid.
example of the urls i'm trying to accomplish: myblog.com/author/author-name/ myblog.com/author/author-name/2
I have the following in my gatsby-node:
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const authors = await graphql(`
{
allPrismicAuthor {
edges {
node {
uid
}
}
}
}
`);
authors.data.allPrismicAuthor.edges.forEach(edge => {
const authorUid = edge.node.uid;
const authorPosts = graphql(`
{
allPrismicBlog(filter: { data: { author: { uid: { eq: ${authorUid} } } } }) {
edges {
node {
uid
}
}
}
`);
const numAuthorPages = Math.ceil(authorPosts.length / 2);
Array.from({ length: numAuthorPages }).forEach((_, i) =>
createPage({
path: i === 0 ? `/author/${authorUid}` : `/author/${authorUid}/${i + 1}`,
component: path.resolve('./src/templates/author.jsx'),
context: {
limit: 2,
skip: i * 2,
numPages,
currentPage: i + 1,
uid: authorUid,
},
}),
);
});
};
I'm getting the error TypeError: Cannot read property 'page' of undefined
I'm not sure if what I'm trying to do here is the right direction or if I'm missing something important. Any help would be greatly appreciated.