-
Notifications
You must be signed in to change notification settings - Fork 10.3k
docs(gatsby): improve createPages example #10777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,49 +12,51 @@ exports.resolvableExtensions = true | |||||
* | ||||||
* See also [the documentation for the action `createPage`](/docs/actions/#createPage). | ||||||
* @example | ||||||
* const path = require(`path`) | ||||||
* | ||||||
* exports.createPages = ({ graphql, actions }) => { | ||||||
* const { createPage } = actions | ||||||
* return new Promise((resolve, reject) => { | ||||||
* const blogPostTemplate = path.resolve(`src/templates/blog-post.js`) | ||||||
* // Query for markdown nodes to use in creating pages. | ||||||
* resolve( | ||||||
* graphql( | ||||||
* ` | ||||||
* { | ||||||
* allMarkdownRemark(limit: 1000) { | ||||||
* edges { | ||||||
* node { | ||||||
* fields { | ||||||
* slug | ||||||
* } | ||||||
* const blogPostTemplate = path.resolve(`src/templates/blog-post.js`) | ||||||
* // Query for markdown nodes to use in creating pages. | ||||||
* // You can query for whatever data you want to create pages for e.g. | ||||||
* // products, portfolio items, landing pages, etc. | ||||||
* graphql(` | ||||||
* { | ||||||
* allMarkdownRemark(limit: 1000) { | ||||||
* edges { | ||||||
* node { | ||||||
* fields { | ||||||
* slug | ||||||
* } | ||||||
* } | ||||||
* } | ||||||
* } | ||||||
* ` | ||||||
* ).then(result => { | ||||||
* if (result.errors) { | ||||||
* reject(result.errors) | ||||||
* } | ||||||
* | ||||||
* // Create blog post pages. | ||||||
* result.data.allMarkdownRemark.edges.forEach(edge => { | ||||||
* createPage({ | ||||||
* path: `${edge.node.fields.slug}`, // required | ||||||
* component: blogPostTemplate, | ||||||
* context: { | ||||||
* // Add optional context data. Data can be used as | ||||||
* // arguments to the page GraphQL query. | ||||||
* // | ||||||
* // The page "path" is always available as a GraphQL | ||||||
* // argument. | ||||||
* }, | ||||||
* }) | ||||||
* }) | ||||||
* } | ||||||
* `).then(result => { | ||||||
* if (result.errors) { | ||||||
* reject(result.errors) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this should be a |
||||||
* } | ||||||
* | ||||||
* return | ||||||
* // Create blog post pages. | ||||||
* result.data.allMarkdownRemark.edges.forEach(edge => { | ||||||
* createPage({ | ||||||
* // Path for this page — required | ||||||
* path: `${edge.node.fields.slug}`, | ||||||
* component: blogPostTemplate, | ||||||
* context: { | ||||||
* // Add optional context data to be inserted | ||||||
* // as props into the page component.. | ||||||
* // | ||||||
* // The context data can also be used as | ||||||
* // arguments to the page GraphQL query. | ||||||
* // | ||||||
* // The page "path" is always available as a GraphQL | ||||||
* // argument. | ||||||
* }, | ||||||
* }) | ||||||
* ) | ||||||
* }) | ||||||
* | ||||||
* return | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably just drop this? The flow ends here anyways, particularly if we return the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
* }) | ||||||
* } | ||||||
*/ | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to return here? It doesn't really matter either way, but it doesn't hurt