This repository has been archived by the owner on Feb 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,035 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,147 @@ | ||
const path = require('path'); | ||
const path = require(`path`) | ||
|
||
exports.onCreateNode = ({node}) => { | ||
console.log(`onCreateNode:`, node.internal.type); | ||
exports.onCreateNode = ({ node }) => { | ||
console.log(`onCreateNode:`, node.internal.type) | ||
} | ||
|
||
exports.createPages = ({ boundActionCreators, graphql }) => { | ||
const { createPage } = boundActionCreators; | ||
const { createPage } = boundActionCreators | ||
|
||
return new Promise((resolve, reject) => { | ||
const artistDetailPageTemplate = path.resolve(`./src/templates/artist-detail.js`); | ||
resolve( | ||
graphql(` | ||
query getAllArtists { | ||
allArtists { | ||
edges { | ||
artist: node { | ||
id | ||
name | ||
slug | ||
picture { | ||
id | ||
handle | ||
width | ||
height | ||
} | ||
records { | ||
id | ||
slug | ||
title | ||
} | ||
} | ||
} | ||
return new Promise((resolve, reject) => { | ||
const artistDetailPageTemplate = path.resolve( | ||
`./src/templates/artist-detail.js` | ||
) | ||
const recordDetailPageTemplate = path.resolve( | ||
`./src/templates/record-detail.js` | ||
) | ||
const reviewDetailPageTemplate = path.resolve( | ||
`./src/templates/review-detail.js` | ||
) | ||
|
||
resolve( | ||
graphql(` | ||
{ | ||
allArtists { | ||
edges { | ||
artist: node { | ||
id | ||
name | ||
slug | ||
picture { | ||
id | ||
handle | ||
width | ||
height | ||
} | ||
records { | ||
id | ||
slug | ||
title | ||
} | ||
} | ||
} | ||
} | ||
allRecords { | ||
edges { | ||
record: node { | ||
id | ||
slug | ||
title | ||
artist { | ||
id | ||
slug | ||
name | ||
} | ||
tracks { | ||
id | ||
title | ||
aliasedLength | ||
} | ||
cover { | ||
handle | ||
} | ||
reviews { | ||
id | ||
slug | ||
title | ||
} | ||
} | ||
} | ||
} | ||
allReviews { | ||
edges { | ||
review: node { | ||
id | ||
slug | ||
createdAt | ||
record { | ||
slug | ||
title | ||
artist { | ||
slug | ||
name | ||
} | ||
} | ||
` | ||
).then(result => { | ||
if(result.errors) { | ||
reject(result.errors) | ||
title | ||
review | ||
rating | ||
comments { | ||
body | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`).then(result => { | ||
if (result.errors) { | ||
reject(result.errors) | ||
} | ||
|
||
const artists = result.data.allArtists.edges | ||
console.log(`artists: `, artists) | ||
artists.forEach(node => { | ||
console.log(`createPages node: `, node) | ||
const path = `artists/` + node.artist.slug | ||
console.log(`createPages path: `, path) | ||
createPage({ | ||
path, | ||
component: artistDetailPageTemplate, | ||
context: { | ||
slug: node.artist.slug, | ||
}, | ||
}) | ||
}) | ||
|
||
const artists = result.data.allArtists.edges; | ||
console.log("artists: ", artists); | ||
artists.forEach((node) => { | ||
console.log("createPages node: ", node); | ||
const path = "artists/" + node.artist.slug; | ||
console.log("createPages path: ", path); | ||
createPage({ | ||
path, | ||
component: artistDetailPageTemplate, | ||
// If you have a layout component at src/layouts/blog-layout.js | ||
//layout: `blog-layout`, | ||
// In your blog post template's graphql query, you can use path | ||
// as a GraphQL variable to query for data from the markdown file. | ||
context: { | ||
slug: node.artist.slug | ||
} | ||
}) | ||
}) | ||
}) | ||
); | ||
}); | ||
}; | ||
const records = result.data.allRecords.edges | ||
console.log(`records: `, records) | ||
records.forEach(node => { | ||
console.log(`createPages node: `, node) | ||
const path = `records/` + node.record.slug | ||
console.log(`createPages path: `, path) | ||
createPage({ | ||
path, | ||
component: recordDetailPageTemplate, | ||
context: { | ||
slug: node.record.slug, | ||
}, | ||
}) | ||
}) | ||
|
||
const reviews = result.data.allReviews.edges | ||
console.log(`reviews: `, reviews) | ||
reviews.forEach(node => { | ||
console.log(`createPages node: `, node) | ||
const path = `reviews/` + node.review.slug | ||
console.log(`createPages path: `, path) | ||
createPage({ | ||
path, | ||
component: reviewDetailPageTemplate, | ||
context: { | ||
slug: node.review.slug, | ||
}, | ||
}) | ||
}) | ||
}) | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.