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
Executable File

const path = require('path')
const { createFilePath } = require('gatsby-source-filesystem')
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions
if (node.internal.type === 'MarkdownRemark') {
const fileNode = getNode(node.parent)
const parsedFilePath = path.parse(fileNode.relativePath)
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()
})
)
})
}