Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Commit

Permalink
record review refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rdela committed Feb 22, 2018
1 parent 2899897 commit b5d0781
Show file tree
Hide file tree
Showing 14 changed files with 1,035 additions and 444 deletions.
12 changes: 6 additions & 6 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ module.exports = {
{
resolve: `gatsby-plugin-manifest`,
options: {
name: 'Gatsby with GraphCMS',
short_name: 'Gatsby GCMS',
start_url: '/',
background_color: '#fff',
theme_color: '#61045f',
display: 'minimal-ui',
name: `Gatsby with GraphCMS`,
short_name: `Gatsby GCMS`,
start_url: `/`,
background_color: `#fff`,
theme_color: `#61045f`,
display: `minimal-ui`,
icons: [
{
src: `/favicons/chrome-192.png`,
Expand Down
192 changes: 138 additions & 54 deletions gatsby-node.js
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,
},
})
})
})
)
})
}
46 changes: 21 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
"version": "1.0.0",
"name": "gatsby-graphcms-example",
"description": "Gatsby example site using the GraphCMS source plugin",
"keywords": [
"data",
"example",
"gatsby",
"graphcms",
"graphql",
"source"
],
"keywords": ["data", "example", "gatsby", "graphcms", "graphql", "source"],
"homepage": "https://github.com/GraphCMS/gatsby-graphcms-example",
"repository": {
"type": "git",
Expand All @@ -18,34 +11,37 @@
"license": "MIT",
"author": "Rafael Cordones <rafael@cordones.me>",
"dependencies": {
"gatsby": "1.9.128",
"gatsby-link": "1.6.30",
"gatsby-plugin-manifest": "1.0.9",
"gatsby-plugin-offline": "1.0.11",
"gatsby-plugin-react-helmet": "2.0.2",
"gatsby": "1.9.206",
"gatsby-link": "1.6.37",
"gatsby-plugin-manifest": "1.0.14",
"gatsby-plugin-offline": "1.0.14",
"gatsby-plugin-react-helmet": "2.0.5",
"gatsby-source-graphcms": "0.0.1",
"react-helmet": "5.2.0",
"react-markdown": "3.1.0",
"react-markdown": "3.2.1",
"react-star-rating-component": "1.3.0"
},
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --trailing-comma es5 --no-semi --single-quote --write 'src/**/*.js'",
"format":
"prettier-eslint --write \"src/**/*.js\" \"gatsby-node.js\" \"gatsby-config.js\"",
"lint": "npm run format",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prettier": "1.9.1"
"prettier": "1.10.2"
},
"renovate": {
"extends": [
"config:base"
],
"labels": [
"renovate"
],
"assignees": [
"rdela"
]
"extends": ["config:base"],
"labels": ["renovate"],
"assignees": ["rdela"],
"devDependencies": {
"schedule": ["on the first day of the month"],
"automerge": true,
"major": {
"automerge": false
}
}
}
}
Loading

0 comments on commit b5d0781

Please sign in to comment.