mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-10 04:22:06 +00:00
Fix author page pagination
This commit is contained in:
@@ -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}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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}`)
|
||||
}}
|
||||
/>
|
||||
</SearchAndFilterContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user