Skip to content

Commit

Permalink
[www] Fix header background for paginated "Blog" pages (#8042)
Browse files Browse the repository at this point in the history
* Move paginated blog pages from e.g. `/blog/2` to `/blog/page/2`

and fix header background for those pages.

* Fix navigating to page 1 (`/blog/`)

Thanks @pieh, @NickyMeuleman and @DSchau! 🙏
  • Loading branch information
fk committed Sep 14, 2018
1 parent a672a60 commit dfeea37
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ exports.createPages = ({ graphql, actions }) => {

Array.from({ length: numPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/blog` : `/blog/${i + 1}`,
path: i === 0 ? `/blog` : `/blog/page/${i + 1}`,
component: slash(blogListTemplate),
context: {
limit: postsPerPage,
Expand Down
2 changes: 1 addition & 1 deletion www/src/components/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const NavItem = ({ linkTo, children }) => (

const Navigation = ({ pathname }) => {
const isHomepage = pathname === `/`
const isBlog = pathname === `/blog/`
const isBlog = pathname === `/blog/` || pathname.indexOf(`/blog/page/`) === 0

const socialIconsStyles = {
...styles.navItem,
Expand Down
6 changes: 3 additions & 3 deletions www/src/components/pagination/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import { options, rhythm } from "../../utils/typography"

class Pagination extends React.Component {
changePage = e => {
navigate(`/blog/${e.target.value}`)
navigate(e.target.value ? `/blog/page/${e.target.value}` : `/blog/`)
}
render() {
const { numPages, currentPage } = this.props.context
const isFirst = currentPage === 1
const isLast = currentPage === numPages
const prevPageNum =
currentPage - 1 === 1 ? `` : (currentPage - 1).toString()
currentPage - 1 === 1 ? `` : `page/${(currentPage - 1).toString()}`
const nextPageNum = (currentPage + 1).toString()
const prevPageLink = isFirst ? null : `/blog/${prevPageNum}`
const nextPageLink = isLast ? null : `/blog/${nextPageNum}`
const nextPageLink = isLast ? null : `/blog/page/${nextPageNum}`

const prevNextLinkStyles = {
"&&": {
Expand Down

0 comments on commit dfeea37

Please sign in to comment.