1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00
docs/gatsby-node.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

const path = require('path')
const { createFilePath } = require('gatsby-source-filesystem')
2018-11-07 12:24:53 +01:00
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
2018-11-08 16:03:16 +01:00
if (node.internal.type === 'MarkdownRemark') {
const fileNode = getNode(node.parent)
const parsedFilePath = path.parse(fileNode.relativePath)
2018-11-08 16:03:16 +01:00
const slug = createFilePath({ node, getNode, basePath: 'content' })
const section = parsedFilePath.dir
createNodeField({
node,
name: 'slug',
value: slug
})
createNodeField({
node,
name: 'section',
value: section
})
}
}
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return new Promise((resolve, reject) => {
resolve(
graphql(
`
{
allMarkdownRemark {
edges {
node {
fields {
slug
section
}
}
}
}
}
`
).then(result => {
if (result.errors) {
/* eslint-disable-next-line no-console */
console.log(result.errors)
reject(result.errors)
}
const posts = result.data.allMarkdownRemark.edges
const docTemplate = path.resolve('./src/templates/Doc.jsx')
// Create Doc pages
posts.forEach(post => {
createPage({
path: `${post.node.fields.slug}`,
component: docTemplate,
context: {
slug: post.node.fields.slug,
section: post.node.fields.section
}
})
})
resolve()
})
)
})
}