Upgrade to 1.0-alpha16

This commit is contained in:
Kyle Mathews 2017-05-26 10:46:52 +01:00
parent 11e1d019cb
commit 4f47229cb6
4 changed files with 38 additions and 36 deletions

View file

@ -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,
})
}
}