@@ -7,7 +7,7 @@ const slash = require(`slash`)
7
7
// called after the Gatsby bootstrap is finished so you have
8
8
// access to any information necessary to programmatically
9
9
// create pages.
10
- exports . createPages = ( { graphql, actions } ) => {
10
+ exports . createPages = async ( { graphql, actions } ) => {
11
11
const { createPage } = actions
12
12
13
13
// The “graphql” function allows us to run arbitrary
@@ -20,7 +20,7 @@ exports.createPages = ({ graphql, actions }) => {
20
20
// is a "connection" (a GraphQL convention for accessing
21
21
// a list of nodes) gives us an easy way to query all
22
22
// Post nodes.
23
- return graphql (
23
+ const result = await graphql (
24
24
`
25
25
{
26
26
allPostsJson(limit: 1000) {
@@ -32,32 +32,32 @@ exports.createPages = ({ graphql, actions }) => {
32
32
}
33
33
}
34
34
`
35
- ) . then ( result => {
36
- if ( result . errors ) {
37
- throw result . errors
38
- }
35
+ )
39
36
40
- // Create image post pages.
41
- const postTemplate = path . resolve ( `src/templates/post-page.js` )
42
- // We want to create a detailed page for each
43
- // Instagram post. Since the scraped Instagram data
44
- // already includes an ID field, we just use that for
45
- // each page's path.
46
- _ . each ( result . data . allPostsJson . edges , edge => {
47
- // Gatsby uses Redux to manage its internal state.
48
- // Plugins and sites can use functions like "createPage"
49
- // to interact with Gatsby.
50
- createPage ( {
51
- // Each page is required to have a `path` as well
52
- // as a template component. The `context` is
53
- // optional but is often necessary so the template
54
- // can query data specific to each page.
55
- path : `/${ slug ( edge . node . id ) } /` ,
56
- component : slash ( postTemplate ) ,
57
- context : {
58
- id : edge . node . id ,
59
- } ,
60
- } )
37
+ if ( result . errors ) {
38
+ throw new Error ( result . errors )
39
+ }
40
+
41
+ // Create image post pages.
42
+ const postTemplate = path . resolve ( `src/templates/post-page.js` )
43
+ // We want to create a detailed page for each
44
+ // Instagram post. Since the scraped Instagram data
45
+ // already includes an ID field, we just use that for
46
+ // each page's path.
47
+ _ . each ( result . data . allPostsJson . edges , edge => {
48
+ // Gatsby uses Redux to manage its internal state.
49
+ // Plugins and sites can use functions like "createPage"
50
+ // to interact with Gatsby.
51
+ createPage ( {
52
+ // Each page is required to have a `path` as well
53
+ // as a template component. The `context` is
54
+ // optional but is often necessary so the template
55
+ // can query data specific to each page.
56
+ path : `/${ slug ( edge . node . id ) } /` ,
57
+ component : slash ( postTemplate ) ,
58
+ context : {
59
+ id : edge . node . id ,
60
+ } ,
61
61
} )
62
62
} )
63
63
}
0 commit comments