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..7688abe 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,4 +1,5 @@ -const path = require("path") +const path = require('path') +const { createFilePath } = require('gatsby-source-filesystem') exports.createPages = ({ boundActionCreators, graphql }) => { const { createPage } = boundActionCreators @@ -8,8 +9,11 @@ exports.createPages = ({ boundActionCreators, graphql }) => { allMarkdownRemark(limit: 1000) { edges { node { + id + fields { + slug + } frontmatter { - path templateKey } } @@ -22,16 +26,31 @@ 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 createPage({ - path: pagePath, + path: edge.node.fields.slug, 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, + }, }) }) }) } + +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/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/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/pages/about/about.md b/src/pages/about/index.md similarity index 100% rename from src/pages/about/about.md rename to src/pages/about/index.md diff --git a/src/pages/blog/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 index c43ebc6..5d3036a 100644 --- a/src/pages/blog/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 @@ -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/blog/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/blog/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/blog/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/blog/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/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/index.md similarity index 100% rename from src/pages/product/product.md rename to src/pages/products/index.md diff --git a/src/templates/about-page.js b/src/templates/about-page.js index e13208d..b36f822 100644 --- a/src/templates/about-page.js +++ b/src/templates/about-page.js @@ -35,11 +35,10 @@ 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 title } } diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index 456824e..f90af05 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -44,11 +44,11 @@ export default props => { } export const pageQuery = graphql` - query BlogPostByPath($path: String!) { - markdownRemark(frontmatter: { path: { eq: $path } }) { + query BlogPostByID($id: String!) { + markdownRemark(id: { eq: $id }) { + 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 186c7e8..3e5ac9d 100644 --- a/src/templates/product-page.js +++ b/src/templates/product-page.js @@ -123,11 +123,10 @@ 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 image heading description 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}