-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
476 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const path = require('path'); | ||
const { createFilePath } = require('gatsby-source-filesystem'); | ||
|
||
exports.onCreateNode = ({ node, getNode, actions }) => { | ||
const { createNodeField } = actions; | ||
// Ensures we are processing only markdown files | ||
if (node.internal.type === "MarkdownRemark") { | ||
// Use `createFilePath` to turn markdown files in our `data/faqs` directory into `/faqs/slug` | ||
const relativeFilePath = createFilePath({ | ||
node, | ||
getNode, | ||
basePath: ".cache/gatsby-source-git", | ||
}); | ||
const { sourceInstanceName } = getNode(node.parent); | ||
|
||
// Creates new query'able field with name of 'slug' | ||
createNodeField({ | ||
node, | ||
name: "slug", | ||
value: `/${sourceInstanceName.toLowerCase()}${relativeFilePath}`, | ||
}); | ||
} | ||
}; | ||
|
||
exports.createPages = async ({ graphql, actions }) => { | ||
const { createPage } = actions; | ||
const result = await graphql(` | ||
query { | ||
allMarkdownRemark { | ||
edges { | ||
node { | ||
fields { | ||
slug | ||
sourceName | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
result.data.allMarkdownRemark.edges.forEach(({ node }) => { | ||
createPage({ | ||
path: node.fields.slug, | ||
component: path.resolve(`./src/templates/docs-page.js`), | ||
context: { | ||
// Data passed to context is available | ||
// in page queries as GraphQL variables. | ||
slug: node.fields.slug, | ||
}, | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.