Skip to content

Commit 1f74a94

Browse files
ltclmbdevjoelhooks
authored andcommitted
Styles for the Pagination (#7)
* set default value to node.frontmatter.banner * styles for pagination * yarn add gatsby-plugin-templated-files * yarn remove gatsby-plugin-t emplated-files * refactor Pagination * hack flexbox! * update package.json & yarn.lock
1 parent 9c964b6 commit 1f74a94

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

gatsby-node.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@ const createPaginatedPages = (createPage, edges, pathPrefix, context) => {
104104
}, [])
105105

106106
pages.forEach((page, index) => {
107-
const previousPagePath = `${pathPrefix}/${index + 1}`
108-
const nextPagePath = index === 1 ? pathPrefix : `${pathPrefix}/${index - 1}`
107+
const nextPagePath = `${pathPrefix}/${index + 1}`
108+
const previousPagePath =
109+
index === 1 ? pathPrefix : `${pathPrefix}/${index - 1}`
109110

110111
createPage({
111112
path: index > 0 ? `${pathPrefix}/${index}` : `${pathPrefix}`,
112113
component: path.resolve(`src/templates/blog.js`),
113114
context: {
114115
pagination: {
115116
page,
116-
nextPagePath: index === 0 ? null : nextPagePath,
117-
previousPagePath:
118-
index === pages.length - 1 ? null : previousPagePath,
117+
nextPagePath: index === pages.length - 1 ? null : nextPagePath,
118+
previousPagePath: index === 0 ? null : previousPagePath,
119119
pageCount: pages.length,
120120
pathPrefix,
121121
},
@@ -178,7 +178,7 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
178178
createNodeField({
179179
name: 'banner',
180180
node,
181-
banner: node.frontmatter.banner,
181+
banner: node.frontmatter.banner || {},
182182
})
183183

184184
createNodeField({

package.json

100644100755
File mode changed.

src/templates/blog.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,28 @@ const Blog = ({
115115
</Link>
116116
</div>
117117
))}
118-
<br />
119-
<br />
120-
<div>
118+
<div
119+
css={css({
120+
marginTop: '50px',
121+
display: 'flex',
122+
justifyContent: 'space-between',
123+
[bpMaxSM]: {
124+
marginTop: '30px',
125+
},
126+
})}
127+
>
128+
{previousPagePath ? (
129+
<Link to={previousPagePath} aria-label="View previous page">
130+
← Previous Page
131+
</Link>
132+
) : (
133+
<div />
134+
)}
121135
{nextPagePath && (
122136
<Link to={nextPagePath} aria-label="View next page">
123137
Next Page →
124138
</Link>
125139
)}
126-
{previousPagePath && (
127-
<Link to={previousPagePath} aria-label="View previous page">
128-
← Previous Page
129-
</Link>
130-
)}
131140
</div>
132141
<hr
133142
css={css`

yarn.lock

100644100755
File mode changed.

0 commit comments

Comments
 (0)