From aacda70eb403006fda057c02c710defe0e3a2116 Mon Sep 17 00:00:00 2001 From: Ricky de Laveaga Date: Tue, 27 Feb 2018 16:37:01 -0800 Subject: [PATCH 1/5] Select by ID instead of path Closes #47 See for background https://github.com/rdela/voidcluster/commit/5bc432b71db4882ff301bad35ab0f80a801adeea#commitcomment-27821888 https://github.com/rdela/voidcluster/commit/5bc432b71db4882ff301bad35ab0f80a801adeea#commitcomment-27821874 + links in #47 thanks @KyleAMathews --- gatsby-config.js | 2 +- gatsby-node.js | 14 +++++++----- package.json | 2 +- src/cms/preview-templates/AboutPagePreview.js | 13 ++++++----- src/cms/preview-templates/BlogPostPreview.js | 8 +++---- .../preview-templates/ProductPagePreview.js | 22 +++++++++---------- src/templates/about-page.js | 4 ++-- src/templates/blog-post.js | 5 +++-- src/templates/product-page.js | 4 ++-- 9 files changed, 41 insertions(+), 33 deletions(-) diff --git a/gatsby-config.js b/gatsby-config.js index b5d4410..3959e81 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -34,4 +34,4 @@ module.exports = { }, }, ], -}; +} diff --git a/gatsby-node.js b/gatsby-node.js index bd04f3b..b68066c 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,4 +1,4 @@ -const path = require("path") +const path = require('path') exports.createPages = ({ boundActionCreators, graphql }) => { const { createPage } = boundActionCreators @@ -8,6 +8,7 @@ exports.createPages = ({ boundActionCreators, graphql }) => { allMarkdownRemark(limit: 1000) { edges { node { + id frontmatter { path templateKey @@ -22,15 +23,18 @@ exports.createPages = ({ boundActionCreators, graphql }) => { return Promise.reject(result.errors) } - return result.data.allMarkdownRemark.edges.forEach(({ node }) => { - const pagePath = node.frontmatter.path + result.data.allMarkdownRemark.edges.forEach(edge => { + const id = edge.node.id + const pagePath = edge.node.frontmatter.path createPage({ path: pagePath, component: path.resolve( - `src/templates/${String(node.frontmatter.templateKey)}.js` + `src/templates/${String(edge.node.frontmatter.templateKey)}.js` ), // additional data can be passed via context - context: {}, + context: { + id, + }, }) }) }) diff --git a/package.json b/package.json index 6296077..92fa01b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "build": "gatsby build", "develop": "gatsby develop", "serve": "gatsby serve", - "format": "prettier --trailing-comma es5 --no-semi --single-quote --write src/**/*.js", + "format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"{gatsby-*.js,src/**/*.js}\"", "test": "echo \"Error: no test specified\" && exit 1" }, "devDependencies": { diff --git a/src/cms/preview-templates/AboutPagePreview.js b/src/cms/preview-templates/AboutPagePreview.js index a8dfee7..71b9d32 100644 --- a/src/cms/preview-templates/AboutPagePreview.js +++ b/src/cms/preview-templates/AboutPagePreview.js @@ -1,8 +1,11 @@ -import React from 'react'; -import { AboutPageTemplate } from '../../templates/about-page'; +import React from 'react' +import { AboutPageTemplate } from '../../templates/about-page' const AboutPagePreview = ({ entry, widgetFor }) => ( - -); + +) -export default AboutPagePreview; +export default AboutPagePreview diff --git a/src/cms/preview-templates/BlogPostPreview.js b/src/cms/preview-templates/BlogPostPreview.js index f481e28..f3be58b 100644 --- a/src/cms/preview-templates/BlogPostPreview.js +++ b/src/cms/preview-templates/BlogPostPreview.js @@ -1,5 +1,5 @@ -import React from 'react'; -import { BlogPostTemplate } from '../../templates/blog-post'; +import React from 'react' +import { BlogPostTemplate } from '../../templates/blog-post' const BlogPostPreview = ({ entry, widgetFor }) => ( ( description={entry.getIn(['data', 'description'])} title={entry.getIn(['data', 'title'])} /> -); +) -export default BlogPostPreview; +export default BlogPostPreview diff --git a/src/cms/preview-templates/ProductPagePreview.js b/src/cms/preview-templates/ProductPagePreview.js index 78af965..0173650 100644 --- a/src/cms/preview-templates/ProductPagePreview.js +++ b/src/cms/preview-templates/ProductPagePreview.js @@ -1,15 +1,15 @@ -import React from 'react'; -import { ProductPageTemplate } from '../../templates/product-page'; +import React from 'react' +import { ProductPageTemplate } from '../../templates/product-page' const ProductPagePreview = ({ entry, getAsset }) => { - const entryBlurbs = entry.getIn(['data', 'intro', 'blurbs']); - const blurbs = entryBlurbs ? entryBlurbs.toJS() : []; + const entryBlurbs = entry.getIn(['data', 'intro', 'blurbs']) + const blurbs = entryBlurbs ? entryBlurbs.toJS() : [] - const entryTestimonials = entry.getIn(['data', 'testimonials']); - const testimonials = entryTestimonials ? entryTestimonials.toJS() : []; + const entryTestimonials = entry.getIn(['data', 'testimonials']) + const testimonials = entryTestimonials ? entryTestimonials.toJS() : [] - const entryPricingPlans = entry.getIn(['data', 'pricing', 'plans']); - const pricingPlans = entryPricingPlans ? entryPricingPlans.toJS() : []; + const entryPricingPlans = entry.getIn(['data', 'pricing', 'plans']) + const pricingPlans = entryPricingPlans ? entryPricingPlans.toJS() : [] return ( { plans: pricingPlans, }} /> - ); -}; + ) +} -export default ProductPagePreview; +export default ProductPagePreview diff --git a/src/templates/about-page.js b/src/templates/about-page.js index e13208d..b8ad80c 100644 --- a/src/templates/about-page.js +++ b/src/templates/about-page.js @@ -35,8 +35,8 @@ export default ({ data }) => { } export const aboutPageQuery = graphql` - query AboutPage($path: String!) { - markdownRemark(frontmatter: { path: { eq: $path } }) { + query AboutPage($id: String!) { + markdownRemark(id: { eq: $id }) { html frontmatter { path diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index 456824e..65f4770 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -44,8 +44,9 @@ export default props => { } export const pageQuery = graphql` - query BlogPostByPath($path: String!) { - markdownRemark(frontmatter: { path: { eq: $path } }) { + query BlogPostByPath($id: String!) { + markdownRemark(id: { eq: $id }) { + id html frontmatter { path diff --git a/src/templates/product-page.js b/src/templates/product-page.js index 186c7e8..46d5c86 100644 --- a/src/templates/product-page.js +++ b/src/templates/product-page.js @@ -123,8 +123,8 @@ export default ({ data }) => { } export const productPageQuery = graphql` - query ProductPage($path: String!) { - markdownRemark(frontmatter: { path: { eq: $path } }) { + query ProductPage($id: String!) { + markdownRemark(id: { eq: $id }) { frontmatter { title path From 6dd7ca3fadf8da9f084dfea244553791d4e6af1e Mon Sep 17 00:00:00 2001 From: Ricky de Laveaga Date: Tue, 27 Feb 2018 17:13:57 -0800 Subject: [PATCH 2/5] rename query and make arbitrary change to all.sass for testing --- src/layouts/all.sass | 2 +- src/templates/blog-post.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layouts/all.sass b/src/layouts/all.sass index 878ce97..32e9e81 100644 --- a/src/layouts/all.sass +++ b/src/layouts/all.sass @@ -1,6 +1,6 @@ @import "~bulma/sass/utilities/initial-variables" -// Config +// Config vars $kaldi-red: #FD461E $kaldi-red-invert: #fff diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index 65f4770..bdf3405 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -44,7 +44,7 @@ export default props => { } export const pageQuery = graphql` - query BlogPostByPath($id: String!) { + query BlogPostByID($id: String!) { markdownRemark(id: { eq: $id }) { id html From 376bd10e2cee6918a11a1d8558ffea6e05a9d989 Mon Sep 17 00:00:00 2001 From: Austin Green Date: Tue, 27 Feb 2018 20:42:59 -0500 Subject: [PATCH 3/5] remove path from frontmatter and restructure directories --- gatsby-node.js | 21 ++++++++++++++++--- ...ing-sense-of-the-scaas-new-flavor-wheel.md | 1 - ...-beginners-guide-to-brewing-with-chemex.md | 1 - ...maican-blue-mountain-in-store-next-week.md | 1 - src/pages/{about => }/about.md | 0 src/pages/index.js | 8 ++++--- src/pages/{product/product.md => products.md} | 0 src/templates/about-page.js | 1 - src/templates/blog-post.js | 1 - src/templates/product-page.js | 1 - 10 files changed, 23 insertions(+), 12 deletions(-) rename src/pages/{blog => }/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md (99%) rename src/pages/{blog => }/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md (99%) rename src/pages/{blog => }/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md (99%) rename src/pages/{about => }/about.md (100%) rename src/pages/{product/product.md => products.md} (100%) diff --git a/gatsby-node.js b/gatsby-node.js index b68066c..7688abe 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,4 +1,5 @@ const path = require('path') +const { createFilePath } = require('gatsby-source-filesystem') exports.createPages = ({ boundActionCreators, graphql }) => { const { createPage } = boundActionCreators @@ -9,8 +10,10 @@ exports.createPages = ({ boundActionCreators, graphql }) => { edges { node { id + fields { + slug + } frontmatter { - path templateKey } } @@ -25,9 +28,8 @@ exports.createPages = ({ boundActionCreators, graphql }) => { result.data.allMarkdownRemark.edges.forEach(edge => { const id = edge.node.id - const pagePath = edge.node.frontmatter.path createPage({ - path: pagePath, + path: edge.node.fields.slug, component: path.resolve( `src/templates/${String(edge.node.frontmatter.templateKey)}.js` ), @@ -39,3 +41,16 @@ exports.createPages = ({ boundActionCreators, graphql }) => { }) }) } + +exports.onCreateNode = ({ node, boundActionCreators, getNode }) => { + const { createNodeField } = boundActionCreators + + if (node.internal.type === `MarkdownRemark`) { + const value = createFilePath({ node, getNode }) + createNodeField({ + name: `slug`, + node, + value, + }) + } +} diff --git a/src/pages/blog/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md b/src/pages/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md similarity index 99% rename from src/pages/blog/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md rename to src/pages/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md index c43ebc6..5d3036a 100644 --- a/src/pages/blog/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md +++ b/src/pages/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md @@ -1,6 +1,5 @@ --- templateKey: blog-post -path: /making-sense title: Making sense of the SCAA’s new Flavor Wheel date: 2016-12-17T15:04:10.000Z description: The Coffee Taster’s Flavor Wheel, the official resource used by coffee tasters, has been revised for the first time this year. diff --git a/src/pages/blog/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md b/src/pages/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md similarity index 99% rename from src/pages/blog/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md rename to src/pages/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md index 1c87563..8889c48 100644 --- a/src/pages/blog/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md +++ b/src/pages/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md @@ -1,6 +1,5 @@ --- templateKey: blog-post -path: /brewing-chemex title: A beginners’ guide to brewing with Chemex date: 2017-01-04T15:04:10.000Z description: Brewing with a Chemex probably seems like a complicated, time-consuming ordeal, but once you get used to the process, it becomes a soothing ritual that's worth the effort every time. diff --git a/src/pages/blog/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md b/src/pages/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md similarity index 99% rename from src/pages/blog/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md rename to src/pages/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md index 6a38da8..9007f16 100644 --- a/src/pages/blog/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md +++ b/src/pages/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md @@ -1,6 +1,5 @@ --- templateKey: 'blog-post' -path: /jamaica-blue title: 'Just in: small batch of Jamaican Blue Mountain in store next week' date: 2017-01-04T15:04:10.000Z description: >- diff --git a/src/pages/about/about.md b/src/pages/about.md similarity index 100% rename from src/pages/about/about.md rename to src/pages/about.md diff --git a/src/pages/index.js b/src/pages/index.js index 827423e..f519327 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -21,7 +21,7 @@ export default class IndexPage extends React.Component { key={post.id} >

- + {post.frontmatter.title} @@ -31,7 +31,7 @@ export default class IndexPage extends React.Component { {post.excerpt}

- + Keep Reading →

@@ -50,11 +50,13 @@ export const pageQuery = graphql` node { excerpt(pruneLength: 400) id + fields { + slug + } frontmatter { title templateKey date(formatString: "MMMM DD, YYYY") - path } } } diff --git a/src/pages/product/product.md b/src/pages/products.md similarity index 100% rename from src/pages/product/product.md rename to src/pages/products.md diff --git a/src/templates/about-page.js b/src/templates/about-page.js index b8ad80c..b36f822 100644 --- a/src/templates/about-page.js +++ b/src/templates/about-page.js @@ -39,7 +39,6 @@ export const aboutPageQuery = graphql` markdownRemark(id: { eq: $id }) { html frontmatter { - path title } } diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index bdf3405..f90af05 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -49,7 +49,6 @@ export const pageQuery = graphql` id html frontmatter { - path date(formatString: "MMMM DD, YYYY") title description diff --git a/src/templates/product-page.js b/src/templates/product-page.js index 46d5c86..3e5ac9d 100644 --- a/src/templates/product-page.js +++ b/src/templates/product-page.js @@ -127,7 +127,6 @@ export const productPageQuery = graphql` markdownRemark(id: { eq: $id }) { frontmatter { title - path image heading description From 6a210e58ff5d6334253e6944f604caa14c460bbd Mon Sep 17 00:00:00 2001 From: Austin Green Date: Tue, 27 Feb 2018 21:04:30 -0500 Subject: [PATCH 4/5] update directory structure --- src/pages/{about.md => about/index.md} | 0 .../2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md | 0 .../2017-01-04-a-beginners-guide-to-brewing-with-chemex.md | 0 ...in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md | 0 src/pages/{products.md => products/index.md} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename src/pages/{about.md => about/index.md} (100%) rename src/pages/{ => blog}/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md (100%) rename src/pages/{ => blog}/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md (100%) rename src/pages/{ => blog}/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md (100%) rename src/pages/{products.md => products/index.md} (100%) diff --git a/src/pages/about.md b/src/pages/about/index.md similarity index 100% rename from src/pages/about.md rename to src/pages/about/index.md diff --git a/src/pages/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md b/src/pages/blog/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md similarity index 100% rename from src/pages/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md rename to src/pages/blog/2016-12-17-making-sense-of-the-scaas-new-flavor-wheel.md diff --git a/src/pages/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md b/src/pages/blog/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md similarity index 100% rename from src/pages/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md rename to src/pages/blog/2017-01-04-a-beginners-guide-to-brewing-with-chemex.md diff --git a/src/pages/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md b/src/pages/blog/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md similarity index 100% rename from src/pages/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md rename to src/pages/blog/2017-01-04-just-in-small-batch-of-jamaican-blue-mountain-in-store-next-week.md diff --git a/src/pages/products.md b/src/pages/products/index.md similarity index 100% rename from src/pages/products.md rename to src/pages/products/index.md From d925464f03c679dfabd8f6dddceb8b8d1a76f06c Mon Sep 17 00:00:00 2001 From: Austin Green Date: Tue, 27 Feb 2018 21:21:54 -0500 Subject: [PATCH 5/5] remove the path fields from the CMS config.yml --- static/admin/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/static/admin/config.yml b/static/admin/config.yml index 27262f7..67b8bda 100644 --- a/static/admin/config.yml +++ b/static/admin/config.yml @@ -13,7 +13,6 @@ collections: slug: "{{year}}-{{month}}-{{day}}-{{slug}}" fields: - {label: "Template Key", name: "templateKey", widget: "hidden", default: "blog-post"} - - {label: "Path", name: "path", widget: "string"} - {label: "Title", name: "title", widget: "string"} - {label: "Publish Date", name: "date", widget: "datetime"} - {label: "Description", name: "description", widget: "text"} @@ -27,7 +26,6 @@ collections: name: "about" fields: - {label: "Template Key", name: "templateKey", widget: "hidden", default: "about-page"} - - {label: "Path", name: "path", widget: "hidden", default: "/about"} - {label: "Title", name: "title", widget: "string"} - {label: "Body", name: "body", widget: "markdown"} - file: "src/pages/product/product.md" @@ -35,7 +33,6 @@ collections: name: "products" fields: - {label: "Template Key", name: "templateKey", widget: "hidden", default: "product-page"} - - {label: "Path", name: "path", widget: "hidden", default: "/products"} - {label: Title, name: title, widget: string} - {label: Image, name: image, widget: image} - {label: Heading, name: heading, widget: string}