mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-10 12:57:46 +00:00
Fix author page pagination
This commit is contained in:
@@ -146,6 +146,7 @@ exports.createPages = ({ graphql, actions }) => {
|
|||||||
skipNumber: 0,
|
skipNumber: 0,
|
||||||
pageIndex: 1,
|
pageIndex: 1,
|
||||||
numberOfPages,
|
numberOfPages,
|
||||||
|
relativePath: ''
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -161,13 +162,16 @@ exports.createPages = ({ graphql, actions }) => {
|
|||||||
skipNumber,
|
skipNumber,
|
||||||
pageIndex: pageNum,
|
pageIndex: pageNum,
|
||||||
numberOfPages,
|
numberOfPages,
|
||||||
|
relativePath: ''
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
unicorns.forEach(unicorn => {
|
unicorns.forEach(unicorn => {
|
||||||
|
const uniId = unicorn.node.id
|
||||||
|
|
||||||
const uniPosts = posts.filter(({ node: { frontmatter } }) =>
|
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)
|
const numberOfUniPages = Math.ceil(uniPosts.length / postsPerPage)
|
||||||
@@ -176,27 +180,29 @@ exports.createPages = ({ graphql, actions }) => {
|
|||||||
path: `unicorns/${unicorn.node.id}`,
|
path: `unicorns/${unicorn.node.id}`,
|
||||||
component: blogProfile,
|
component: blogProfile,
|
||||||
context: {
|
context: {
|
||||||
slug: unicorn.node.id,
|
slug: uniId,
|
||||||
limitNumber: postsPerPage,
|
limitNumber: postsPerPage,
|
||||||
skipNumber: 0,
|
skipNumber: 0,
|
||||||
pageIndex: 1,
|
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
|
if (i === 0) continue
|
||||||
const pageNum = i + 1
|
const pageNum = i + 1
|
||||||
const skipNumber = postsPerPage * i
|
const skipNumber = postsPerPage * i
|
||||||
createPage({
|
createPage({
|
||||||
path: `unicorns/${unicorn.node.id}/page/${pageNum}`,
|
path: `unicorns/${uniId}/page/${pageNum}`,
|
||||||
component: blogProfile,
|
component: blogProfile,
|
||||||
context: {
|
context: {
|
||||||
slug: unicorn.node.id,
|
slug: uniId,
|
||||||
limitNumber: postsPerPage,
|
limitNumber: postsPerPage,
|
||||||
skipNumber,
|
skipNumber,
|
||||||
pageIndex: pageNum,
|
pageIndex: pageNum,
|
||||||
numberOfUniPages,
|
numberOfPages: numberOfUniPages,
|
||||||
|
relativePath: `unicorns/${uniId}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const PostListLayout = ({ children, posts, pageContext, ...postListProps
|
|||||||
pageIndex: originalPageIndexPlusOne,
|
pageIndex: originalPageIndexPlusOne,
|
||||||
numberOfPages,
|
numberOfPages,
|
||||||
limitNumber,
|
limitNumber,
|
||||||
|
relativePath
|
||||||
} = pageContext
|
} = pageContext
|
||||||
/**
|
/**
|
||||||
* In order to get around limitations with GQL query calls, we originally
|
* 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}
|
marginPagesDisplayed={2}
|
||||||
forcePage={forcePage}
|
forcePage={forcePage}
|
||||||
pageRangeDisplayed={5}
|
pageRangeDisplayed={5}
|
||||||
hrefBuilder={props => `/page/${props}`}
|
hrefBuilder={props => `${relativePath}/page/${props}`}
|
||||||
containerClassName={"pagination"}
|
containerClassName={"pagination"}
|
||||||
subContainerClassName={"pages pagination"}
|
subContainerClassName={"pages pagination"}
|
||||||
activeClassName={"active"}
|
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
|
// Even though we index at 1 for pages, this component indexes at 0
|
||||||
const newPageIndex = selected + 1
|
const newPageIndex = selected + 1
|
||||||
if (newPageIndex === 1) {
|
if (newPageIndex === 1) {
|
||||||
navigate("/")
|
navigate(`${relativePath}/`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
navigate(`/page/${newPageIndex}`)
|
navigate(`${relativePath}/page/${newPageIndex}`)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SearchAndFilterContext.Provider>
|
</SearchAndFilterContext.Provider>
|
||||||
|
|||||||
Reference in New Issue
Block a user