Just use frontmatter paths for paths + cleanups
This commit is contained in:
parent
4936e80940
commit
d2e2bc8df7
6 changed files with 33 additions and 63 deletions
|
|
@ -17,8 +17,8 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
|||
allMarkdownRemark(limit: 1000) {
|
||||
edges {
|
||||
node {
|
||||
fields {
|
||||
slug
|
||||
frontmatter {
|
||||
path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,10 +34,10 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
|||
// Create blog posts pages.
|
||||
_.each(result.data.allMarkdownRemark.edges, edge => {
|
||||
createPage({
|
||||
path: edge.node.fields.slug, // required
|
||||
path: edge.node.frontmatter.path,
|
||||
component: blogPost,
|
||||
context: {
|
||||
slug: edge.node.fields.slug,
|
||||
path: edge.node.frontmatter.path,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
|
@ -45,29 +45,3 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
|||
)
|
||||
})
|
||||
}
|
||||
|
||||
// Add custom slug for blog posts to both File and MarkdownRemark nodes.
|
||||
exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
|
||||
const { createNodeField } = boundActionCreators
|
||||
|
||||
switch (node.internal.type) {
|
||||
case 'File':
|
||||
const parsedFilePath = path.parse(node.relativePath)
|
||||
const slug = `/${parsedFilePath.dir}/`
|
||||
createNodeField({
|
||||
node,
|
||||
fieldName: 'slug',
|
||||
fieldValue: slug
|
||||
})
|
||||
return
|
||||
|
||||
case 'MarkdownRemark':
|
||||
const fileNode = getNode(node.parent)
|
||||
createNodeField({
|
||||
node,
|
||||
fieldName: 'slug',
|
||||
fieldValue: fileNode.fields.slug,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue