From 4f47229cb6fde0af25944ae6f4d8f047a14522c7 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Fri, 26 May 2017 10:46:52 +0100 Subject: [PATCH] Upgrade to 1.0-alpha16 --- gatsby-node.js | 31 ++++++++++--------- package.json | 30 +++++++++--------- src/pages/index.js | 6 ++-- .../{template-blog-post.js => blog-post.js} | 7 ++--- 4 files changed, 38 insertions(+), 36 deletions(-) rename src/templates/{template-blog-post.js => blog-post.js} (88%) diff --git a/gatsby-node.js b/gatsby-node.js index 5874a1e..bfe80bf 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -9,7 +9,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => { return new Promise((resolve, reject) => { const pages = [] - const blogPost = path.resolve("./src/templates/template-blog-post.js") + const blogPost = path.resolve("./src/templates/blog-post.js") resolve( graphql( ` @@ -17,7 +17,9 @@ exports.createPages = ({ graphql, boundActionCreators }) => { allMarkdownRemark(limit: 1000) { edges { node { - slug + fields { + slug + } } } } @@ -32,10 +34,10 @@ exports.createPages = ({ graphql, boundActionCreators }) => { // Create blog posts pages. _.each(result.data.allMarkdownRemark.edges, edge => { upsertPage({ - path: edge.node.slug, // required + path: edge.node.fields.slug, // required component: blogPost, context: { - slug: edge.node.slug, + slug: edge.node.fields.slug, }, }) }) @@ -44,20 +46,19 @@ exports.createPages = ({ graphql, boundActionCreators }) => { }) } -// Add custom url pathname for blog posts. +// Add custom slug for blog posts to both File and MarkdownRemark nodes. exports.onNodeCreate = ({ node, boundActionCreators, getNode }) => { - const { updateNode } = boundActionCreators - if (node.internal.type === `File` && typeof node.slug === "undefined") { + const { addFieldToNode } = boundActionCreators + if (node.internal.type === `File`) { const parsedFilePath = path.parse(node.relativePath) const slug = `/${parsedFilePath.dir}/` - node.slug = slug - updateNode(node) - } else if ( - node.internal.type === `MarkdownRemark` && - typeof node.slug === "undefined" - ) { + addFieldToNode({ node, fieldName: `slug`, fieldValue: slug }) + } else if (node.internal.type === `MarkdownRemark`) { const fileNode = getNode(node.parent) - node.slug = fileNode.slug - updateNode(node) + addFieldToNode({ + node, + fieldName: `slug`, + fieldValue: fileNode.fields.slug, + }) } } diff --git a/package.json b/package.json index 3550ff9..bf50144 100644 --- a/package.json +++ b/package.json @@ -7,21 +7,21 @@ "url": "https://github.com/gatsbyjs/gatsby-starter-blog/issues" }, "dependencies": { - "gatsby": "canary", - "gatsby-link": "canary", - "gatsby-transformer-remark": "canary", - "gatsby-transformer-sharp": "canary", - "gatsby-plugin-google-analytics": "canary", - "gatsby-plugin-manifest": "canary", - "gatsby-plugin-offline": "canary", - "gatsby-plugin-preact": "canary", - "gatsby-plugin-sharp": "canary", - "gatsby-source-filesystem": "canary", - "gatsby-remark-copy-linked-files": "canary", - "gatsby-remark-prismjs": "canary", - "gatsby-remark-responsive-iframe": "canary", - "gatsby-remark-responsive-image": "canary", - "gatsby-remark-smartypants": "canary", + "gatsby": "next", + "gatsby-link": "next", + "gatsby-transformer-remark": "next", + "gatsby-transformer-sharp": "next", + "gatsby-plugin-google-analytics": "next", + "gatsby-plugin-manifest": "next", + "gatsby-plugin-offline": "next", + "gatsby-plugin-preact": "next", + "gatsby-plugin-sharp": "next", + "gatsby-source-filesystem": "next", + "gatsby-remark-copy-linked-files": "next", + "gatsby-remark-prismjs": "next", + "gatsby-remark-responsive-iframe": "next", + "gatsby-remark-responsive-image": "next", + "gatsby-remark-smartypants": "next", "lodash": "^4.15.0", "moment": "^2.14.1", "react-helmet": "^4.0.0", diff --git a/src/pages/index.js b/src/pages/index.js index c354840..68c878c 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -23,7 +23,7 @@ class BlogIndex extends React.Component { marginBottom: rhythm(1 / 4), }} > - + {post.node.frontmatter.title} @@ -59,7 +59,9 @@ query IndexQuery { allMarkdownRemark { edges { node { - slug + fields { + slug + } frontmatter { title } diff --git a/src/templates/template-blog-post.js b/src/templates/blog-post.js similarity index 88% rename from src/templates/template-blog-post.js rename to src/templates/blog-post.js index 082fcc8..a5fd0c9 100644 --- a/src/templates/template-blog-post.js +++ b/src/templates/blog-post.js @@ -6,11 +6,10 @@ import get from "lodash/get" import Bio from "../components/Bio" import { rhythm, scale } from "../utils/typography" -class BlogPostRoute extends React.Component { +class BlogPostTemplate extends React.Component { render() { const post = this.props.data.markdownRemark const siteTitle = get(this.props, "data.site.siteMetadata.title") - // console.log(this.props) return (
@@ -38,7 +37,7 @@ class BlogPostRoute extends React.Component { } } -export default BlogPostRoute +export default BlogPostTemplate export const pageQuery = graphql` query BlogPostByPath($slug: String!) { @@ -48,7 +47,7 @@ export const pageQuery = graphql` author } } - markdownRemark(slug: { eq: $slug }) { + markdownRemark(fields: { slug: { eq: $slug }}) { id html frontmatter {