diff --git a/gatsby-node.js b/gatsby-node.js index a3dfe93c..2630000b 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -146,6 +146,7 @@ exports.createPages = ({ graphql, actions }) => { skipNumber: 0, pageIndex: 1, numberOfPages, + relativePath: '' }, }) @@ -161,13 +162,16 @@ exports.createPages = ({ graphql, actions }) => { skipNumber, pageIndex: pageNum, numberOfPages, + relativePath: '' }, }) } unicorns.forEach(unicorn => { + const uniId = unicorn.node.id + const uniPosts = posts.filter(({ node: { frontmatter } }) => - frontmatter.authors.find(uni => uni.id === unicorn.node.id) + frontmatter.authors.find(uni => uni.id === uniId) ) const numberOfUniPages = Math.ceil(uniPosts.length / postsPerPage) @@ -176,27 +180,29 @@ exports.createPages = ({ graphql, actions }) => { path: `unicorns/${unicorn.node.id}`, component: blogProfile, context: { - slug: unicorn.node.id, + slug: uniId, limitNumber: postsPerPage, skipNumber: 0, pageIndex: 1, - numberOfUniPages, + numberOfPages: numberOfUniPages, + relativePath: `unicorns/${uniId}`, }, }) - for (const i of Array(numberOfPages).keys()) { + for (const i of Array(numberOfUniPages).keys()) { if (i === 0) continue const pageNum = i + 1 const skipNumber = postsPerPage * i createPage({ - path: `unicorns/${unicorn.node.id}/page/${pageNum}`, + path: `unicorns/${uniId}/page/${pageNum}`, component: blogProfile, context: { - slug: unicorn.node.id, + slug: uniId, limitNumber: postsPerPage, skipNumber, pageIndex: pageNum, - numberOfUniPages, + numberOfPages: numberOfUniPages, + relativePath: `unicorns/${uniId}`, }, }) } diff --git a/src/components/post-list-layout/post-list-layout.js b/src/components/post-list-layout/post-list-layout.js index 69ce06e2..fb5a1e1b 100644 --- a/src/components/post-list-layout/post-list-layout.js +++ b/src/components/post-list-layout/post-list-layout.js @@ -20,6 +20,7 @@ export const PostListLayout = ({ children, posts, pageContext, ...postListProps pageIndex: originalPageIndexPlusOne, numberOfPages, limitNumber, + relativePath } = pageContext /** * In order to get around limitations with GQL query calls, we originally @@ -134,7 +135,7 @@ export const PostListLayout = ({ children, posts, pageContext, ...postListProps marginPagesDisplayed={2} forcePage={forcePage} pageRangeDisplayed={5} - hrefBuilder={props => `/page/${props}`} + hrefBuilder={props => `${relativePath}/page/${props}`} containerClassName={"pagination"} subContainerClassName={"pages pagination"} activeClassName={"active"} @@ -147,10 +148,10 @@ export const PostListLayout = ({ children, posts, pageContext, ...postListProps // Even though we index at 1 for pages, this component indexes at 0 const newPageIndex = selected + 1 if (newPageIndex === 1) { - navigate("/") + navigate(`${relativePath}/`) return } - navigate(`/page/${newPageIndex}`) + navigate(`${relativePath}/page/${newPageIndex}`) }} />