Upgrade to 1.0-alpha16
This commit is contained in:
parent
11e1d019cb
commit
4f47229cb6
4 changed files with 38 additions and 36 deletions
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
package.json
30
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",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class BlogIndex extends React.Component {
|
|||
marginBottom: rhythm(1 / 4),
|
||||
}}
|
||||
>
|
||||
<Link style={{ boxShadow: "none" }} to={post.node.slug}>
|
||||
<Link style={{ boxShadow: "none" }} to={post.node.fields.slug}>
|
||||
{post.node.frontmatter.title}
|
||||
</Link>
|
||||
</li>
|
||||
|
|
@ -59,7 +59,9 @@ query IndexQuery {
|
|||
allMarkdownRemark {
|
||||
edges {
|
||||
node {
|
||||
slug
|
||||
fields {
|
||||
slug
|
||||
}
|
||||
frontmatter {
|
||||
title
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div>
|
||||
|
|
@ -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 {
|
||||
Loading…
Add table
Add a link
Reference in a new issue