Skip to content

Commit ad7febe

Browse files
committed
use nodes and not edges
1 parent 4025104 commit ad7febe

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

starters/blog/gatsby-node.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
1515
sort: { fields: [frontmatter___date], order: ASC }
1616
limit: 1000
1717
) {
18-
edges {
19-
previous {
20-
id
21-
}
22-
next {
23-
id
24-
}
25-
node {
26-
id
27-
fields {
28-
slug
29-
}
18+
nodes {
19+
id
20+
fields {
21+
slug
3022
}
3123
}
3224
}
@@ -42,21 +34,25 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
4234
return
4335
}
4436

45-
const posts = result.data.allMarkdownRemark.edges
37+
const posts = result.data.allMarkdownRemark.nodes
38+
console.log({ posts })
4639

4740
// Create blog posts pages
4841
// But only if there's at least one markdown file found at "content/blog" (defined in gatsby-config.js)
4942
// `context` is available in the template as a prop and as a variable in GraphQL
5043

5144
if (posts.length > 0) {
52-
posts.forEach(post => {
45+
posts.forEach((post, index) => {
46+
const previousPostId = index === 0 ? null : posts[index - 1].id
47+
const nextPostId = index === posts.length - 1 ? null : posts[index + 1].id
48+
5349
createPage({
54-
path: post.node.fields.slug,
50+
path: post.fields.slug,
5551
component: blogPost,
5652
context: {
57-
id: post.node.id,
58-
previous: post.previous ? post.previous.id : undefined,
59-
next: post.next ? post.next.id : undefined,
53+
id: post.id,
54+
previousPostId,
55+
nextPostId,
6056
},
6157
})
6258
})

starters/blog/src/templates/blog-post.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ const BlogPostTemplate = ({ data, location }) => {
6767
export default BlogPostTemplate
6868

6969
export const pageQuery = graphql`
70-
query BlogPostBySlug($id: String!, $next: String, $previous: String) {
70+
query BlogPostBySlug(
71+
$id: String!
72+
$previousPostId: String
73+
$nextPostId: String
74+
) {
7175
site {
7276
siteMetadata {
7377
title
@@ -83,15 +87,15 @@ export const pageQuery = graphql`
8387
description
8488
}
8589
}
86-
previous: markdownRemark(id: { eq: $previous }) {
90+
previous: markdownRemark(id: { eq: $previousPostId }) {
8791
fields {
8892
slug
8993
}
9094
frontmatter {
9195
title
9296
}
9397
}
94-
next: markdownRemark(id: { eq: $next }) {
98+
next: markdownRemark(id: { eq: $nextPostId }) {
9599
fields {
96100
slug
97101
}

0 commit comments

Comments
 (0)